QGIS API Documentation  2.99.0-Master (37c43df)
Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
QgsLayerTreeGroup Class Reference

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

#include <qgslayertreegroup.h>

Inheritance diagram for QgsLayerTreeGroup:
Inheritance graph
[legend]

Public Member Functions

 QgsLayerTreeGroup (const QString &name=QString(), Qt::CheckState checked=Qt::Checked)
 
 QgsLayerTreeGroup (const QgsLayerTreeGroup &other)
 
void addChildNode (QgsLayerTreeNode *node)
 Append an existing node. The node must not have a parent yet. The node will be owned by this group. More...
 
QgsLayerTreeGroupaddGroup (const QString &name)
 Append a new group node with given name. Newly created node is owned by this group. More...
 
QgsLayerTreeLayeraddLayer (QgsMapLayer *layer)
 Append a new layer node for given map layer. Newly created node is owned by this group. More...
 
virtual QgsLayerTreeGroupclone () const override
 Return a clone of the group. The children are cloned too. More...
 
virtual QString dump () const override
 Return text representation of the tree. For debugging purposes only. More...
 
QgsLayerTreeGroupfindGroup (const QString &name)
 Find group node with specified name. Searches recursively the whole sub-tree. More...
 
QgsLayerTreeLayerfindLayer (const QString &layerId) const
 Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tree. More...
 
QStringList findLayerIds () const
 Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree. More...
 
QList< QgsLayerTreeLayer * > findLayers () const
 Find all layer nodes. Searches recursively the whole sub-tree. More...
 
void insertChildNode (int index, QgsLayerTreeNode *node)
 Insert existing node at specified position. The node must not have a parent yet. The node will be owned by this group. More...
 
void insertChildNodes (int index, const QList< QgsLayerTreeNode *> &nodes)
 Insert existing nodes at specified position. The nodes must not have a parent yet. The nodes will be owned by this group. More...
 
QgsLayerTreeGroupinsertGroup (int index, const QString &name)
 Insert a new group node with given name at specified position. Newly created node is owned by this group. More...
 
QgsLayerTreeLayerinsertLayer (int index, QgsMapLayer *layer)
 Insert a new layer node for given map layer at specified position. Newly created node is owned by this group. More...
 
bool isMutuallyExclusive () const
 Return whether the group is mutually exclusive (only one child can be checked at a time) More...
 
Qt::CheckState isVisible () const
 Return the check state of the group node. More...
 
QString name () const override
 Get group's name. More...
 
void readChildrenFromXml (QDomElement &element)
 Read children from XML and append them to the group. More...
 
void removeAllChildren ()
 Remove all child nodes. The nodes will be deleted. More...
 
void removeChildNode (QgsLayerTreeNode *node)
 Remove a child node from this group. The node will be deleted. More...
 
void removeChildren (int from, int count)
 Remove child nodes from index "from". The nodes will be deleted. More...
 
void removeChildrenGroupWithoutLayers ()
 Remove all child group nodes without layers. The groupnodes will be deleted. More...
 
void removeLayer (QgsMapLayer *layer)
 Remove map layer's node from this group. The node will be deleted. More...
 
void setIsMutuallyExclusive (bool enabled, int initialChildIndex=-1)
 Set whether the group is mutually exclusive (only one child can be checked at a time). More...
 
void setName (const QString &n) override
 Set group's name. More...
 
void setVisible (Qt::CheckState state)
 Set check state of the group node - will also update children. More...
 
virtual void writeXml (QDomElement &parentElement) override
 Write group (tree) as XML element <layer-tree-group> and add it to the given parent element. More...
 
- Public Member Functions inherited from QgsLayerTreeNode
 ~QgsLayerTreeNode ()
 
QList< QgsLayerTreeNode * > children ()
 Get list of children of the node. Children are owned by the parent. More...
 
QStringList customProperties () const
 Return list of keys stored in custom properties. More...
 
QVariant customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const
 Read a custom property from layer. Properties are stored in a map and saved in project file. More...
 
bool isExpanded () const
 Return whether the node should be shown as expanded or collapsed in GUI. More...
 
