Subgroup: Layer

Class: QgsLayerTreeUtils

class qgis.core.QgsLayerTreeUtils

Bases: sip.wrapper

Assorted functions for dealing with layer trees.

New in version 2.4: Methods

checkStateFromXml Convert QString to Qt.CheckState
checkStateToXml Convert Qt.CheckState to QString
hasLegendFilterExpression Test if one of the layers in a group has an expression filter
insertLayerBelow Insert a QgsMapLayer just below another one
invisibleLayerList Gets invisible layers
layersEditable Returns true if any of the layers is editable
layersModified Returns true if any of the layers is modified
legendFilterByExpression Returns the expression filter of a legend layer
readOldLegend Try to load layer tree from verbatim <legend> endverbatim tag from project files from QGIS 2.2 and below
readOldLegendLayerOrder Try to load custom layer order from verbatim <legend> endverbatim tag from project files from QGIS 2.2 and below
removeInvalidLayers Remove layer nodes that refer to invalid layers
replaceChildrenOfEmbeddedGroups Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers
setLegendFilterByExpression Sets the expression filter of a legend layer
updateEmbeddedGroupsProjectPath Updates an embedded group from a project.
writeOldLegend Returns verbatim <legend> endverbatim tag used in QGIS 2.2 and below

Signals

Attributes

checkStateFromXml(txt: str) → Qt.CheckState

Convert QString to Qt.CheckState

checkStateToXml(state: Qt.CheckState) → str

Convert Qt.CheckState to QString

hasLegendFilterExpression(group: QgsLayerTreeGroup) → bool

Test if one of the layers in a group has an expression filter

insertLayerBelow(group: QgsLayerTreeGroup, refLayer: QgsMapLayer, layerToInsert: QgsMapLayer) → QgsLayerTreeLayer

Insert a QgsMapLayer just below another one

Parameters:
  • group – the tree group where layers are (can be the root group)
  • refLayer – the reference layer
  • layerToInsert – the new layer to insert just below the reference layer
Returns:

the new tree layer

invisibleLayerList(node: QgsLayerTreeNode) → List[str]

Gets invisible layers

layersEditable(layerNodes: object) → bool

Returns true if any of the layers is editable

layersModified(layerNodes: Iterable[QgsLayerTreeLayer]) → bool

Returns true if any of the layers is modified

legendFilterByExpression(layer: QgsLayerTreeLayer) → Tuple[str, bool]

Returns the expression filter of a legend layer

readOldLegend(root: QgsLayerTreeGroup, legendElem: QDomElement) → bool

Try to load layer tree from verbatim <legend> endverbatim tag from project files from QGIS 2.2 and below

readOldLegendLayerOrder(legendElem: QDomElement, order: Iterable[str]) → Tuple[bool, bool]

Try to load custom layer order from verbatim <legend> endverbatim tag from project files from QGIS 2.2 and below

removeInvalidLayers(group: QgsLayerTreeGroup)

Remove layer nodes that refer to invalid layers

replaceChildrenOfEmbeddedGroups(group: QgsLayerTreeGroup)

Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers

setLegendFilterByExpression(layer: QgsLayerTreeLayer, expr: str, enabled: bool = True)

Sets the expression filter of a legend layer

updateEmbeddedGroupsProjectPath(group: QgsLayerTreeGroup, project: QgsProject)

Updates an embedded group from a project.

writeOldLegend(doc: QDomDocument, root: QgsLayerTreeGroup, hasCustomOrder: bool, order: Iterable[QgsMapLayer]) → QDomElement

Returns verbatim <legend> endverbatim tag used in QGIS 2.2 and below