Subgroup: Layer

Class: QgsLayerTreeLayer

class qgis.core.QgsLayerTreeLayer(layer: QgsMapLayer)

Bases: qgis._core.QgsLayerTreeNode

QgsLayerTreeLayer(layerId: str, name: str = ‘’, source: str = ‘’, provider: str = ‘’) Constructor for QgsLayerTreeLayer using weak references to layer ID, name, public source, and provider key.

Layer tree node points to a map layer.

The node can exist also without a valid instance of a layer (just ID). That means the referenced layer does not need to be loaded in order to use it in layer tree. In such case, resolveReferences() method can be called once the layer is loaded.

A map layer is supposed to be present in one layer tree just once. It is however possible that temporarily a layer exists in one tree more than just once, e.g. while reordering items with drag and drop.

New in version 2.4: Methods

attachToLayer
childEvent
clone
connectNotify
customEvent
disconnectNotify
dump
insertChildrenPrivate
isSignalConnected
layer Returns the map layer associated with this node.
layerId Returns the ID for the map layer associated with this node.
name Returns the layer’s name.
readCommonXml
readXml Read layer node from XML.
receivers
removeChildrenPrivate
resolveReferences Resolves reference to layer from stored layer ID (if it has not been resolved already)
sender
senderSignalIndex
setName Sets the layer’s name.
timerEvent
writeCommonXml
writeXml

Signals

layerLoaded Emitted when a previously unavailable layer got loaded.
layerWillBeUnloaded Emitted when a previously available layer got unloaded (from layer registry).

Attributes

attachToLayer(self)
childEvent()
clone(self) → QgsLayerTreeLayer
connectNotify()
customEvent()
disconnectNotify()
dump(self) → str
insertChildrenPrivate()
isSignalConnected()
layer(self) → QgsMapLayer

Returns the map layer associated with this node.

Warning

This can be (and often is!) a None, e.g. in the case of a layer node representing a layer which has not yet been fully loaded into a project, or a layer node representing a layer with an invalid data source. The returned pointer must ALWAYS be checked to avoid dereferencing a None.

See also

layerId()

layerId(self) → str

Returns the ID for the map layer associated with this node.

See also

layer()

layerLoaded

Emitted when a previously unavailable layer got loaded. [signal]

layerWillBeUnloaded

Emitted when a previously available layer got unloaded (from layer registry).

New in version 2.6: [signal]

name(self) → str

Returns the layer’s name.

See also

setName()

New in version 3.0.

readCommonXml()
readXml(element: QDomElement, context: QgsReadWriteContext) → QgsLayerTreeLayer

Read layer node from XML. Returns new instance. Does not resolve textual references to layers. Call resolveReferences() afterwards to do it.

readXml(element: QDomElement, project: QgsProject, context: QgsReadWriteContext) -> QgsLayerTreeLayer Read layer node from XML. Returns new instance. Also resolves textual references to layers from the project (calls resolveReferences() internally).

New in version 3.0.

receivers()
removeChildrenPrivate()
resolveReferences(self, project: QgsProject, looseMatching: bool = False)

Resolves reference to layer from stored layer ID (if it has not been resolved already)

New in version 3.0.

sender()
senderSignalIndex()
setName(self, n: str)

Sets the layer’s name.

See also

name()

New in version 3.0.

timerEvent()
writeCommonXml()
writeXml(self, parentElement: QDomElement, context: QgsReadWriteContext)