Skip to content
Permalink
Browse files

Merge pull request #287 from tecoholic/3275

Fix for issue #3275
  • Loading branch information
NathanW2 committed Oct 11, 2012
2 parents a587cb6 + 936f4aa commit 6a5dcacf361427eddef9385d3d3062f3f548f035
@@ -596,3 +596,15 @@ void QgsCategorizedSymbolRendererV2::setSourceColorRamp( QgsVectorColorRampV2* r
delete mSourceColorRamp;
mSourceColorRamp = ramp;
}

void QgsCategorizedSymbolRendererV2::updateSymbols( QgsSymbolV2 * sym )
{
int i = 0;
foreach( QgsRendererCategoryV2 cat, mCategories )
{
QgsSymbolV2* symbol = sym->clone();
symbol->setColor( cat.symbol()->color() );
updateCategorySymbol( i, symbol );
++i;
}
}
@@ -84,6 +84,8 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
virtual int capabilities() { return SymbolLevels | RotationField; }

virtual QgsSymbolV2List symbols();
//! @note added in 2.0
void updateSymbols( QgsSymbolV2 * sym );

const QgsCategoryList& categories() { return mCategories; }

@@ -151,13 +151,63 @@ QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2Widget::renderer()
return mRenderer;
}

void QgsCategorizedSymbolRendererV2Widget::changeSelectedSymbols()
{
QItemSelectionModel* m = viewCategories->selectionModel();
QModelIndexList selectedIndexes = m->selectedRows( 1 );

if ( m && selectedIndexes.size() > 0 )
{
QgsSymbolV2* newSymbol = mCategorizedSymbol->clone();
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
if ( !dlg.exec() )
{
delete newSymbol;
return;
}

foreach( QModelIndex idx, selectedIndexes )
{
if( idx.isValid() )
{
int catIdx = mRenderer->categoryIndexForValue( idx.data( Qt::UserRole + 1 ) );
QgsSymbolV2* newCatSymbol = newSymbol->clone();
newCatSymbol->setColor( mRenderer->categories()[catIdx].symbol()->color() );
mRenderer->updateCategorySymbol( catIdx, newCatSymbol );
}
}
}

populateCategories();
}

void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
{
QgsSymbolV2SelectorDialog dlg( mCategorizedSymbol, mStyle, mLayer, this );
// When there is a slection, change the selected symbols alone
QItemSelectionModel* m = viewCategories->selectionModel();
QModelIndexList i = m->selectedRows();

if ( m && i.size() > 0 )
{
changeSelectedSymbols();
return;
}

// When there is no selection, change the base mCategorizedSymbol
QgsSymbolV2* newSymbol = mCategorizedSymbol->clone();

QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
if ( !dlg.exec() )
{
delete newSymbol;
return;
}

mCategorizedSymbol = newSymbol;
updateCategorizedSymbolIcon();

mRenderer->updateSymbols( mCategorizedSymbol );
populateCategories();
}

void QgsCategorizedSymbolRendererV2Widget::updateCategorizedSymbolIcon()
@@ -396,18 +446,41 @@ QVariant QgsCategorizedSymbolRendererV2Widget::currentCategory()
return m->item( row, 1 )->data();
}

QList<QVariant> QgsCategorizedSymbolRendererV2Widget::selectedCategories()
{
QList<QVariant> categories;
QModelIndexList rows = viewCategories->selectionModel()->selectedRows();
QStandardItemModel* m = qobject_cast<QStandardItemModel*>( viewCategories->model() );

foreach( QModelIndex r, rows )
{
if( r.isValid() )
{
categories.append( m->item( r.row(), 1 )->data() );
}
}

return categories;
}

void QgsCategorizedSymbolRendererV2Widget::deleteCategory()
{
QVariant k = currentCategory();
if ( !k.isValid() )
return;
QList<QVariant> categories = selectedCategories();

int idx = mRenderer->categoryIndexForValue( k );
if ( idx < 0 )
if ( !categories.size() )
return;

mRenderer->deleteCategory( idx );

foreach( const QVariant k, categories )
{
if ( k.isValid() )
{
int idx = mRenderer->categoryIndexForValue( k );
if ( idx >= 0 )
{
mRenderer->deleteCategory( idx );
}
}
}
populateCategories();
}

@@ -70,6 +70,12 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg
//! return key for the currently selected category
QVariant currentCategory();

//! return a list of keys for the categories unders selection
QList<QVariant> selectedCategories();

//! change the selected symbols alone for the change button, if there is a selection
void changeSelectedSymbols();

void changeCategorySymbol();

QList<QgsSymbolV2*> selectedSymbols();
@@ -239,9 +239,26 @@ void QgsGraduatedSymbolRendererV2Widget::reapplyColorRamp()

void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()
{
QgsSymbolV2SelectorDialog dlg( mGraduatedSymbol, mStyle, mLayer, this );
// Change the selected symbols alone if anything is selected
QItemSelectionModel* m = viewGraduated->selectionModel();
QModelIndexList i = m->selectedRows();
if ( m && i.size() > 0 )
{
changeSelectedSymbols();
return;
}

// Otherwise change the base mGraduatedSymbol
QgsSymbolV2* newSymbol = mGraduatedSymbol->clone();

QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
if ( !dlg.exec() )
{
delete newSymbol;
return;
}

mGraduatedSymbol = newSymbol;

updateGraduatedSymbolIcon();
mRenderer->updateSymbols( mGraduatedSymbol );
@@ -320,6 +337,34 @@ void QgsGraduatedSymbolRendererV2Widget::rangesClicked( const QModelIndex & idx
mRowSelected = idx.row();
}

void QgsGraduatedSymbolRendererV2Widget::changeSelectedSymbols()
{
QItemSelectionModel* m = viewGraduated->selectionModel();
QModelIndexList selectedIndexes = m->selectedRows( 1 );
if ( m && selectedIndexes.size() > 0 )
{
QgsSymbolV2* newSymbol = mGraduatedSymbol->clone();
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
if ( !dlg.exec() )
{
delete newSymbol;
return;
}

foreach( QModelIndex idx, selectedIndexes )
{
if( idx.isValid() )
{
int rangeIdx = idx.row();
QgsSymbolV2* newRangeSymbol = newSymbol->clone();
newRangeSymbol->setColor( mRenderer->ranges()[rangeIdx].symbol()->color() );
mRenderer->updateRangeSymbol( rangeIdx, newRangeSymbol );
}
}
}
refreshSymbolView();
}

void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx )
{
QgsSymbolV2* newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone();
@@ -68,6 +68,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
void changeRangeSymbol( int rangeIdx );
void changeRange( int rangeIdx );

void changeSelectedSymbols();

QList<QgsSymbolV2*> selectedSymbols();
QgsSymbolV2* findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList& ranges ) const;
void refreshSymbolView();

0 comments on commit 6a5dcac

Please sign in to comment.
You can’t perform that action at this time.