Skip to content
Permalink
Browse files

Fix #11143 take 3 (cannot remove visibility groups)

Now we also handle rules that are not valid anymore
  • Loading branch information
wonder-sk committed Sep 10, 2014
1 parent 4ef67ca commit 95f4a30e7bbe35959b210d824d24648a51d7b17e
Showing with 28 additions and 0 deletions.
  1. +24 −0 src/app/qgsvisibilitygroups.cpp
  2. +4 −0 src/app/qgsvisibilitygroups.h
@@ -256,6 +256,30 @@ void QgsVisibilityGroups::applyState( const QString& groupName )
return;

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 );
}
}


@@ -84,6 +84,10 @@ class QgsVisibilityGroups : public QObject
{
return mVisibleLayerIDs == other.mVisibleLayerIDs && mPerLayerCheckedLegendSymbols == other.mPerLayerCheckedLegendSymbols;
}
bool operator!=( const GroupRecord& other ) const
{
return !( *this == other );
}

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

0 comments on commit 95f4a30

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