Class: QgsLayerTree

class qgis.core.QgsLayerTree

Bases: QgsLayerTreeGroup

Namespace with helper functions for layer tree operations.

Only generally useful routines should be here. Miscellaneous utility functions for work with the layer tree are in QgsLayerTreeUtils class.

QgsLayerTree() Create a new empty layer tree

Methods

childEvent

clear

Clear any information from this layer tree.

clone

rtype:

QgsLayerTree

connectNotify

customEvent

customLayerOrder

The order in which layers will be rendered on the canvas.

disconnectNotify

hasCustomLayerOrder

Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.

insertChildrenPrivate

Low-level insertion of children to the node.

isGroup

Check whether the node is a valid group node

isLayer

Check whether the node is a valid layer node

isSignalConnected

layerOrder

The order in which layers will be rendered on the canvas.

nodeVisibilityChanged

readCommonXml

Read common XML elements.

readLayerOrderFromXml

Load the layer order from an XML element.

readXml

Load the layer tree from an XML element.

receivers

removeChildrenPrivate

Low-level removal of children from the node.

sender

senderSignalIndex

setCustomLayerOrder

The order in which layers will be rendered on the canvas.

setCustomLayerOrderByIds

The order in which layers will be rendered on the canvas.

setHasCustomLayerOrder

Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.

timerEvent

updateChildVisibilityMutuallyExclusive

Set check state of children - if mutually exclusive

writeCommonXml

Write common XML elements.

writeXml

param parentElement:

Signals

customLayerOrderChanged

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

hasCustomLayerOrderChanged

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

layerOrderChanged

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

childEvent(self, QChildEvent)
clear(self)

Clear any information from this layer tree.

clone(self) QgsLayerTree
Return type:

QgsLayerTree

connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
customLayerOrder(self) List[QgsMapLayer]

The order in which layers will be rendered on the canvas. Will only be used if the property hasCustomLayerOrder is True. If you need the current layer order that is active, prefer using layerOrder().

See also

layerOrder()

Return type:

List[QgsMapLayer]

customLayerOrderChanged

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

disconnectNotify(self, QMetaMethod)
hasCustomLayerOrder(self) bool

Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.

Return type:

bool

hasCustomLayerOrderChanged

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

insertChildrenPrivate(self, index: int, nodes: Iterable[QgsLayerTreeNode])

Low-level insertion of children to the node. The children must not have any parent yet!

isGroup(node: QgsLayerTreeNode) bool

Check whether the node is a valid group node

Parameters:

node (QgsLayerTreeNode) –

Return type:

bool

isLayer(node: QgsLayerTreeNode) bool

Check whether the node is a valid layer node

Parameters:

node (QgsLayerTreeNode) –

Return type:

bool

isSignalConnected(self, QMetaMethod) bool
layerOrder(self) List[QgsMapLayer]

The order in which layers will be rendered on the canvas. Depending on hasCustomLayerOrder, this will return either the override customLayerOrder or the layer order derived from the tree. This property is read only.

Return type:

List[QgsMapLayer]

layerOrderChanged

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

nodeVisibilityChanged(self, node: QgsLayerTreeNode)
readCommonXml(self, element: QDomElement)

Read common XML elements.

readLayerOrderFromXml(self, doc: QDomElement)

Load the layer order from an XML element. Make sure that this is only called after the layers are loaded.

Parameters:

doc (QDomElement) –

readXml(element: QDomElement, context: QgsReadWriteContext) QgsLayerTree

Load the layer tree from an XML element. It is not required that layers are loaded at this point. resolveReferences() needs to be called after loading the layers and before using the tree.

Parameters:
Return type:

QgsLayerTree

receivers(self, PYQT_SIGNAL) int
removeChildrenPrivate(self, from_: int, count: int, destroy: bool = True)

Low-level removal of children from the node.

sender(self) QObject
senderSignalIndex(self) int
setCustomLayerOrder(self, customLayerOrder: Iterable[QgsMapLayer])

The order in which layers will be rendered on the canvas. Will only be used if the property hasCustomLayerOrder is True. If you need the current layer order that is active, prefer using layerOrder().

See also

layerOrder()

Parameters:

customLayerOrder (Iterable[QgsMapLayer]) –

setCustomLayerOrderByIds(self, customLayerOrder: Iterable[str])

The order in which layers will be rendered on the canvas. Will only be used if the property hasCustomLayerOrder is True. If you need the current layer order that is active, prefer using layerOrder().

See also

layerOrder()

Parameters:

customLayerOrder (Iterable[str]) –

setHasCustomLayerOrder(self, hasCustomLayerOrder: bool)

Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.

Parameters:

hasCustomLayerOrder (bool) –

timerEvent(self, QTimerEvent)
updateChildVisibilityMutuallyExclusive(self)

Set check state of children - if mutually exclusive

writeCommonXml(self, element: QDomElement)

Write common XML elements.

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