Subgroup: Layer

Class: QgsLayerTreeGroup

class qgis.core.QgsLayerTreeGroup

Bases: qgis._core.QgsLayerTreeNode

Layer tree group node serves as a container for layers and further groups.

Group names do not need to be unique within one tree nor within one parent.

New in version 2.4: Methods

addChildNode Append an existing node.
addGroup Append a new group node with given name.
addLayer Append a new layer node for given map layer.
blockSignals
checkedLayers Returns a list of any checked layers which belong to this node or its children.
childEvent
children Get list of children of the node.
clone Return a clone of the group.
connectNotify
customEvent
customProperties Return list of keys stored in custom properties
customProperty Read a custom property from layer.
deleteLater
disconnect
disconnectNotify
dump Return text representation of the tree.
dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
event
eventFilter
findChild findChild(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> QObject
findChildren findChildren(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> List[QObject]
findGroup Find group node with specified name.
findLayer Find layer node representing the map layer.
findLayerIds Find layer IDs used in all layer nodes.
findLayers Find all layer nodes.
inherits
insertChildNode Insert existing node at specified position.
insertChildNodes Insert existing nodes at specified position.
insertChildrenPrivate
insertGroup Insert a new group node with given name at specified position.
insertLayer Insert a new layer node for given map layer at specified position.
installEventFilter
isExpanded Return whether the node should be shown as expanded or collapsed in GUI
isItemVisibilityCheckedRecursive Return whether this node is checked and all its children.
isItemVisibilityUncheckedRecursive Return whether this node is unchecked and all its children.
isMutuallyExclusive Return whether the group is mutually exclusive (only one child can be checked at a time)
isSignalConnected
isVisible Returns whether a node is really visible (ie checked and all its ancestors checked as well)
isWidgetType
isWindowType
itemVisibilityChecked Returns whether a node is checked (independently of its ancestors or children)
killTimer
metaObject
moveToThread
name Returns the group’s name.
nodeType Find out about type of the node.
nodeVisibilityChanged
objectName
parent Get pointer to the parent.
property
pyqtConfigure Each keyword argument is either the name of a Qt property or a Qt signal.
readChildrenFromXml Read children from XML and append them to the group.
readCommonXml
readXml Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on error).
receivers
removeAllChildren Remove all child nodes.
removeChildNode Remove a child node from this group.
removeChildren Remove child nodes from index “from”.
removeChildrenGroupWithoutLayers Remove all child group nodes without layers.
removeChildrenPrivate
removeCustomProperty Remove a custom property from layer.
removeEventFilter
removeLayer Remove map layer’s node from this group.
resolveReferences Calls resolveReferences() on child tree nodes
sender
senderSignalIndex
setCustomProperty Set a custom property for the node.
setExpanded Set whether the node should be shown as expanded or collapsed in GUI
setIsMutuallyExclusive Set whether the group is mutually exclusive (only one child can be checked at a time).
setItemVisibilityChecked Check or uncheck a node (independently of its ancestors or children)
setItemVisibilityCheckedParentRecursive Check or uncheck a node and all its parents
setItemVisibilityCheckedRecursive Check or uncheck a node and all its children (taking into account exclusion rules)
setName Sets the group’s name.
setObjectName
setParent
setProperty
signalsBlocked
startTimer
takeChild Remove a child from a node
thread
timerEvent
tr
updateChildVisibilityMutuallyExclusive Set check state of children - if mutually exclusive
writeCommonXml
writeXml Write group (tree) as XML element <layer-tree-group> and add it to the given parent element

Attributes

NodeGroup
NodeLayer
addedChildren Emitted when one or more nodes have been added to a node within the tree [signal]
customPropertyChanged Emitted when a custom property of a node within the tree has been changed or removed [signal]
destroyed destroyed(self, QObject = None) [signal]
expandedChanged Emitted when the collapsed/expanded state of a node within the tree has been changed [signal]
nameChanged Emitted when the name of the node is changed
objectNameChanged objectNameChanged(self, str) [signal]
removedChildren Emitted when one or more nodes has been removed from a node within the tree [signal]
staticMetaObject
visibilityChanged Emitted when check state of a node within the tree has been changed [signal]
willAddChildren Emitted when one or more nodes will be added to a node within the tree [signal]
willRemoveChildren Emitted when one or more nodes will be removed from a node within the tree [signal]
addChildNode(self, node: QgsLayerTreeNode)

Append an existing node. The node must not have a parent yet. The node will be owned by this group.

addGroup(self, name: str) → QgsLayerTreeGroup

Append a new group node with given name. Newly created node is owned by this group.

addLayer(self, layer: QgsMapLayer) → QgsLayerTreeLayer

Append a new layer node for given map layer. The newly created node is owned by this group.

childEvent()
clone(self) → QgsLayerTreeGroup

Return a clone of the group. The children are cloned too.

connectNotify()
customEvent()
disconnectNotify()
dump(self) → str

Return text representation of the tree. For debugging purposes only.

findGroup(self, name: str) → QgsLayerTreeGroup

Find group node with specified name. Searches recursively the whole sub-tree.

findLayer(self, layer: QgsMapLayer) → QgsLayerTreeLayer

Find layer node representing the map layer. Searches recursively the whole sub-tree.

New in version 3.0.

findLayer(self, layerId: str) -> QgsLayerTreeLayer Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tree.

findLayerIds(self) → List[str]

Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree.

findLayers(self) → List[QgsLayerTreeLayer]

Find all layer nodes. Searches recursively the whole sub-tree.

insertChildNode(self, index: int, node: QgsLayerTreeNode)

Insert existing node at specified position. The node must not have a parent yet. The node will be owned by this group.

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

Insert existing nodes at specified position. The nodes must not have a parent yet. The nodes will be owned by this group.

insertChildrenPrivate()
insertGroup(self, index: int, name: str) → QgsLayerTreeGroup

Insert a new group node with given name at specified position. The newly created node is owned by this group.

insertLayer(self, index: int, layer: QgsMapLayer) → QgsLayerTreeLayer

Insert a new layer node for given map layer at specified position. The newly created node is owned by this group.

isMutuallyExclusive(self) → bool

Return whether the group is mutually exclusive (only one child can be checked at a time)

New in version 2.12.

isSignalConnected()
name(self) → str

Returns the group’s name.

nodeVisibilityChanged(self, node: QgsLayerTreeNode)
readChildrenFromXml(self, element: QDomElement, context: QgsReadWriteContext)

Read children from XML and append them to the group. Does not resolve textual references to layers. Call resolveReferences() afterwards to do it.

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

Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on error). Does not resolve textual references to layers. Call resolveReferences() afterwards to do it.

