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 authored and m-kuhn committed Jun 9, 2016
1 parent 015ee77 commit 61d243e9f7e8282e4c046127fbfdb2da3c0bae88
@@ -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* ) ) );
}

@@ -326,6 +327,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 61d243e

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