QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
A storage object for map layers, in which the layers are owned by the store and have their lifetime bound to the store. More...
#include <qgsmaplayerstore.h>
Signals | |
void | allLayersRemoved () |
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted. | |
void | layerRemoved (const QString &layerId) |
Emitted after a layer was removed from the store. | |
void | layersAdded (const QList< QgsMapLayer * > &layers) |
Emitted when one or more layers were added to the store. | |
void | layersRemoved (const QStringList &layerIds) |
Emitted after one or more layers were removed from the store. | |
void | layersWillBeRemoved (const QList< QgsMapLayer * > &layers) |
Emitted when one or more layers are about to be removed from the store. | |
void | layersWillBeRemoved (const QStringList &layerIds) |
Emitted when one or more layers are about to be removed from the store. | |
void | layerWasAdded (QgsMapLayer *layer) |
Emitted when a layer was added to the store. | |
void | layerWillBeRemoved (const QString &layerId) |
Emitted when a layer is about to be removed from the store. | |
void | layerWillBeRemoved (QgsMapLayer *layer) |
Emitted when a layer is about to be removed from the store. | |
Public Member Functions | |
QgsMapLayerStore (QObject *parent=nullptr) | |
Constructor for QgsMapLayerStore. | |
~QgsMapLayerStore () override | |
QgsMapLayer * | addMapLayer (QgsMapLayer *layer, bool takeOwnership=true) |
Add a layer to the store. | |
QList< QgsMapLayer * > | addMapLayers (const QList< QgsMapLayer * > &layers, bool takeOwnership=true) |
Add a list of layers to the store. | |
int | count () const |
Returns the number of layers contained in the store. | |
template<typename T > | |
QVector< T > | layers () const |
Returns a list of registered map layers with a specified layer type. | |
QgsMapLayer * | mapLayer (const QString &id) const |
Retrieve a pointer to a layer by layer id. | |
QMap< QString, QgsMapLayer * > | mapLayers () const |
Returns a map of all layers by layer ID. | |
QList< QgsMapLayer * > | mapLayersByName (const QString &name) const |
Retrieve a list of matching layers by layer name. | |
void | removeAllMapLayers () |
Removes all registered layers. | |
void | removeMapLayer (const QString &id) |
Remove a layer from the store by layer id. | |
void | removeMapLayer (QgsMapLayer *layer) |
Remove a layer from the store. | |
void | removeMapLayers (const QList< QgsMapLayer * > &layers) |
Remove a set of layers from the store. | |
void | removeMapLayers (const QStringList &layerIds) |
Remove a set of layers from the store by layer ID. | |
QgsMapLayer * | takeMapLayer (QgsMapLayer *layer) |
Takes a layer from the store. | |
void | transferLayersFromStore (QgsMapLayerStore *other) |
Transfers all the map layers contained within another map layer store and adds them to this store. | |
int | validCount () const |
Returns the number of valid layers contained in the store. | |
QMap< QString, QgsMapLayer * > | validMapLayers () const |
Returns a map of all valid layers by layer ID. | |
A storage object for map layers, in which the layers are owned by the store and have their lifetime bound to the store.
Definition at line 34 of file qgsmaplayerstore.h.
|
explicit |
Constructor for QgsMapLayerStore.
Definition at line 25 of file qgsmaplayerstore.cpp.
|
override |
Definition at line 29 of file qgsmaplayerstore.cpp.
QgsMapLayer * QgsMapLayerStore::addMapLayer | ( | QgsMapLayer * | layer, |
bool | takeOwnership = true |
||
) |
Add a layer to the store.
Ownership of the layer is transferred to the store.
The layersAdded() and layerWasAdded() signals will always be emitted. If you are adding multiple layers at once, you should use addMapLayers() instead.
layer | A layer to add to the store |
takeOwnership | Ownership will be transferred to the layer store. If you specify false here you have take care of deleting the layers yourself. Not available in Python. |
nullptr
if unable to add layer, otherwise pointer to newly added layerDefinition at line 121 of file qgsmaplayerstore.cpp.
QList< QgsMapLayer * > QgsMapLayerStore::addMapLayers | ( | const QList< QgsMapLayer * > & | layers, |
bool | takeOwnership = true |
||
) |
Add a list of layers to the store.
Ownership of the layers is transferred to the store.
The layersAdded() and layerWasAdded() signals will always be emitted.
layers | A list of layer which should be added to the store. |
takeOwnership | Ownership will be transferred to the layer store. If you specify false here you have take care of deleting the layers yourself. Not available in Python. |
false
to true
, the layer data source is updated to the new one.Definition at line 79 of file qgsmaplayerstore.cpp.
|
signal |
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted.
The layersWillBeRemoved() and layerWillBeRemoved() signals will still be emitted following this signal. You can use this signal to do easy (and fast) cleanup.
int QgsMapLayerStore::count | ( | ) | const |
Returns the number of layers contained in the store.
Definition at line 34 of file qgsmaplayerstore.cpp.
|
signal |
Emitted after a layer was removed from the store.
layerId | The ID of the layer removed. |
|
inline |
Returns a list of registered map layers with a specified layer type.
QVector<QgsVectorLayer*> vectorLayers = store->layers<QgsVectorLayer*>();
Definition at line 123 of file qgsmaplayerstore.h.
|
signal |
Emitted when one or more layers were added to the store.
layers | List of layers which have been added. |
|
signal |
Emitted after one or more layers were removed from the store.
layerIds | A list of IDs of the layers which were removed. |
|
signal |
Emitted when one or more layers are about to be removed from the store.
layers | A list of layers which are to be removed. |
|
signal |
Emitted when one or more layers are about to be removed from the store.
layerIds | A list of IDs for the layers which are to be removed. |
|
signal |
Emitted when a layer was added to the store.
|
signal |
Emitted when a layer is about to be removed from the store.
layerId | The ID of the layer to be removed. |
|
signal |
Emitted when a layer is about to be removed from the store.
layer | The layer to be removed. |
QgsMapLayer * QgsMapLayerStore::mapLayer | ( | const QString & | id | ) | const |
Retrieve a pointer to a layer by layer id.
id | ID of layer to retrieve |
nullptr
if no matching layer found Definition at line 55 of file qgsmaplayerstore.cpp.
QMap< QString, QgsMapLayer * > QgsMapLayerStore::mapLayers | ( | ) | const |
Returns a map of all layers by layer ID.
Definition at line 269 of file qgsmaplayerstore.cpp.
QList< QgsMapLayer * > QgsMapLayerStore::mapLayersByName | ( | const QString & | name | ) | const |
Retrieve a list of matching layers by layer name.
name | name of layers to match |
Definition at line 63 of file qgsmaplayerstore.cpp.
void QgsMapLayerStore::removeAllMapLayers | ( | ) |
Removes all registered layers.
These layers will also be deleted.
Definition at line 226 of file qgsmaplayerstore.cpp.
void QgsMapLayerStore::removeMapLayer | ( | const QString & | id | ) |
Remove a layer from the store by layer id.
The specified layer will be removed from the store. The layer will also be deleted.
id | ID of the layer to remove |
Definition at line 188 of file qgsmaplayerstore.cpp.
void QgsMapLayerStore::removeMapLayer | ( | QgsMapLayer * | layer | ) |
Remove a layer from the store.
The specified layer will be removed from the store. The layer will also be deleted.
layer | The layer to remove. nullptr values are ignored. |
Definition at line 195 of file qgsmaplayerstore.cpp.
void QgsMapLayerStore::removeMapLayers | ( | const QList< QgsMapLayer * > & | layers | ) |
Remove a set of layers from the store.
The specified layers will be removed from the store. These layers will also be deleted.
layers | A list of layers to remove. nullptr values are ignored. |
Definition at line 144 of file qgsmaplayerstore.cpp.
void QgsMapLayerStore::removeMapLayers | ( | const QStringList & | layerIds | ) |
Remove a set of layers from the store by layer ID.
The specified layers will be removed from the store. These layers will also be deleted.
layerIds | list of IDs of the layers to remove |
Definition at line 130 of file qgsmaplayerstore.cpp.
QgsMapLayer * QgsMapLayerStore::takeMapLayer | ( | QgsMapLayer * | layer | ) |
Takes a layer from the store.
If the layer was owned by the store, the layer will be returned without deleting it. The caller takes ownership of the layer and is responsible for deleting it.
Definition at line 203 of file qgsmaplayerstore.cpp.
void QgsMapLayerStore::transferLayersFromStore | ( | QgsMapLayerStore * | other | ) |
Transfers all the map layers contained within another map layer store and adds them to this store.
Note that other and this store must have the same thread affinity.
Definition at line 237 of file qgsmaplayerstore.cpp.
int QgsMapLayerStore::validCount | ( | ) | const |
Returns the number of valid layers contained in the store.
Definition at line 41 of file qgsmaplayerstore.cpp.
QMap< QString, QgsMapLayer * > QgsMapLayerStore::validMapLayers | ( | ) | const |
Returns a map of all valid layers by layer ID.
Definition at line 277 of file qgsmaplayerstore.cpp.