NodeType nodeType ()
 Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree namespace for that. More...
 
QgsLayerTreeNodeparent ()
 Get pointer to the parent. If parent is a null pointer, the node is a root node. More...
 
void removeCustomProperty (const QString &key)
 Remove a custom property from layer. Properties are stored in a map and saved in project file. More...
 
void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for the node. Properties are stored in a map and saved in project file. More...
 
void setExpanded (bool expanded)
 Set whether the node should be shown as expanded or collapsed in GUI. More...
 
bool takeChild (QgsLayerTreeNode *node)
 Remove a child from a node. More...
 

Static Public Member Functions

static QgsLayerTreeGroupreadXml (QDomElement &element)
 Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on error) More...
 
- Static Public Member Functions inherited from QgsLayerTreeNode
static QgsLayerTreeNodereadXml (QDomElement &element)
 Read layer tree from XML. Returns new instance. More...
 

Protected Slots

void layerDestroyed ()
 
void nodeVisibilityChanged (QgsLayerTreeNode *node)
 

Protected Member Functions

void updateChildVisibility ()
 Set check state of children (when this group's check state changes) - if not mutually exclusive. More...
 
void updateChildVisibilityMutuallyExclusive ()
 Set check state of children - if mutually exclusive. More...
 
void updateVisibilityFromChildren ()
 Set check state of this group from its children. More...
 
- Protected Member Functions inherited from QgsLayerTreeNode
 QgsLayerTreeNode (NodeType t)
 
 QgsLayerTreeNode (const QgsLayerTreeNode &other)
 
void insertChildrenPrivate (int index, QList< QgsLayerTreeNode *> nodes)
 Low-level insertion of children to the node. The children must not have any parent yet! More...
 
void readCommonXml (QDomElement &element)
 
void removeChildrenPrivate (int from, int count, bool destroy=true)
 Low-level removal of children from the node. More...
 
void writeCommonXml (QDomElement &element)
 

Protected Attributes

bool mChangingChildVisibility
 
Qt::CheckState mChecked
 
bool mMutuallyExclusive
 Whether the group is mutually exclusive (i.e. only one child can be checked at a time) More...
 
int mMutuallyExclusiveChildIndex
 Keeps track which child has been most recently selected (so if the whole group is unchecked and checked again, we know which child to check) More...
 
QString mName
 
- Protected Attributes inherited from QgsLayerTreeNode
QList< QgsLayerTreeNode * > mChildren
 list of children - node is responsible for their deletion More...
 
bool mExpanded
 whether the node should be shown in GUI as expanded More...
 
NodeType mNodeType
 type of the node - determines which subclass is used More...
 
QgsLayerTreeNodemParent
 pointer to the parent node - null in case of root node More...
 
QgsObjectCustomProperties mProperties
 custom properties attached to the node More...
 

Additional Inherited Members

- Public Types inherited from QgsLayerTreeNode
enum  NodeType { NodeGroup, NodeLayer }
 Enumeration of possible tree node types. More...
 
- Signals inherited from QgsLayerTreeNode
void addedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes have been added to a node within the tree. More...
 
void customPropertyChanged (QgsLayerTreeNode *node, const QString &key)
 Emitted when a custom property of a node within the tree has been changed or removed. More...
 
void expandedChanged (QgsLayerTreeNode *node, bool expanded)
 Emitted when the collapsed/expanded state of a node within the tree has been changed. More...
 
void nameChanged (QgsLayerTreeNode *node, QString name)
 Emitted when the name of the node is changed. More...
 
void removedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes has been removed from a node within the tree. More...
 
void visibilityChanged (QgsLayerTreeNode *node, Qt::CheckState state)
 Emitted when check state of a node within the tree has been changed. More...
 
void willAddChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes will be added to a node within the tree. More...
 
void willRemoveChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes will be removed from a node within the tree. More...
 

Detailed Description

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.

Note
added in 2.4

Definition at line 31 of file qgslayertreegroup.h.

Constructor & Destructor Documentation

§ QgsLayerTreeGroup() [1/2]

QgsLayerTreeGroup::QgsLayerTreeGroup ( const QString &  name = QString(),
Qt::CheckState  checked = Qt::Checked 
)

Definition at line 27 of file qgslayertreegroup.cpp.

§ QgsLayerTreeGroup() [2/2]

QgsLayerTreeGroup::QgsLayerTreeGroup ( const QgsLayerTreeGroup other)

Definition at line 38 of file qgslayertreegroup.cpp.

Member Function Documentation

§ addChildNode()

void QgsLayerTreeGroup::addChildNode ( QgsLayerTreeNode node)

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

Definition at line 135 of file qgslayertreegroup.cpp.

§ addGroup()

QgsLayerTreeGroup * QgsLayerTreeGroup::addGroup ( const QString &  name)

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

Definition at line 71 of file qgslayertreegroup.cpp.

§ addLayer()

QgsLayerTreeLayer * QgsLayerTreeGroup::addLayer ( QgsMapLayer layer)

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

Definition at line 88 of file qgslayertreegroup.cpp.

§ clone()

QgsLayerTreeGroup * QgsLayerTreeGroup::clone ( ) const
overridevirtual

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

Implements QgsLayerTreeNode.

Definition at line 328 of file qgslayertreegroup.cpp.

§ dump()

QString QgsLayerTreeGroup::dump ( ) const
overridevirtual

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

Implements QgsLayerTreeNode.

Definition at line 317 of file qgslayertreegroup.cpp.

§ findGroup()

QgsLayerTreeGroup * QgsLayerTreeGroup::findGroup ( const QString &  name)

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

Definition at line 237 of file qgslayertreegroup.cpp.

§ findLayer()

QgsLayerTreeLayer * QgsLayerTreeGroup::findLayer ( const QString &  layerId) const

Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tree.

Definition at line 204 of file qgslayertreegroup.cpp.

§ findLayerIds()

QStringList QgsLayerTreeGroup::findLayerIds ( ) const

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

Definition at line 418 of file qgslayertreegroup.cpp.

§ findLayers()

QList< QgsLayerTreeLayer * > QgsLayerTreeGroup::findLayers ( ) const

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

Definition at line 224 of file qgslayertreegroup.cpp.

§ insertChildNode()

void QgsLayerTreeGroup::insertChildNode ( int  index,
QgsLayerTreeNode node 
)

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

Definition at line 98 of file qgslayertreegroup.cpp.

§ insertChildNodes()

void QgsLayerTreeGroup::insertChildNodes ( int  index,
const QList< QgsLayerTreeNode *> &  nodes 
)

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

Definition at line 105 of file qgslayertreegroup.cpp.

§ insertGroup()

QgsLayerTreeGroup * QgsLayerTreeGroup::insertGroup ( int  index,
const QString &  name 
)

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

Definition at line 64 of file qgslayertreegroup.cpp.

§ insertLayer()

QgsLayerTreeLayer * QgsLayerTreeGroup::insertLayer ( int  index,
QgsMapLayer layer 
)

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

Definition at line 78 of file qgslayertreegroup.cpp.

§ isMutuallyExclusive()

bool QgsLayerTreeGroup::isMutuallyExclusive ( ) const

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

Note
added in 2.12

Definition at line 384 of file qgslayertreegroup.cpp.

§ isVisible()

Qt::CheckState QgsLayerTreeGroup::isVisible ( ) const
inline

Return the check state of the group node.

Definition at line 93 of file qgslayertreegroup.h.

§ layerDestroyed

void QgsLayerTreeGroup::layerDestroyed ( )
protectedslot

Definition at line 432 of file qgslayertreegroup.cpp.

§ name()

QString QgsLayerTreeGroup::name ( ) const
overridevirtual

Get group's name.

Implements QgsLayerTreeNode.

Definition at line 49 of file qgslayertreegroup.cpp.

§ nodeVisibilityChanged

void QgsLayerTreeGroup::nodeVisibilityChanged ( QgsLayerTreeNode node)
protectedslot

Definition at line 439 of file qgslayertreegroup.cpp.

§ readChildrenFromXml()

void QgsLayerTreeGroup::readChildrenFromXml ( QDomElement &  element)

Read children from XML and append them to the group.

Definition at line 301 of file qgslayertreegroup.cpp.

§ readXml()

QgsLayerTreeGroup * QgsLayerTreeGroup::readXml ( QDomElement &  element)
static

Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on error)

