Skip to content
Permalink
Browse files

QgsEditorWidgetRegistry disconnect signals when mapLayer will be remo…

…ved (#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.
  • Loading branch information
rldhont committed Jun 9, 2016
1 parent d708473 commit 9494dce05a060fa4543b85124697a34e4506a853
@@ -79,6 +79,7 @@ QgsEditorWidgetRegistry::QgsEditorWidgetRegistry()
connect( QgsProject::instance(), SIGNAL( readMapLayer( QgsMapLayer*, const QDomElement& ) ), this, SLOT( readMapLayer( QgsMapLayer*, const QDomElement& ) ) );
// connect( QgsProject::instance(), SIGNAL( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ), this, SLOT( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ) );

connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( mapLayerWillBeRemoved( QgsMapLayer* ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( mapLayerAdded( QgsMapLayer* ) ) );
}

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

void QgsEditorWidgetRegistry::mapLayerWillBeRemoved( QgsMapLayer* mapLayer )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mapLayer );

if ( vl )
{
disconnect( vl, SIGNAL( readCustomSymbology( const QDomElement&, QString& ) ), this, SLOT( readSymbology( const QDomElement&, QString& ) ) );
disconnect( vl, SIGNAL( writeCustomSymbology( QDomElement&, QDomDocument&, QString& ) ), this, SLOT( writeSymbology( QDomElement&, QDomDocument&, QString& ) ) );
}
}

void QgsEditorWidgetRegistry::mapLayerAdded( QgsMapLayer* mapLayer )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mapLayer );
@@ -173,6 +173,13 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
*/
void mapLayerAdded( QgsMapLayer* mapLayer );

/**
* Will disconnect to appropriate signals from map layers to load and save style
*
* @param mapLayer The layer to disconnect
*/
void mapLayerWillBeRemoved( QgsMapLayer* mapLayer );

/**
* Loads layer symbology for the layer that emitted the signal
*

0 comments on commit 9494dce

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