Skip to content

Commit 95f4a30

Browse files
committedSep 10, 2014
Fix #11143 take 3 (cannot remove visibility groups)
Now we also handle rules that are not valid anymore
1 parent 4ef67ca commit 95f4a30

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
 

‎src/app/qgsvisibilitygroups.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,30 @@ void QgsVisibilityGroups::applyState( const QString& groupName )
256256
return;
257257

258258
applyStateToLayerTreeGroup( QgsProject::instance()->layerTreeRoot(), mGroups[groupName] );
259+
260+
// also make sure that the group is up-to-date (not containing any non-existant legend items)
261+
if ( mGroups[groupName] == currentState() )
262+
return; // no need for update
263+
264+
GroupRecord& rec = mGroups[groupName];
265+
foreach ( QString layerID, rec.mPerLayerCheckedLegendSymbols.keys() )
266+
{
267+
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID ) );
268+
if ( !vl || !vl->rendererV2() )
269+
continue;
270+
271+
QSet<QString> validRuleKeys;
272+
foreach ( const QgsLegendSymbolItemV2& item, vl->rendererV2()->legendSymbolItemsV2() )
273+
validRuleKeys << item.ruleKey();
274+
275+
QSet<QString> invalidRuleKeys;
276+
foreach ( QString ruleKey, rec.mPerLayerCheckedLegendSymbols[layerID] )
277+
if ( !validRuleKeys.contains( ruleKey ) )
278+
invalidRuleKeys << ruleKey;
279+
280+
foreach ( QString invalidRuleKey, invalidRuleKeys )
281+
rec.mPerLayerCheckedLegendSymbols[layerID].remove( invalidRuleKey );
282+
}
259283
}
260284

261285

‎src/app/qgsvisibilitygroups.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class QgsVisibilityGroups : public QObject
8484
{
8585
return mVisibleLayerIDs == other.mVisibleLayerIDs && mPerLayerCheckedLegendSymbols == other.mPerLayerCheckedLegendSymbols;
8686
}
87+
bool operator!=( const GroupRecord& other ) const
88+
{
89+
return !( *this == other );
90+
}
8791

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

0 commit comments

Comments
 (0)
Please sign in to comment.