2929QgsMapThemeCollection::QgsMapThemeCollection ( QgsProject *project )
3030 : mProject( project )
3131{
32- connect ( project, & QgsProject::layersRemoved , this , &QgsMapThemeCollection::registryLayersRemoved );
32+ connect ( project, static_cast < void ( QgsProject::* )( const QStringList & )>( & QgsProject::layersWillBeRemoved ) , this , &QgsMapThemeCollection::registryLayersRemoved );
3333}
3434
3535QgsMapThemeCollection::MapThemeLayerRecord QgsMapThemeCollection::createThemeLayerRecord ( QgsLayerTreeLayer *nodeLayer, QgsLayerTreeModel *model )
@@ -169,9 +169,9 @@ void QgsMapThemeCollection::setProject( QgsProject *project )
169169 if ( project == mProject )
170170 return ;
171171
172- disconnect ( mProject , & QgsProject::layersRemoved , this , &QgsMapThemeCollection::registryLayersRemoved );
172+ disconnect ( mProject , static_cast < void ( QgsProject::* )( const QStringList & )>( & QgsProject::layersWillBeRemoved ) , this , &QgsMapThemeCollection::registryLayersRemoved );
173173 mProject = project;
174- connect ( mProject , & QgsProject::layersRemoved , this , &QgsMapThemeCollection::registryLayersRemoved );
174+ connect ( mProject , static_cast < void ( QgsProject::* )( const QStringList & )>( & QgsProject::layersWillBeRemoved ) , this , &QgsMapThemeCollection::registryLayersRemoved );
175175 emit projectChanged ();
176176}
177177
@@ -186,6 +186,7 @@ void QgsMapThemeCollection::insert( const QString &name, const QgsMapThemeCollec
186186 mMapThemes .insert ( name, state );
187187
188188 reconnectToLayersStyleManager ();
189+ emit mapThemeChanged ( name );
189190 emit mapThemesChanged ();
190191}
191192
@@ -197,6 +198,7 @@ void QgsMapThemeCollection::update( const QString &name, const MapThemeRecord &s
197198 mMapThemes [name] = state;
198199
199200 reconnectToLayersStyleManager ();
201+ emit mapThemeChanged ( name );
200202 emit mapThemesChanged ();
201203}
202204
@@ -316,7 +318,7 @@ void QgsMapThemeCollection::reconnectToLayersStyleManager()
316318
317319 Q_FOREACH ( QgsMapLayer *ml, layers )
318320 {
319- connect ( ml->styleManager (), SIGNAL ( styleRenamed ( QString, QString ) ), this , SLOT ( layerStyleRenamed ( QString, QString ) ) );
321+ connect ( ml->styleManager (), &QgsMapLayerStyleManager:: styleRenamed, this , &QgsMapThemeCollection:: layerStyleRenamed );
320322 }
321323}
322324
@@ -375,6 +377,7 @@ void QgsMapThemeCollection::readXml( const QDomDocument &doc )
375377 MapThemeRecord rec;
376378 rec.setLayerRecords ( layerRecords.values () );
377379 mMapThemes .insert ( presetName, rec );
380+ emit mapThemeChanged ( presetName );
378381
379382 visPresetElem = visPresetElem.nextSiblingElement ( QStringLiteral ( " visibility-preset" ) );
380383 }
@@ -426,8 +429,9 @@ void QgsMapThemeCollection::writeXml( QDomDocument &doc )
426429
427430void QgsMapThemeCollection::registryLayersRemoved ( const QStringList &layerIDs )
428431{
429- // TODO: this should not be necessary - layers are stored as weak pointers
430-
432+ // while layers are stored as weak pointers, this triggers the mapThemeChanged signal for
433+ // affected themes
434+ QSet< QString > changedThemes;
431435 MapThemeRecordMap::iterator it = mMapThemes .begin ();
432436 for ( ; it != mMapThemes .end (); ++it )
433437 {
@@ -436,9 +440,17 @@ void QgsMapThemeCollection::registryLayersRemoved( const QStringList &layerIDs )
436440 {
437441 MapThemeLayerRecord &layerRec = rec.mLayerRecords [i];
438442 if ( layerRec.layer () && layerIDs.contains ( layerRec.layer ()->id () ) )
443+ {
439444 rec.mLayerRecords .removeAt ( i-- );
445+ changedThemes << it.key ();
446+ }
440447 }
441448 }
449+
450+ Q_FOREACH ( const QString &theme, changedThemes )
451+ {
452+ emit mapThemeChanged ( theme );
453+ }
442454 emit mapThemesChanged ();
443455}
444456
@@ -448,6 +460,8 @@ void QgsMapThemeCollection::layerStyleRenamed( const QString &oldName, const QSt
448460 if ( !styleMgr )
449461 return ;
450462
463+ QSet< QString > changedThemes;
464+
451465 MapThemeRecordMap::iterator it = mMapThemes .begin ();
452466 for ( ; it != mMapThemes .end (); ++it )
453467 {
@@ -458,10 +472,17 @@ void QgsMapThemeCollection::layerStyleRenamed( const QString &oldName, const QSt
458472 if ( layerRec.layer () == styleMgr->layer () )
459473 {
460474 if ( layerRec.currentStyle == oldName )
475+ {
461476 layerRec.currentStyle = newName;
477+ changedThemes << it.key ();
478+ }
462479 }
463480 }
464481 }
482+ Q_FOREACH ( const QString &theme, changedThemes )
483+ {
484+ emit mapThemeChanged ( theme );
485+ }
465486 emit mapThemesChanged ();
466487}
467488
0 commit comments