QGIS API Documentation
3.8.0-Zanzibar (11aff65)
|
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. More... | |
void | layerRemoved (const QString &layerId) |
Emitted after a layer was removed from the store. More... | |
void | layersAdded (const QList< QgsMapLayer *> &layers) |
Emitted when one or more layers were added to the store. More... | |
void | layersRemoved (const QStringList &layerIds) |
Emitted after one or more layers were removed from the store. More... | |
void | layersWillBeRemoved (const QStringList &layerIds) |
Emitted when one or more layers are about to be removed from the store. More... | |
void | layersWillBeRemoved (const QList< QgsMapLayer *> &layers) |
Emitted when one or more layers are about to be removed from the store. More... | |
void | layerWasAdded (QgsMapLayer *layer) |
Emitted when a layer was added to the store. More... | |
void | layerWillBeRemoved (const QString &layerId) |
Emitted when a layer is about to be removed from the store. More... | |
void | layerWillBeRemoved (QgsMapLayer *layer) |
Emitted when a layer is about to be removed from the store. More... | |
Public Member Functions | |
QgsMapLayerStore (QObject *parent=nullptr) | |
Constructor for QgsMapLayerStore. More... | |
~QgsMapLayerStore () override | |
QgsMapLayer * | addMapLayer (QgsMapLayer *layer, bool takeOwnership=true) |
Add a layer to the store. More... | |
QList< QgsMapLayer * > | addMapLayers (const QList< QgsMapLayer *> &layers, bool takeOwnership=true) |
Add a list of layers to the store. More... | |
int | count () const |
Returns the number of layers contained in the store. More... | |
template<typename T > | |
QVector< T > | layers () const |
Returns a list of registered map layers with a specified layer type. More... | |
QgsMapLayer * | mapLayer (const QString &id) const |
Retrieve a pointer to a layer by layer id. More... | |
QMap< QString, QgsMapLayer * > | mapLayers () const |
Returns a map of all layers by layer ID. More... | |
QList< QgsMapLayer * > | mapLayersByName (const QString &name) const |
Retrieve a list of matching layers by layer name. More... | |
void | removeAllMapLayers () |
Removes all registered layers. More... | |
void | removeMapLayer (const QString &id) |
Remove a layer from the store by layer id. More... | |
void | removeMapLayer (QgsMapLayer *layer) |
Remove a layer from the store. More... | |
void | removeMapLayers (const QStringList &layerIds) |
Remove a set of layers from the store by layer ID. More... | |
void | removeMapLayers (const QList< QgsMapLayer *> &layers) |
Remove a set of layers from the store. More... | |
QgsMapLayer * | takeMapLayer (QgsMapLayer *layer) |
Takes a layer from the store. More... | |
void | transferLayersFromStore (QgsMapLayerStore *other) |
Transfers all the map layers contained within another map layer store and adds them to this store. More... | |
int | validCount () const |
Returns the number of valid layers contained in the store. More... | |
QMap< QString, QgsMapLayer * > | validMapLayers () const |
Returns a map of all valid layers by layer ID. More... | |
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 35 of file qgsmaplayerstore.h.
|
explicit |
Constructor for QgsMapLayerStore.
Definition at line 23 of file qgsmaplayerstore.cpp.
|
override |
Definition at line 27 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 105 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 68 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 32 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.
Example:
QVector<QgsVectorLayer*> vectorLayers = store->layers<QgsVectorLayer*>();
Definition at line 124 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.
layerIds | A list of IDs for the layers which are to be 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 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 49 of file qgsmaplayerstore.cpp.
QMap< QString, QgsMapLayer * > QgsMapLayerStore::mapLayers | ( | ) | const |
Returns a map of all layers by layer ID.
Definition at line 235 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 54 of file qgsmaplayerstore.cpp.
void QgsMapLayerStore::removeAllMapLayers | ( | ) |
Removes all registered layers.
These layers will also be deleted.
Definition at line 198 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 166 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 171 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 112 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 124 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 177 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 207 of file qgsmaplayerstore.cpp.
int QgsMapLayerStore::validCount | ( | ) | const |
Returns the number of valid layers contained in the store.
Definition at line 37 of file qgsmaplayerstore.cpp.
QMap< QString, QgsMapLayer * > QgsMapLayerStore::validMapLayers | ( | ) | const |
Returns a map of all valid layers by layer ID.
Definition at line 240 of file qgsmaplayerstore.cpp.