2016-02-14 03:50:23 +01:00
|
|
|
/** \ingroup core
|
2016-07-04 11:05:52 +10:00
|
|
|
* \class QgsMapLayerRegistry
|
2016-02-14 03:50:23 +01:00
|
|
|
* This class tracks map layers that are currently loaded and provides
|
2016-07-04 11:05:52 +10:00
|
|
|
* various methods to retrieve matching layers from the registry.
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2007-01-09 02:39:15 +00:00
|
|
|
class QgsMapLayerRegistry : QObject
|
2004-06-07 08:43:53 +00:00
|
|
|
{
|
2007-01-09 02:39:15 +00:00
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsmaplayerregistry.h>
|
|
|
|
%End
|
2012-04-05 00:04:24 +02:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
|
|
|
//! Returns the instance pointer, creating the object on the first call
|
|
|
|
static QgsMapLayerRegistry * instance();
|
2012-04-05 00:04:24 +02:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
~QgsMapLayerRegistry();
|
2004-10-21 17:27:38 +00:00
|
|
|
|
2016-07-04 11:05:52 +10:00
|
|
|
//! Returns the number of registered layers.
|
|
|
|
int count() const;
|
2004-10-21 17:27:38 +00:00
|
|
|
|
2016-07-04 11:05:52 +10:00
|
|
|
/** Retrieve a pointer to a registered layer by layer ID.
|
|
|
|
* @param theLayerId ID of layer to retrieve
|
|
|
|
* @returns matching layer, or nullptr if no matching layer found
|
|
|
|
* @see mapLayersByName()
|
|
|
|
* @see mapLayers()
|
|
|
|
*/
|
|
|
|
//TODO QGIS 3.0 - rename theLayerId to layerId
|
|
|
|
QgsMapLayer* mapLayer( const QString& theLayerId ) const;
|
2013-01-08 07:10:46 +10:00
|
|
|
|
2016-07-04 11:05:52 +10:00
|
|
|
/** Retrieve a list of matching registered layers by layer name.
|
|
|
|
* @param layerName name of layers to match
|
|
|
|
* @returns list of matching layers
|
|
|
|
* @see mapLayer()
|
|
|
|
* @see mapLayers()
|
|
|
|
*/
|
|
|
|
QList<QgsMapLayer *> mapLayersByName( const QString& layerName ) const;
|
|
|
|
|
2016-07-04 12:24:27 +10:00
|
|
|
/** Returns a map of all registered layers by layer ID.
|
2016-07-04 11:05:52 +10:00
|
|
|
* @see mapLayer()
|
|
|
|
* @see mapLayersByName()
|
|
|
|
* @see layers()
|
|
|
|
*/
|
|
|
|
QMap<QString, QgsMapLayer*> mapLayers() const;
|
2004-10-21 17:27:38 +00:00
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
|
|
|
* @brief
|
2016-07-04 11:05:52 +10:00
|
|
|
* Add a list of layers to the map of loaded layers.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* The layersAdded() and layerWasAdded() signals will always be emitted.
|
|
|
|
* The legendLayersAdded() signal is emitted only if addToLegend is true.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2013-06-23 16:00:16 +02:00
|
|
|
* @param theMapLayers A list of layer which should be added to the registry
|
|
|
|
* @param addToLegend If true (by default), the layers will be added to the
|
|
|
|
* legend and to the main canvas. If you have a private
|
2016-07-04 11:05:52 +10:00
|
|
|
* layer you can set this parameter to false to hide it.
|
2014-01-27 09:22:24 +01:00
|
|
|
* @param takeOwnership Ownership will be transferred to the layer registry.
|
2016-07-04 11:05:52 +10:00
|
|
|
* If you specify false here you have take care of deleting
|
2014-01-27 09:22:24 +01:00
|
|
|
* the layers yourself. Not available in python.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @return a list of the map layers that were added
|
2013-04-20 10:21:14 +02:00
|
|
|
* successfully. If a layer is invalid, or already exists in the registry,
|
|
|
|
* it will not be part of the returned QList.
|
|
|
|
*
|
|
|
|
* @note As a side-effect QgsProject is made dirty.
|
2016-07-04 11:05:52 +10:00
|
|
|
* @note takeOwnership is not available in the Python bindings - the registry will always
|
|
|
|
* take ownership
|
|
|
|
* @note added in QGIS 1.8
|
|
|
|
* @see addMapLayer()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *>& theMapLayers /Transfer/,
|
2013-04-20 10:21:14 +02:00
|
|
|
bool addToLegend = true );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
2016-07-04 11:05:52 +10:00
|
|
|
* Add a layer to the map of loaded layers.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* The layersAdded() and layerWasAdded() signals will always be emitted.
|
|
|
|
* The legendLayersAdded() signal is emitted only if addToLegend is true.
|
2013-04-20 10:21:14 +02:00
|
|
|
* If you are adding multiple layers at once, you should use
|
2016-07-04 11:05:52 +10:00
|
|
|
* addMapLayers() instead.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theMapLayer A layer to add to the registry
|
2013-04-20 10:21:14 +02:00
|
|
|
* @param addToLegend If true (by default), the layer will be added to the
|
|
|
|
* legend and to the main canvas. If you have a private
|
2016-07-04 11:05:52 +10:00
|
|
|
* layer you can set this parameter to false to hide it.
|
2014-01-27 09:22:24 +01:00
|
|
|
* @param takeOwnership Ownership will be transferred to the layer registry.
|
2016-07-04 11:05:52 +10:00
|
|
|
* If you specify false here you have take care of deleting
|
2014-01-27 09:22:24 +01:00
|
|
|
* the layer yourself. Not available in python.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-02-14 03:50:23 +01:00
|
|
|
* @return nullptr if unable to add layer, otherwise pointer to newly added layer
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
|
|
|
* @see addMapLayers
|
|
|
|
*
|
|
|
|
* @note As a side-effect QgsProject is made dirty.
|
|
|
|
* @note Use addMapLayers if adding more than one layer at a time
|
2016-07-04 11:05:52 +10:00
|
|
|
* @note takeOwnership is not available in the Python bindings - the registry will always
|
|
|
|
* take ownership
|
|
|
|
* @see addMapLayers()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2013-04-23 10:42:14 +02:00
|
|
|
QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer /Transfer/, bool addToLegend = true );
|
2013-04-20 10:21:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
2016-07-04 11:05:52 +10:00
|
|
|
* Remove a set of layers from the registry by layer ID.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* The specified layers will be removed from the registry. If the registry has ownership
|
|
|
|
* of any layers these layers will also be deleted.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theLayerIds list of IDs of the layers to remove
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @note As a side-effect the QgsProject instance is marked dirty.
|
|
|
|
* @note added in QGIS 1.8
|
|
|
|
* @see removeMapLayer()
|
|
|
|
* @see removeAllMapLayers()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
// TODO QGIS 3.0 - rename theLayerIds to layerIds
|
2015-10-07 11:55:34 +11:00
|
|
|
void removeMapLayers( const QStringList& theLayerIds );
|
2013-04-20 10:21:14 +02:00
|
|
|
|
2015-12-01 11:36:03 +01:00
|
|
|
/**
|
|
|
|
* @brief
|
2016-07-04 11:05:52 +10:00
|
|
|
* Remove a set of layers from the registry.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* The specified layers will be removed from the registry. If the registry has ownership
|
|
|
|
* of any layers these layers will also be deleted.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param layers A list of layers to remove. Null pointers are ignored.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @note As a side-effect the QgsProject instance is marked dirty.
|
|
|
|
* @see removeMapLayer()
|
|
|
|
* @see removeAllMapLayers()
|
2015-12-01 11:36:03 +01:00
|
|
|
*/
|
2015-12-01 11:36:03 +01:00
|
|
|
void removeMapLayers( const QList<QgsMapLayer*>& layers );
|
2015-12-01 11:36:03 +01:00
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
|
|
|
* @brief
|
2016-07-04 11:05:52 +10:00
|
|
|
* Remove a layer from the registry by layer ID.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* The specified layer will be removed from the registry. If the registry has ownership
|
|
|
|
* of the layer then it will also be deleted.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theLayerId ID of the layer to remove
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @note As a side-effect the QgsProject instance is marked dirty.
|
|
|
|
* @see removeMapLayers()
|
|
|
|
* @see removeAllMapLayers()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
// TODO QGIS 3.0 - rename theLayerId to layerId
|
2013-04-20 10:21:14 +02:00
|
|
|
void removeMapLayer( const QString& theLayerId );
|
|
|
|
|
2015-12-01 11:36:03 +01:00
|
|
|
/**
|
|
|
|
* @brief
|
2016-07-04 11:05:52 +10:00
|
|
|
* Remove a layer from the registry.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* The specified layer will be removed from the registry. If the registry has ownership
|
|
|
|
* of the layer then it will also be deleted.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param layer The layer to remove. Null pointers are ignored.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @note As a side-effect the QgsProject instance is marked dirty.
|
|
|
|
* @see removeMapLayers()
|
|
|
|
* @see removeAllMapLayers()
|
2015-12-01 11:36:03 +01:00
|
|
|
*/
|
|
|
|
void removeMapLayer( QgsMapLayer* layer );
|
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Removes all registered layers. If the registry has ownership
|
|
|
|
* of any layers these layers will also be deleted.
|
|
|
|
*
|
|
|
|
* @note As a side-effect the QgsProject instance is marked dirty.
|
|
|
|
* @note Calling this method will cause the removeAll() signal to
|
|
|
|
* be emitted.
|
|
|
|
* @see removeMapLayer()
|
|
|
|
* @see removeMapLayers()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void removeAllMapLayers();
|
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
|
|
|
* Clears all layer caches, resetting them to zero and
|
2012-09-24 02:28:15 +02:00
|
|
|
* freeing up any memory they may have been using. Layer
|
|
|
|
* caches are used to speed up rendering in certain situations
|
|
|
|
* see ticket #1974 for more details.
|
|
|
|
*/
|
2014-02-21 17:33:09 +07:00
|
|
|
//! @deprecated since 2.4 - does nothing
|
2013-12-05 18:27:45 +07:00
|
|
|
void clearAllLayerCaches() /Deprecated/;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Reload all registered layer's provider data caches, synchronising the layer
|
|
|
|
* with any changes in the datasource.
|
|
|
|
* @see QgsMapLayer::reload()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void reloadAllLayers();
|
|
|
|
|
|
|
|
signals:
|
2016-07-04 11:05:52 +10:00
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted when one or more layers are about to be removed from the registry.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theLayerIds A list of IDs for the layers which are to be removed.
|
|
|
|
* @see layerWillBeRemoved()
|
|
|
|
* @see layersRemoved()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
// TODO QGIS 3.0 - rename theLayerIds to layerIds
|
2015-10-26 22:46:25 +11:00
|
|
|
void layersWillBeRemoved( const QStringList& theLayerIds );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted when one or more layers are about to be removed from the registry.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param layers A list of layers which are to be removed.
|
|
|
|
* @see layerWillBeRemoved()
|
|
|
|
* @see layersRemoved()
|
2015-12-01 11:36:03 +01:00
|
|
|
*/
|
2015-12-01 11:36:03 +01:00
|
|
|
void layersWillBeRemoved( const QList<QgsMapLayer*>& layers );
|
2015-12-01 11:36:03 +01:00
|
|
|
|
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted when a layer is about to be removed from the registry.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theLayerId The ID of the layer to be removed.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
|
|
|
* @note Consider using {@link layersWillBeRemoved()} instead
|
2016-07-04 11:05:52 +10:00
|
|
|
* @see layersWillBeRemoved()
|
|
|
|
* @see layerRemoved()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
//TODO QGIS 3.0 - rename theLayerId to layerId
|
2015-10-26 22:46:25 +11:00
|
|
|
void layerWillBeRemoved( const QString& theLayerId );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-12-01 11:36:03 +01:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted when a layer is about to be removed from the registry.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param layer The layer to be removed.
|
2015-12-01 11:36:03 +01:00
|
|
|
*
|
|
|
|
* @note Consider using {@link layersWillBeRemoved()} instead
|
2016-07-04 11:05:52 +10:00
|
|
|
* @see layersWillBeRemoved()
|
|
|
|
* @see layerRemoved()
|
2015-12-01 11:36:03 +01:00
|
|
|
*/
|
|
|
|
void layerWillBeRemoved( QgsMapLayer* layer );
|
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted after one or more layers were removed from the registry.
|
2014-01-27 09:22:24 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theLayerIds A list of IDs of the layers which were removed.
|
|
|
|
* @see layersWillBeRemoved()
|
2014-01-27 09:22:24 +01:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
//TODO QGIS 3.0 - rename theLayerIds to layerIds
|
2015-10-26 22:46:25 +11:00
|
|
|
void layersRemoved( const QStringList& theLayerIds );
|
2014-01-27 09:22:24 +01:00
|
|
|
|
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted after a layer was removed from the registry.
|
2014-01-27 09:22:24 +01:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theLayerId The ID of the layer removed.
|
2014-01-27 09:22:24 +01:00
|
|
|
*
|
|
|
|
* @note Consider using {@link layersRemoved()} instead
|
2016-07-04 11:05:52 +10:00
|
|
|
* @see layerWillBeRemoved()
|
2014-01-27 09:22:24 +01:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
//TODO QGIS 3.0 - rename theLayerId to layerId
|
2015-10-26 22:46:25 +11:00
|
|
|
void layerRemoved( const QString& theLayerId );
|
2014-01-27 09:22:24 +01:00
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted when all layers are removed, before {@link layersWillBeRemoved()} and
|
|
|
|
* {@link layerWillBeRemoved()} signals are emitted. The layersWillBeRemoved() and
|
|
|
|
* layerWillBeRemoved() signals will still be emitted following this signal.
|
2013-04-20 10:21:14 +02:00
|
|
|
* You can use this signal to do easy (and fast) cleanup.
|
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
//TODO QGIS 3.0 - rename to past tense
|
2013-04-20 10:21:14 +02:00
|
|
|
void removeAll();
|
|
|
|
|
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted when one or more layers were added to the registry.
|
2013-04-20 10:21:14 +02:00
|
|
|
* This signal is also emitted for layers added to the registry,
|
2016-07-04 11:05:52 +10:00
|
|
|
* but not to the legend.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theMapLayers List of layers which have been added.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
|
|
|
* @see legendLayersAdded()
|
2016-07-04 11:05:52 +10:00
|
|
|
* @see layerWasAdded()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
//TODO QGIS 3.0 - rename theMapLayers to mapLayers
|
2015-10-26 22:46:25 +11:00
|
|
|
void layersAdded( const QList<QgsMapLayer *>& theMapLayers );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2013-04-20 10:21:14 +02:00
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted when a layer was added to the registry.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theMapLayer The ID of the layer which has been added.
|
2013-04-20 10:21:14 +02:00
|
|
|
*
|
|
|
|
* @note Consider using {@link layersAdded()} instead
|
2016-07-04 11:05:52 +10:00
|
|
|
* @see layersAdded()
|
2013-04-20 10:21:14 +02:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
// TODO QGIS 3.0 - rename theMapLayer to layer
|
2013-04-20 10:21:14 +02:00
|
|
|
void layerWasAdded( QgsMapLayer* theMapLayer );
|
|
|
|
|
|
|
|
/**
|
2016-07-04 11:05:52 +10:00
|
|
|
* Emitted, when a layer was added to the registry and the legend.
|
|
|
|
* Layers can also be private layers, which are signalled by
|
2013-04-20 10:21:14 +02:00
|
|
|
* {@link layersAdded()} and {@link layerWasAdded()} but will not be
|
|
|
|
* advertised by this signal.
|
|
|
|
*
|
2016-07-04 11:05:52 +10:00
|
|
|
* @param theMapLayers List of {@link QgsMapLayer}s which were added to the legend.
|
2012-09-24 02:28:15 +02:00
|
|
|
*/
|
2016-07-04 11:05:52 +10:00
|
|
|
//TODO QGIS 3.0 rename theMapLayers to mapLayers
|
2015-10-26 22:46:25 +11:00
|
|
|
void legendLayersAdded( const QList<QgsMapLayer*>& theMapLayers );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
private:
|
2016-02-14 03:50:23 +01:00
|
|
|
//! private singleton constructor
|
|
|
|
QgsMapLayerRegistry();
|
2014-08-18 11:47:08 +02:00
|
|
|
|
2013-12-08 22:37:45 +02:00
|
|
|
void connectNotify( const char * signal );
|
2016-07-04 11:05:52 +10:00
|
|
|
};
|