QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
QgsLayerTreeUtils Class Reference

Assorted functions for dealing with layer trees. More...

#include <qgslayertreeutils.h>

Static Public Member Functions

static Qt::CheckState checkStateFromXml (const QString &txt)
 Convert QString to Qt::CheckState.
 
static QString checkStateToXml (Qt::CheckState state)
 Convert Qt::CheckState to QString.
 
static QSet< QgsMapLayer * > collectMapLayersRecursive (const QList< QgsLayerTreeNode * > &nodes)
 Returns map layers from the given list of layer tree nodes.
 
static int countMapLayerInTree (QgsLayerTreeNode *tree, QgsMapLayer *layer)
 Returns how many occurrences of a map layer are there in a layer tree.
 
static QgsLayerTreeGroupfirstGroupWithoutCustomProperty (QgsLayerTreeGroup *group, const QString &property)
 Returns the first parent which doesn't have the given custom property or the group itself if it doesn't hold the property.
 
static bool hasLegendFilterExpression (const QgsLayerTreeGroup &group)
 Test if one of the layers in a group has an expression filter.
 
static QgsLayerTreeLayerinsertLayerAtOptimalPlacement (QgsLayerTreeGroup *group, QgsMapLayer *layer)
 Inserts a layer within a given group at an optimal index position by insuring a given layer type will always sit on top of or below other types.
 
static QgsLayerTreeLayerinsertLayerBelow (QgsLayerTreeGroup *group, const QgsMapLayer *refLayer, QgsMapLayer *layerToInsert)
 Insert a QgsMapLayer just below another one.
 
static QStringList invisibleLayerList (QgsLayerTreeNode *node)
 Gets invisible layers.
 
static bool layersEditable (const QList< QgsLayerTreeLayer * > &layerNodes, bool ignoreLayersWhichCannotBeToggled=false)
 Returns true if any of the specified layers is editable.
 
static bool layersModified (const QList< QgsLayerTreeLayer * > &layerNodes)
 Returns true if any of the layers is modified.
 
static QString legendFilterByExpression (const QgsLayerTreeLayer &layer, bool *enabled=nullptr)
 Returns the expression filter of a legend layer.
 
static bool readOldLegend (QgsLayerTreeGroup *root, const QDomElement &legendElem)
 Try to load layer tree from.
 
static bool readOldLegendLayerOrder (const QDomElement &legendElem, bool &hasCustomOrder, QStringList &order)
 Try to load custom layer order from.
 
static void removeInvalidLayers (QgsLayerTreeGroup *group)
 Removes layer nodes that refer to invalid layers.
 
static void replaceChildrenOfEmbeddedGroups (QgsLayerTreeGroup *group)
 Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers.
 
static void setLegendFilterByExpression (QgsLayerTreeLayer &layer, const QString &expr, bool enabled=true)
 Sets the expression filter of a legend layer.
 
static void storeOriginalLayersProperties (QgsLayerTreeGroup *group, const QDomDocument *doc)
 Stores in a layer's originalXmlProperties the layer properties information.
 
static void updateEmbeddedGroupsProjectPath (QgsLayerTreeGroup *group, const QgsProject *project)
 Updates an embedded group from a project.
 
static QDomElement writeOldLegend (QDomDocument &doc, QgsLayerTreeGroup *root, bool hasCustomOrder, const QList< QgsMapLayer * > &order)
 Returns.
 

Detailed Description

Assorted functions for dealing with layer trees.

Definition at line 39 of file qgslayertreeutils.h.

Member Function Documentation

◆ checkStateFromXml()

Qt::CheckState QgsLayerTreeUtils::checkStateFromXml ( const QString &  txt)
static

Convert QString to Qt::CheckState.

Definition at line 197 of file qgslayertreeutils.cpp.

◆ checkStateToXml()

QString QgsLayerTreeUtils::checkStateToXml ( Qt::CheckState  state)
static

Convert Qt::CheckState to QString.

Definition at line 183 of file qgslayertreeutils.cpp.

◆ collectMapLayersRecursive()

QSet< QgsMapLayer * > QgsLayerTreeUtils::collectMapLayersRecursive ( const QList< QgsLayerTreeNode * > &  nodes)
static

Returns map layers from the given list of layer tree nodes.

Also recursively visits child nodes of groups.

Since
QGIS 3.4

Definition at line 494 of file qgslayertreeutils.cpp.

◆ countMapLayerInTree()

int QgsLayerTreeUtils::countMapLayerInTree ( QgsLayerTreeNode tree,
QgsMapLayer layer 
)
static

Returns how many occurrences of a map layer are there in a layer tree.

In normal situations there is at most one occurrence, but sometimes there may be temporarily more: for example, during drag&drop, upon drop a new layer node is created while the original dragged node is still in the tree, resulting in two occurrences.

This is useful when deciding whether to start or stop listening to a signal of a map layer within a layer tree and only connecting/disconnecting when there is only one occurrence of that layer.

Since
QGIS 3.4

Definition at line 501 of file qgslayertreeutils.cpp.

◆ firstGroupWithoutCustomProperty()

QgsLayerTreeGroup * QgsLayerTreeUtils::firstGroupWithoutCustomProperty ( QgsLayerTreeGroup group,
const QString &  property 
)
static

Returns the first parent which doesn't have the given custom property or the group itself if it doesn't hold the property.

