From ed48ffb68aaee6efb71059e217d61aafce16e419 Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Tue, 5 Mar 2013 21:36:52 +0100 Subject: [PATCH] Map layer registry: un-deprecated addMapLayer(), added removeMapLayer() for convenience --- python/core/qgsmaplayerregistry.sip | 14 +++++++++++++- src/core/qgsmaplayerregistry.cpp | 6 ++++++ src/core/qgsmaplayerregistry.h | 16 ++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/python/core/qgsmaplayerregistry.sip b/python/core/qgsmaplayerregistry.sip index ca62c1efcd54..61c2cb72b128 100644 --- a/python/core/qgsmaplayerregistry.sip +++ b/python/core/qgsmaplayerregistry.sip @@ -49,7 +49,7 @@ class QgsMapLayerRegistry : QObject @see addMapLayers @note Use addMapLayers if adding more than one layer at a time */ - QgsMapLayer *addMapLayer( QgsMapLayer * theMapLayer /Transfer/, bool theEmitSignal = true ) /Deprecated/; + QgsMapLayer *addMapLayer( QgsMapLayer * theMapLayer /Transfer/, bool theEmitSignal = true ); /** Remove a set of layers from qgis @note As a side-effect QgsProject is made dirty. @@ -63,6 +63,18 @@ class QgsMapLayerRegistry : QObject */ void removeMapLayers( QStringList theLayerIds, bool theEmitSignal = true ); + /** Remove a layer from qgis + @note As a side-effect QgsProject is made dirty. + Any canvases using the affected layers will need to remove them + + If theEmitSignal is true (by default), a layersRemoved( QStringList theLayerIds ) + signal will be emitted indicating to any listeners that the layers are being removed. + + The layer being removed is deleted as well as the registry + table entry. + */ + void removeMapLayer( const QString& theLayerId, bool theEmitSignal = true ); + /** Remove all registered layers @note raises removedAll() As a side-effect QgsProject is made dirty. diff --git a/src/core/qgsmaplayerregistry.cpp b/src/core/qgsmaplayerregistry.cpp index c37f06fa9b22..9c83320fe763 100644 --- a/src/core/qgsmaplayerregistry.cpp +++ b/src/core/qgsmaplayerregistry.cpp @@ -133,6 +133,12 @@ void QgsMapLayerRegistry::removeMapLayers( QStringList theLayerIds, emit layersWillBeRemoved( theLayerIds ); } +void QgsMapLayerRegistry::removeMapLayer( const QString& theLayerId, bool theEmitSignal ) +{ + removeMapLayers( QStringList( theLayerId ), theEmitSignal ); +} + + void QgsMapLayerRegistry::removeAllMapLayers() { // moved before physically removing the layers diff --git a/src/core/qgsmaplayerregistry.h b/src/core/qgsmaplayerregistry.h index 77c89ff66389..c9db5c528279 100644 --- a/src/core/qgsmaplayerregistry.h +++ b/src/core/qgsmaplayerregistry.h @@ -70,9 +70,9 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject /** Add a layer to the map of loaded layers @returns NULL if unable to add layer, otherwise pointer to newly added layer @see addMapLayers - @note addMapLayers is prefered and must be used if adding more than one layer at a time + @note Use addMapLayers if adding more than one layer at a time */ - Q_DECL_DEPRECATED QgsMapLayer *addMapLayer( QgsMapLayer * theMapLayer, bool theEmitSignal = true ); + QgsMapLayer *addMapLayer( QgsMapLayer * theMapLayer, bool theEmitSignal = true ); /** Remove a set of layers from qgis @note As a side-effect QgsProject is made dirty. @@ -86,6 +86,18 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject */ void removeMapLayers( QStringList theLayerIds, bool theEmitSignal = true ); + /** Remove a layer from qgis + @note As a side-effect QgsProject is made dirty. + Any canvases using the affected layers will need to remove them + + If theEmitSignal is true (by default), a layersRemoved( QStringList theLayerIds ) + signal will be emitted indicating to any listeners that the layers are being removed. + + The layer being removed is deleted as well as the registry + table entry. + */ + void removeMapLayer( const QString& theLayerId, bool theEmitSignal = true ); + /** Remove all registered layers @note raises removedAll() As a side-effect QgsProject is made dirty.