File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,30 @@ void QgsVisibilityGroups::applyState( const QString& groupName )
256
256
return ;
257
257
258
258
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
+ }
259
283
}
260
284
261
285
Original file line number Diff line number Diff line change @@ -84,6 +84,10 @@ class QgsVisibilityGroups : public QObject
84
84
{
85
85
return mVisibleLayerIDs == other.mVisibleLayerIDs && mPerLayerCheckedLegendSymbols == other.mPerLayerCheckedLegendSymbols ;
86
86
}
87
+ bool operator !=( const GroupRecord& other ) const
88
+ {
89
+ return !( *this == other );
90
+ }
87
91
88
92
// ! List of layers that are visible
89
93
QSet<QString> mVisibleLayerIDs ;
You can’t perform that action at this time.
0 commit comments