readXml(element: QDomElement, project: QgsProject, context: QgsReadWriteContext) -> QgsLayerTreeGroup Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on error). Also resolves textual references to layers from the project (calls resolveReferences() internally).

New in version 3.0.

receivers()
removeAllChildren(self)

Remove all child nodes. The nodes will be deleted.

removeChildNode(self, node: QgsLayerTreeNode)

Remove a child node from this group. The node will be deleted.

removeChildren(self, from_: int, count: int)

Remove child nodes from index “from”. The nodes will be deleted.

removeChildrenGroupWithoutLayers(self)

Remove all child group nodes without layers. The groupnodes will be deleted.

removeChildrenPrivate()
removeLayer(self, layer: QgsMapLayer)

Remove map layer’s node from this group. The node will be deleted.

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

Calls resolveReferences() on child tree nodes

New in version 3.0.

sender()
senderSignalIndex()
setIsMutuallyExclusive(self, enabled: bool, initialChildIndex: int = -1)

Set whether the group is mutually exclusive (only one child can be checked at a time). The initial child index determines which child should be initially checked. The default value of -1 will determine automatically (either first one currently checked or none)

New in version 2.12.

setItemVisibilityCheckedRecursive(self, checked: bool)

Check or uncheck a node and all its children (taking into account exclusion rules)

setName(self, n: str)

Sets the group’s name.

timerEvent()
updateChildVisibilityMutuallyExclusive(self)

Set check state of children - if mutually exclusive

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

Write group (tree) as XML element <layer-tree-group> and add it to the given parent element