Skip to content
Permalink
Browse files
Add possibility to temporarily disable layer tree to registry bridge
This is useful during the project load where the updates from
map layer registry would make the layers appear twice in the tree
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent 129d295 commit 1906de17798fde07c14a02d1841869aa59c338a5
@@ -7,6 +7,7 @@
QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge(QgsLayerTreeGroup *root, QObject *parent)
: QObject(parent)
, mRoot(root)
, mEnabled(true)
{
connect(QgsMapLayerRegistry::instance(), SIGNAL(layersAdded(QList<QgsMapLayer*>)), this, SLOT(layersAdded(QList<QgsMapLayer*>)));
connect(QgsMapLayerRegistry::instance(), SIGNAL(layersWillBeRemoved(QStringList)), this, SLOT(layersWillBeRemoved(QStringList)));
@@ -16,6 +17,9 @@ QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge(QgsLayerTreeGroup *root,

void QgsLayerTreeRegistryBridge::layersAdded(QList<QgsMapLayer*> layers)
{
if (!mEnabled)
return;

foreach (QgsMapLayer* layer, layers)
{
mRoot->addLayer(layer);
@@ -24,6 +28,9 @@ void QgsLayerTreeRegistryBridge::layersAdded(QList<QgsMapLayer*> layers)

void QgsLayerTreeRegistryBridge::layersWillBeRemoved(QStringList layerIds)
{
if (!mEnabled)
return;

foreach (QString layerId, layerIds)
{
QgsLayerTreeLayer* nodeLayer = mRoot->findLayer(layerId);
@@ -17,6 +17,9 @@ class CORE_EXPORT QgsLayerTreeRegistryBridge : public QObject
public:
explicit QgsLayerTreeRegistryBridge(QgsLayerTreeGroup* root, QObject *parent = 0);

void setEnabled(bool enabled) { mEnabled = enabled; }
bool isEnabled() const { return mEnabled; }

signals:

protected slots:
@@ -33,6 +36,7 @@ protected slots:
protected:
QgsLayerTreeGroup* mRoot;
QStringList mLayerIdsForRemoval;
bool mEnabled;
};

#endif // QGSLAYERTREEREGISTRYBRIDGE_H
@@ -342,7 +342,7 @@ QgsProject::QgsProject()
// bind the layer tree to the map layer registry.
// whenever layers are added to or removed from the registry,
// layer tree will be updated
new QgsLayerTreeRegistryBridge(mRootGroup, this);
mLayerTreeRegistryBridge = new QgsLayerTreeRegistryBridge(mRootGroup, this);

} // QgsProject ctor

@@ -915,6 +915,8 @@ bool QgsProject::read()

QgsDebugMsg( "Loaded layer tree:\n " + mRootGroup->dump() );

mLayerTreeRegistryBridge->setEnabled( false );

// get the map layers
QPair< bool, QList<QDomNode> > getMapLayersResults = _getMapLayers( *doc );

@@ -935,6 +937,8 @@ bool QgsProject::read()
mBadLayerHandler->handleBadLayers( getMapLayersResults.second, *doc );
}

mLayerTreeRegistryBridge->setEnabled( true );

// read the project: used by map canvas and legend
emit readProject( *doc );

@@ -40,6 +40,7 @@ class QDomElement;
class QDomNode;

class QgsLayerTreeGroup;
class QgsLayerTreeRegistryBridge;
class QgsMapLayer;
class QgsProjectBadLayerHandler;
class QgsRelationManager;
@@ -417,6 +418,8 @@ class CORE_EXPORT QgsProject : public QObject

QgsLayerTreeGroup* mRootGroup;

QgsLayerTreeRegistryBridge* mLayerTreeRegistryBridge;

}; // QgsProject


0 comments on commit 1906de1

Please sign in to comment.