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: Enums

Methods

attachToLayer

childEvent

clone

connectNotify

customEvent

disconnectNotify

dump

insertChildrenPrivate

isSignalConnected

labelExpression

Returns the expression member of the LayerTreeNode

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

setLabelExpression

set the expression to evaluate

setName

Sets the layer’s name.

setUseLayerName

Uses the layer’s name if use is true, or the name manually set if false.

timerEvent

useLayerName

Returns whether the layer’s name is used, or the name manually set.

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()
labelExpression(self) → str

Returns the expression member of the LayerTreeNode

New in version 3.10.

layer(self) → QgsMapLayer

Returns the map layer associated with this node.

Warning

This can be (and often is!) 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 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()
setLabelExpression(self, expression: str)

set the expression to evaluate

New in version 3.10.

setName(self, n: str)

Sets the layer’s name.

See also

name()

New in version 3.0.

setUseLayerName(self, use: bool = True)

Uses the layer’s name if use is true, or the name manually set if false.

New in version 3.8.

timerEvent()
useLayerName(self) → bool

Returns whether the layer’s name is used, or the name manually set.

New in version 3.8.

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