Definition at line 257 of file qgslayertreegroup.cpp.

§ removeAllChildren()

void QgsLayerTreeGroup::removeAllChildren ( )

Remove all child nodes. The nodes will be deleted.

Definition at line 199 of file qgslayertreegroup.cpp.

§ removeChildNode()

void QgsLayerTreeGroup::removeChildNode ( QgsLayerTreeNode node)

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

Definition at line 140 of file qgslayertreegroup.cpp.

§ removeChildren()

void QgsLayerTreeGroup::removeChildren ( int  from,
int  count 
)

Remove child nodes from index "from". The nodes will be deleted.

Definition at line 163 of file qgslayertreegroup.cpp.

§ removeChildrenGroupWithoutLayers()

void QgsLayerTreeGroup::removeChildrenGroupWithoutLayers ( )

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

Definition at line 183 of file qgslayertreegroup.cpp.

§ removeLayer()

void QgsLayerTreeGroup::removeLayer ( QgsMapLayer layer)

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

Definition at line 147 of file qgslayertreegroup.cpp.

§ setIsMutuallyExclusive()

void QgsLayerTreeGroup::setIsMutuallyExclusive ( bool  enabled,
int  initialChildIndex = -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)

Note
added in 2.12

Definition at line 389 of file qgslayertreegroup.cpp.

