QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
Signals | Public Member Functions | List of all members
QgsMapLayerStore Class Reference

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>

Inheritance diagram for QgsMapLayerStore:
Inheritance graph
[legend]

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
 
QgsMapLayeraddMapLayer (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.
 
QgsMapLayermapLayer (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.
 
QgsMapLayertakeMapLayer (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ QgsMapLayerStore()

QgsMapLayerStore::QgsMapLayerStore ( QObject *  parent = nullptr)
explicit

Constructor for QgsMapLayerStore.

Definition at line 24 of file qgsmaplayerstore.cpp.

◆ ~QgsMapLayerStore()

QgsMapLayerStore::~QgsMapLayerStore ( )
override

Definition at line 28 of file qgsmaplayerstore.cpp.

Member Function Documentation

◆ addMapLayer()

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.

Parameters
layerA layer to add to the store
takeOwnershipOwnership 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.
Returns
nullptr if unable to add layer, otherwise pointer to newly added layer
See also
addMapLayers
Note
Use addMapLayers() if adding more than one layer at a time.
See also
addMapLayers()

Definition at line 120 of file qgsmaplayerstore.cpp.

◆ addMapLayers()

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.

Parameters
layersA list of layer which should be added to the store.
takeOwnershipOwnership 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.
Note
If a layer with the same id is already in the store it is not added again, but if the validity of the layer has changed from false to true, the layer data source is updated to the new one.
Returns
a list of the map layers that were added successfully. If a layer already exists in the store, it will not be part of the returned list.
See also
addMapLayer()

Definition at line 78 of file qgsmaplayerstore.cpp.

◆ allLayersRemoved

void QgsMapLayerStore::allLayersRemoved ( )
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.

◆ count()

int QgsMapLayerStore::count ( ) const

Returns the number of layers contained in the store.

Definition at line 33 of file qgsmaplayerstore.cpp.

◆ layerRemoved

void QgsMapLayerStore::layerRemoved ( const QString &  layerId)
signal

Emitted after a layer was removed from the store.

Parameters
layerIdThe ID of the layer removed.
Note
Consider using layersRemoved() instead
See also
layerWillBeRemoved()

◆ layers()

template<typename T >
QVector< T > QgsMapLayerStore::layers ( ) const
inline

Returns a list of registered map layers with a specified layer type.

Example

QVector<QgsVectorLayer*> vectorLayers = store->layers<QgsVectorLayer*>();
Note
not available in Python bindings
See also
mapLayers()

Definition at line 123 of file qgsmaplayerstore.h.

◆ layersAdded

void QgsMapLayerStore::layersAdded ( const QList< QgsMapLayer * > &  layers)
signal

Emitted when one or more layers were added to the store.

Parameters
layersList of layers which have been added.
See also
layerWasAdded()

◆ layersRemoved

void QgsMapLayerStore::layersRemoved ( const QStringList &  layerIds)
signal

Emitted after one or more layers were removed from the store.

Parameters
layerIdsA list of IDs of the layers which were removed.
See also
layersWillBeRemoved()

◆ layersWillBeRemoved [1/2]

void QgsMapLayerStore::layersWillBeRemoved ( const QList< QgsMapLayer * > &  layers)
signal

Emitted when one or more layers are about to be removed from the store.

Parameters
layersA list of layers which are to be removed.
See also
layerWillBeRemoved()
layersRemoved()

◆ layersWillBeRemoved [2/2]

void QgsMapLayerStore::layersWillBeRemoved ( const QStringList &  layerIds)
signal

Emitted when one or more layers are about to be removed from the store.

Parameters
layerIdsA list of IDs for the layers which are to be removed.
See also
layerWillBeRemoved()
layersRemoved()

◆ layerWasAdded

void QgsMapLayerStore::layerWasAdded ( QgsMapLayer layer)
signal

Emitted when a layer was added to the store.

Note
Consider using layersAdded() instead
See also
layersAdded()

◆ layerWillBeRemoved [1/2]

void QgsMapLayerStore::layerWillBeRemoved ( const QString &  layerId)
signal

Emitted when a layer is about to be removed from the store.

Parameters
layerIdThe ID of the layer to be removed.
Note
Consider using layersWillBeRemoved() instead.
See also
layersWillBeRemoved()
layerRemoved()

◆ layerWillBeRemoved [2/2]

void QgsMapLayerStore::layerWillBeRemoved ( QgsMapLayer layer)
signal

Emitted when a layer is about to be removed from the store.

Parameters
layerThe layer to be removed.
Note
Consider using layersWillBeRemoved() instead.
See also
layersWillBeRemoved()
layerRemoved()

◆ mapLayer()

QgsMapLayer * QgsMapLayerStore::mapLayer ( const QString &  id) const

Retrieve a pointer to a layer by layer id.

Parameters
idID of layer to retrieve
Returns
matching layer, or nullptr if no matching layer found
See also
mapLayersByName()
mapLayers()

Definition at line 54 of file qgsmaplayerstore.cpp.

◆ mapLayers()

QMap< QString, QgsMapLayer * > QgsMapLayerStore::mapLayers ( ) const

Returns a map of all layers by layer ID.

See also
mapLayer()
mapLayersByName()
layers()

Definition at line 268 of file qgsmaplayerstore.cpp.

◆ mapLayersByName()

QList< QgsMapLayer * > QgsMapLayerStore::mapLayersByName ( const QString &  name) const

Retrieve a list of matching layers by layer name.

Parameters
namename of layers to match
Returns
list of matching layers
See also
mapLayer()
mapLayers()

Definition at line 62 of file qgsmaplayerstore.cpp.

◆ removeAllMapLayers()

void QgsMapLayerStore::removeAllMapLayers ( )

Removes all registered layers.

These layers will also be deleted.

Note
Calling this method will cause the removeAll() signal to be emitted.
See also
removeMapLayer()
removeMapLayers()

Definition at line 225 of file qgsmaplayerstore.cpp.

◆ removeMapLayer() [1/2]

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.

Parameters
idID of the layer to remove
See also
takeMapLayer()
removeMapLayers()
removeAllMapLayers()

Definition at line 187 of file qgsmaplayerstore.cpp.

◆ removeMapLayer() [2/2]

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.

Parameters
layerThe layer to remove. nullptr values are ignored.
See also
takeMapLayer()
removeMapLayers()
removeAllMapLayers()

Definition at line 194 of file qgsmaplayerstore.cpp.

◆ removeMapLayers() [1/2]

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.

Parameters
layersA list of layers to remove. nullptr values are ignored.
See also
takeMapLayer()
removeMapLayer()
removeAllMapLayers()

Definition at line 143 of file qgsmaplayerstore.cpp.

◆ removeMapLayers() [2/2]

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.

Parameters
layerIdslist of IDs of the layers to remove
See also
takeMapLayer()
removeMapLayer()
removeAllMapLayers()
Note
available in Python bindings as removeMapLayersById.

Definition at line 129 of file qgsmaplayerstore.cpp.

◆ takeMapLayer()

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.

See also
removeMapLayer()

Definition at line 202 of file qgsmaplayerstore.cpp.

◆ transferLayersFromStore()

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 236 of file qgsmaplayerstore.cpp.

◆ validCount()

int QgsMapLayerStore::validCount ( ) const

Returns the number of valid layers contained in the store.

Since
QGIS 3.6

Definition at line 40 of file qgsmaplayerstore.cpp.

◆ validMapLayers()

QMap< QString, QgsMapLayer * > QgsMapLayerStore::validMapLayers ( ) const

Returns a map of all valid layers by layer ID.

See also
mapLayer()
mapLayersByName()
layers()
Since
QGIS 3.6

Definition at line 276 of file qgsmaplayerstore.cpp.


The documentation for this class was generated from the following files: