Class: QgsMapLayerStore

class qgis.core.QgsMapLayerStore

Bases: PyQt5.QtCore.QObject

A storage object for map layers, in which the layers are owned by the store and have their lifetime bound to the store.

New in version 3.0.

QgsMapLayerStore(parent: QObject = None) Constructor for QgsMapLayerStore.

Methods

addMapLayer

Add a layer to the store.

addMapLayers

Add a list of layers to the store.

childEvent

connectNotify

count

Returns the number of layers contained in the store.

customEvent

disconnectNotify

isSignalConnected

mapLayer

Retrieve a pointer to a layer by layer id.

mapLayers

Returns a map of all layers by layer ID.

mapLayersByName

Retrieve a list of matching layers by layer name.

receivers

removeAllMapLayers

Removes all registered layers.

removeMapLayer

Remove a layer from the store by layer id.

removeMapLayers

Remove a set of layers from the store.

removeMapLayersById

Remove a set of layers from the store by layer ID.

sender

senderSignalIndex

takeMapLayer

Takes a layer from the store.

timerEvent

transferLayersFromStore

Transfers all the map layers contained within another map layer store and adds them to this store.

validCount

Returns the number of valid layers contained in the store.

validMapLayers

Returns a map of all valid layers by layer ID.

Signals

allLayersRemoved

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layerRemoved

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layerWasAdded

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layerWillBeRemoved

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layersAdded

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layersRemoved

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layersWillBeRemoved

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

addMapLayer(self, layer: QgsMapLayer) QgsMapLayer

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:

layer (QgsMapLayer) – A layer to add to the store

Return type:

QgsMapLayer

Returns:

None 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()

addMapLayers(self, layers: Iterable[QgsMapLayer]) List[QgsMapLayer]

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:

layers (Iterable[QgsMapLayer]) – A list of layer which should be added to the store.

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.

Return type:

List[QgsMapLayer]

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()

allLayersRemoved

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
count(self) int

Returns the number of layers contained in the store.

Return type:

int

customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
isSignalConnected(self, QMetaMethod) bool
layerRemoved

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

layerWasAdded

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

layerWillBeRemoved

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

layersAdded

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

layersRemoved

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

layersWillBeRemoved

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

mapLayer(self, id: str) QgsMapLayer

Retrieve a pointer to a layer by layer id.

Parameters:

id (str) – ID of layer to retrieve

Return type:

QgsMapLayer

Returns:

matching layer, or None if no matching layer found

See also

mapLayers()

mapLayers(self) object

Returns a map of all layers by layer ID.

See also

mapLayer()

See also

layers()

Return type:

object

mapLayersByName(self, name: str) List[QgsMapLayer]

Retrieve a list of matching layers by layer name.

Parameters:

name (str) – name of layers to match

Return type:

List[QgsMapLayer]

Returns:

list of matching layers

See also

mapLayer()

See also

mapLayers()

receivers(self, PYQT_SIGNAL) int
removeAllMapLayers(self)

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()

removeMapLayer(self, id: str)

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:

id (str) – ID of the layer to remove

See also

takeMapLayer()

removeMapLayer(self, layer: QgsMapLayer) Remove a layer from the store.

The specified layer will be removed from the store. The layer will also be deleted.

Parameters:

layer – The layer to remove. None values are ignored.

See also

takeMapLayer()

removeMapLayers(self, layers: Iterable[QgsMapLayer])

Remove a set of layers from the store.

The specified layers will be removed from the store. These layers will also be deleted.

Parameters:

layers (Iterable[QgsMapLayer]) – A list of layers to remove. None values are ignored.

See also

takeMapLayer()

See also

removeMapLayer()

removeMapLayersById(self, layerIds: Iterable[str])

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:

layerIds (Iterable[str]) – list of IDs of the layers to remove

See also

takeMapLayer()

See also

removeMapLayer()

Note

available in Python bindings as removeMapLayersById.

sender(self) QObject
senderSignalIndex(self) int
takeMapLayer(self, layer: QgsMapLayer) QgsMapLayer

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()

Parameters:

layer (QgsMapLayer) –

Return type:

QgsMapLayer

timerEvent(self, QTimerEvent)
transferLayersFromStore(self, other: QgsMapLayerStore)

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.

Parameters:

other (QgsMapLayerStore) –

validCount(self) int

Returns the number of valid layers contained in the store.

New in version 3.6.

Return type:

int

validMapLayers(self) object

Returns a map of all valid layers by layer ID.

See also

mapLayer()

See also

layers()

New in version 3.6.

Return type:

object