Class: QgsMapLayerStore¶
A storage object for map layers, in which the layers are owned by the store and have their lifetime bound to the store.
Class Hierarchy¶
Base classes¶
- class qgis.core.QgsMapLayerStore[source]¶
Bases:
QObject- __init__(parent: QObject | None = None)
Constructor for QgsMapLayerStore.
- Parameters:
parent (Optional[QObject] = None)
- addMapLayer(self, layer: QgsMapLayer | None) QgsMapLayer | None[source]¶
Add a
layerto the store. Ownership of the layer is transferred to the store.The
layersAdded()andlayerWasAdded()signals will always be emitted. If you are adding multiple layers at once, you should useaddMapLayers()instead.- Parameters:
layer (Optional[QgsMapLayer]) – A layer to add to the store
- Return type:
Optional[QgsMapLayer]
- Returns:
Noneif unable to add layer, otherwise pointer to newly added layer
See also
Note
Use
addMapLayers()if adding more than one layer at a time.See also
- addMapLayers(self, layers: Iterable[QgsMapLayer]) List[QgsMapLayer]¶
Add a list of
layersto the store. Ownership of the layers is transferred to the store.The
layersAdded()andlayerWasAdded()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
FalsetoTrue, the layer data source is updated to the new one.- Return type:
- 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
- signal allLayersRemoved[source]¶
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.
- signal layerRemoved[source]¶
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.
- signal layerWasAdded[source]¶
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.
- signal layerWillBeRemoved[source]¶
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.
- signal layersAdded[source]¶
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.
- signal layersRemoved[source]¶
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.
- signal layersWillBeRemoved[source]¶
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.
- mapLayer(self, id: str | None) QgsMapLayer | None[source]¶
Retrieve a pointer to a layer by layer
id.- Parameters:
id (Optional[str]) – ID of layer to retrieve
- Return type:
Optional[QgsMapLayer]
- Returns:
matching layer, or
Noneif no matching layer found
See also
See also
- mapLayers(self) Any¶
Returns a map of all layers by layer ID.
See also
See also
See also
layers()- Return type:
- mapLayersByName(self, name: str | None) List[QgsMapLayer]¶
Retrieve a list of matching layers by layer
name.- Parameters:
name (Optional[str]) – name of layers to match
- Return type:
- Returns:
list of matching layers
See also
See also
- removeAllMapLayers(self)[source]¶
Removes all registered layers. These layers will also be deleted.
Note
Calling this method will cause the
removeAll()signal to be emitted.See also
See also
- removeMapLayer(self, id: str | None)[source]¶
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 (Optional[str]) – ID of the layer to remove
See also
See also
See also
removeMapLayer(self, layer: Optional[QgsMapLayer]) Remove a
layerfrom the store.The specified layer will be removed from the store. The layer will also be deleted.
- Parameters:
layer – The layer to remove.
Nonevalues are ignored.
See also
See also
See also
- removeMapLayers(self, layers: Iterable[QgsMapLayer])[source]¶
Remove a set of
layersfrom 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.
Nonevalues are ignored.
See also
See also
See also
- removeMapLayersById(self, layerIds: Iterable[str | None])¶
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[Optional[str]]) – list of IDs of the layers to remove
See also
See also
See also
- takeMapLayer(self, layer: QgsMapLayer | None) QgsMapLayer | None[source]¶
Takes a
layerfrom 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
- Parameters:
layer (Optional[QgsMapLayer])
- Return type:
Optional[QgsMapLayer]
- transferLayersFromStore(self, other: QgsMapLayerStore | None)[source]¶
Transfers all the map layers contained within another map layer store and adds them to this store. Note that
otherand this store must have the same thread affinity.- Parameters:
other (Optional[QgsMapLayerStore])
- validCount(self) int[source]¶
Returns the number of valid layers contained in the store.
Added in version 3.6.
- Return type:
int