§ setName()

void QgsLayerTreeGroup::setName ( const QString &  n)
overridevirtual

Set group's name.

Implements QgsLayerTreeNode.

Definition at line 54 of file qgslayertreegroup.cpp.

§ setVisible()

void QgsLayerTreeGroup::setVisible ( Qt::CheckState  state)

Set check state of the group node - will also update children.

Definition at line 333 of file qgslayertreegroup.cpp.

§ updateChildVisibility()

void QgsLayerTreeGroup::updateChildVisibility ( )
protected

Set check state of children (when this group's check state changes) - if not mutually exclusive.

Definition at line 353 of file qgslayertreegroup.cpp.

§ updateChildVisibilityMutuallyExclusive()

void QgsLayerTreeGroup::updateChildVisibilityMutuallyExclusive ( )
protected

Set check state of children - if mutually exclusive.

Definition at line 514 of file qgslayertreegroup.cpp.

§ updateVisibilityFromChildren()

void QgsLayerTreeGroup::updateVisibilityFromChildren ( )
protected

Set check state of this group from its children.

Definition at line 464 of file qgslayertreegroup.cpp.

§ writeXml()

void QgsLayerTreeGroup::writeXml ( QDomElement &  parentElement)
overridevirtual

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

Implements QgsLayerTreeNode.

Definition at line 280 of file qgslayertreegroup.cpp.

Member Data Documentation

§ mChangingChildVisibility

bool QgsLayerTreeGroup::mChangingChildVisibility
protected

Definition at line 122 of file qgslayertreegroup.h.

§ mChecked

Qt::CheckState QgsLayerTreeGroup::mChecked
protected

Definition at line 120 of file qgslayertreegroup.h.

§ mMutuallyExclusive

bool QgsLayerTreeGroup::mMutuallyExclusive
protected

Whether the group is mutually exclusive (i.e. only one child can be checked at a time)

Definition at line 125 of file qgslayertreegroup.h.

§ mMutuallyExclusiveChildIndex

int QgsLayerTreeGroup::mMutuallyExclusiveChildIndex
protected

Keeps track which child has been most recently selected (so if the whole group is unchecked and checked again, we know which child to check)

Definition at line 128 of file qgslayertreegroup.h.

§ mName

QString QgsLayerTreeGroup::mName
protected

Definition at line 119 of file qgslayertreegroup.h.


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