Skip to content

Commit

Permalink
Fix #11143 take 3 (cannot remove visibility groups)
Browse files Browse the repository at this point in the history
Now we also handle rules that are not valid anymore
  • Loading branch information
wonder-sk committed Sep 10, 2014
1 parent 4ef67ca commit 95f4a30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/app/qgsvisibilitygroups.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -256,6 +256,30 @@ void QgsVisibilityGroups::applyState( const QString& groupName )
return; return;


applyStateToLayerTreeGroup( QgsProject::instance()->layerTreeRoot(), mGroups[groupName] ); applyStateToLayerTreeGroup( QgsProject::instance()->layerTreeRoot(), mGroups[groupName] );

// also make sure that the group is up-to-date (not containing any non-existant legend items)
if ( mGroups[groupName] == currentState() )
return; // no need for update

GroupRecord& rec = mGroups[groupName];
foreach ( QString layerID, rec.mPerLayerCheckedLegendSymbols.keys() )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID ) );
if ( !vl || !vl->rendererV2() )
continue;

QSet<QString> validRuleKeys;
foreach ( const QgsLegendSymbolItemV2& item, vl->rendererV2()->legendSymbolItemsV2() )
validRuleKeys << item.ruleKey();

QSet<QString> invalidRuleKeys;
foreach ( QString ruleKey, rec.mPerLayerCheckedLegendSymbols[layerID] )
if ( !validRuleKeys.contains( ruleKey ) )
invalidRuleKeys << ruleKey;

foreach ( QString invalidRuleKey, invalidRuleKeys )
rec.mPerLayerCheckedLegendSymbols[layerID].remove( invalidRuleKey );
}
} }




Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsvisibilitygroups.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class QgsVisibilityGroups : public QObject
{ {
return mVisibleLayerIDs == other.mVisibleLayerIDs && mPerLayerCheckedLegendSymbols == other.mPerLayerCheckedLegendSymbols; return mVisibleLayerIDs == other.mVisibleLayerIDs && mPerLayerCheckedLegendSymbols == other.mPerLayerCheckedLegendSymbols;
} }
bool operator!=( const GroupRecord& other ) const
{
return !( *this == other );
}


//! List of layers that are visible //! List of layers that are visible
QSet<QString> mVisibleLayerIDs; QSet<QString> mVisibleLayerIDs;
Expand Down

0 comments on commit 95f4a30

Please sign in to comment.