Parameters
groupthe layer tree group
propertythe property
Since
QGIS 3.8

Definition at line 517 of file qgslayertreeutils.cpp.

◆ hasLegendFilterExpression()

bool QgsLayerTreeUtils::hasLegendFilterExpression ( const QgsLayerTreeGroup group)
static

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

Definition at line 440 of file qgslayertreeutils.cpp.

◆ insertLayerAtOptimalPlacement()

QgsLayerTreeLayer * QgsLayerTreeUtils::insertLayerAtOptimalPlacement ( QgsLayerTreeGroup group,
QgsMapLayer layer 
)
static

Inserts a layer within a given group at an optimal index position by insuring a given layer type will always sit on top of or below other types.

From top to bottom, the stacking logic is as follow:

  • vector points
  • vector lines
  • vector polygons
  • point clouds
  • meshes
  • rasters
  • base maps

A base map is defined as a non-gdal provider raster layer (e.g. XYZ raster layer, vector tile layer, etc.)

Since
QGIS 3.28

Definition at line 533 of file qgslayertreeutils.cpp.

◆ insertLayerBelow()

QgsLayerTreeLayer * QgsLayerTreeUtils::insertLayerBelow ( QgsLayerTreeGroup group,
const QgsMapLayer refLayer,
QgsMapLayer layerToInsert 
)
static

Insert a QgsMapLayer just below another one.

Parameters
groupthe tree group where layers are (can be the root group)
refLayerthe reference layer
layerToInsertthe new layer to insert just below the reference layer
Returns
the new tree layer

Definition at line 455 of file qgslayertreeutils.cpp.

◆ invisibleLayerList()

QStringList QgsLayerTreeUtils::invisibleLayerList ( QgsLayerTreeNode node)
static

Gets invisible layers.

Definition at line 360 of file qgslayertreeutils.cpp.

◆ layersEditable()

bool QgsLayerTreeUtils::layersEditable ( const QList< QgsLayerTreeLayer * > &  layerNodes,
bool  ignoreLayersWhichCannotBeToggled = false 
)
static

Returns true if any of the specified layers is editable.

The ignoreLayersWhichCannotBeToggled argument can be used to control whether layers which cannot have their edit states toggled by users should be ignored or not (since QGIS 3.22).

Definition at line 263 of file qgslayertreeutils.cpp.

◆ layersModified()

bool QgsLayerTreeUtils::layersModified ( const QList< QgsLayerTreeLayer * > &  layerNodes)
static

Returns true if any of the layers is modified.

Definition at line 278 of file qgslayertreeutils.cpp.

◆ legendFilterByExpression()

QString QgsLayerTreeUtils::legendFilterByExpression ( const QgsLayerTreeLayer layer,
bool *  enabled = nullptr 
)
static

Returns the expression filter of a legend layer.

Definition at line 432 of file qgslayertreeutils.cpp.

◆ readOldLegend()

bool QgsLayerTreeUtils::readOldLegend ( QgsLayerTreeGroup root,
const QDomElement &  legendElem 
)
static

Try to load layer tree from.

<legend> 

tag from project files from QGIS 2.2 and below

Definition at line 28 of file qgslayertreeutils.cpp.

◆ readOldLegendLayerOrder()

bool QgsLayerTreeUtils::readOldLegendLayerOrder ( const QDomElement &  legendElem,
bool &  hasCustomOrder,
QStringList &  order 
)
static

Try to load custom layer order from.

<legend> 

tag from project files from QGIS 2.2 and below

Definition at line 80 of file qgslayertreeutils.cpp.

◆ removeInvalidLayers()

void QgsLayerTreeUtils::removeInvalidLayers ( QgsLayerTreeGroup group)
static

Removes layer nodes that refer to invalid layers.

Definition at line 293 of file qgslayertreeutils.cpp.

◆ replaceChildrenOfEmbeddedGroups()

void QgsLayerTreeUtils::replaceChildrenOfEmbeddedGroups ( QgsLayerTreeGroup group)
static

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

Definition at line 386 of file qgslayertreeutils.cpp.

◆ setLegendFilterByExpression()

void QgsLayerTreeUtils::setLegendFilterByExpression ( QgsLayerTreeLayer layer,
const QString &  expr,
bool  enabled = true 
)
static

Sets the expression filter of a legend layer.

Definition at line 426 of file qgslayertreeutils.cpp.

◆ storeOriginalLayersProperties()

void QgsLayerTreeUtils::storeOriginalLayersProperties ( QgsLayerTreeGroup group,
const QDomDocument *  doc 
)
static

Stores in a layer's originalXmlProperties the layer properties information.

Since
QGIS 3.6

Definition at line 313 of file qgslayertreeutils.cpp.

◆ updateEmbeddedGroupsProjectPath()

void QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath ( QgsLayerTreeGroup group,
const QgsProject project 
)
static

Updates an embedded group from a project.

Definition at line 407 of file qgslayertreeutils.cpp.

◆ writeOldLegend()

QDomElement QgsLayerTreeUtils::writeOldLegend ( QDomDocument &  doc,
QgsLayerTreeGroup root,
bool  hasCustomOrder,
const QList< QgsMapLayer * > &  order 
)
static

Returns.

<legend> 

tag used in QGIS 2.2 and below

Definition at line 172 of file qgslayertreeutils.cpp.


The documentation for this class was generated from the following files: