Skip to content

Commit 9494dce

Browse files
committed
QgsEditorWidgetRegistry disconnect signals when mapLayer will be removed (#3186)
Add a method to disconnect signals added when layerIsAdded to QgsMapLayerRegistry. This method is connect to layerWillBeRemoved. This method will probably fix an issue in QGIS Server about performance deterioration. Each time a layer is added to QgsMapLayerRegistry by QGIS Server, QgsEditorWidgetRegistry connects to appropriate signals from map layers to load and save style but NEVER disconnects its.
1 parent d708473 commit 9494dce

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ QgsEditorWidgetRegistry::QgsEditorWidgetRegistry()
7979
connect( QgsProject::instance(), SIGNAL( readMapLayer( QgsMapLayer*, const QDomElement& ) ), this, SLOT( readMapLayer( QgsMapLayer*, const QDomElement& ) ) );
8080
// connect( QgsProject::instance(), SIGNAL( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ), this, SLOT( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ) );
8181

82+
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( mapLayerWillBeRemoved( QgsMapLayer* ) ) );
8283
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( mapLayerAdded( QgsMapLayer* ) ) );
8384
}
8485

@@ -318,6 +319,17 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
318319
layerElem.appendChild( editTypesNode );
319320
}
320321

322+
void QgsEditorWidgetRegistry::mapLayerWillBeRemoved( QgsMapLayer* mapLayer )
323+
{
324+
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mapLayer );
325+
326+
if ( vl )
327+
{
328+
disconnect( vl, SIGNAL( readCustomSymbology( const QDomElement&, QString& ) ), this, SLOT( readSymbology( const QDomElement&, QString& ) ) );
329+
disconnect( vl, SIGNAL( writeCustomSymbology( QDomElement&, QDomDocument&, QString& ) ), this, SLOT( writeSymbology( QDomElement&, QDomDocument&, QString& ) ) );
330+
}
331+
}
332+
321333
void QgsEditorWidgetRegistry::mapLayerAdded( QgsMapLayer* mapLayer )
322334
{
323335
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mapLayer );

src/gui/editorwidgets/core/qgseditorwidgetregistry.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
173173
*/
174174
void mapLayerAdded( QgsMapLayer* mapLayer );
175175

176+
/**
177+
* Will disconnect to appropriate signals from map layers to load and save style
178+
*
179+
* @param mapLayer The layer to disconnect
180+
*/
181+
void mapLayerWillBeRemoved( QgsMapLayer* mapLayer );
182+
176183
/**
177184
* Loads layer symbology for the layer that emitted the signal
178185
*

0 commit comments

Comments
 (0)