QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsLayerTreeNode Class Referenceabstract

This class is a base class for nodes in a layer tree. More...

#include <qgslayertreenode.h>

Inheritance diagram for QgsLayerTreeNode:
Inheritance graph
[legend]

Public Types

enum  NodeType { NodeGroup, NodeLayer }
 Enumeration of possible tree node types. More...
 

Signals

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...
 

Public Member Functions

 ~QgsLayerTreeNode ()
 
QList< QgsLayerTreeNode * > children ()
 Get list of children of the node. Children are owned by the parent. More...
 
virtual QgsLayerTreeNodeclone () const =0
 Create a copy of the node. Returns new instance. 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. More...
 
virtual QString dump () const =0
 Return string with layer tree structure. For debug purposes only. More...
 
bool isExpanded () const
 Return whether the node should be shown as expanded or collapsed in GUI. More...
 
virtual QString name () const =0
 Return name of the node. 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. More...
 
void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for the node. More...
 
void setExpanded (bool expanded)
 Set whether the node should be shown as expanded or collapsed in GUI. More...
 
virtual void setName (const QString &name)=0
 Set name of the node. More...
 
bool takeChild (QgsLayerTreeNode *node)
 Remove a child from a node. More...
 
virtual void writeXML (QDomElement &parentElement)=0
 Write layer tree to XML. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual ~QObject ()
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 

Static Public Member Functions

static QgsLayerTreeNodereadXML (QDomElement &element, bool looseMatch=false)
 Read layer tree from XML. More...
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

 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 Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Protected Attributes

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

- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

This class is a base class for nodes in a layer tree.

Layer tree is a hierarchical structure consisting of group and layer nodes:

Layer trees may be used for organization of layers, typically a layer tree is exposed to the user using QgsLayerTreeView widget which shows the tree and allows manipulation with the tree.

Ownership of nodes: every node is owned by its parent. Therefore once node is added to a layer tree, it is the responsibility of the parent to delete it when the node is not needed anymore. Deletion of root node of a tree will delete all nodes of the tree.

Signals: signals are propagated from children to parent. That means it is sufficient to connect to root node in order to get signals about updates in the whole layer tree. When adding or removing a node that contains further children (i.e. a whole subtree), the addition/removal signals are emitted only for the root node of the subtree that is being added or removed.

Custom properties: Every node may have some custom properties assigned to it. This mechanism allows third parties store additional data with the nodes. The properties are used within QGIS code (whether to show layer in overview, whether the node is embedded from another project etc), but may be also used by third party plugins. Custom properties are stored also in the project file. The storage is not efficient for large amount of data.

Custom properties that have already been used within QGIS:

See also
also QgsLayerTree, QgsLayerTreeLayer, QgsLayerTreeGroup
Note
added in 2.4

Definition at line 65 of file qgslayertreenode.h.

Member Enumeration Documentation

◆ NodeType

Enumeration of possible tree node types.

Enumerator
NodeGroup 

container of other groups and layers

NodeLayer 

leaf node pointing to a layer

Definition at line 71 of file qgslayertreenode.h.

Constructor & Destructor Documentation

◆ ~QgsLayerTreeNode()

QgsLayerTreeNode::~QgsLayerTreeNode ( )

Definition at line 45 of file qgslayertreenode.cpp.

◆ QgsLayerTreeNode() [1/2]

QgsLayerTreeNode::QgsLayerTreeNode ( QgsLayerTreeNode::NodeType  t)
protected

Definition at line 25 of file qgslayertreenode.cpp.

◆ QgsLayerTreeNode() [2/2]

QgsLayerTreeNode::QgsLayerTreeNode ( const QgsLayerTreeNode other)
protected

Definition at line 32 of file qgslayertreenode.cpp.

Member Function Documentation

◆ addedChildren

void QgsLayerTreeNode::addedChildren ( QgsLayerTreeNode node,
int  indexFrom,
int  indexTo 
)
signal

Emitted when one or more nodes have been added to a node within the tree.

◆ children()

QList<QgsLayerTreeNode*> QgsLayerTreeNode::children ( )
inline

Get list of children of the node. Children are owned by the parent.

Definition at line 84 of file qgslayertreenode.h.

◆ clone()

virtual QgsLayerTreeNode* QgsLayerTreeNode::clone ( ) const
pure virtual

Create a copy of the node. Returns new instance.

Implemented in QgsLayerTreeLayer, and QgsLayerTreeGroup.

◆ customProperties()

QStringList QgsLayerTreeNode::customProperties ( ) const

Return list of keys stored in custom properties.

Definition at line 95 of file qgslayertreenode.cpp.

◆ customProperty()

QVariant QgsLayerTreeNode::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.

Definition at line 84 of file qgslayertreenode.cpp.

◆ customPropertyChanged

void QgsLayerTreeNode::customPropertyChanged ( QgsLayerTreeNode node,
const QString key 
)
signal

Emitted when a custom property of a node within the tree has been changed or removed.

◆ dump()

virtual QString QgsLayerTreeNode::dump ( ) const
pure virtual

Return string with layer tree structure. For debug purposes only.

Implemented in QgsLayerTreeLayer, and QgsLayerTreeGroup.

◆ expandedChanged

void QgsLayerTreeNode::expandedChanged ( QgsLayerTreeNode node,
bool  expanded 
)
signal

Emitted when the collapsed/expanded state of a node within the tree has been changed.

◆ insertChildrenPrivate()

void QgsLayerTreeNode::insertChildrenPrivate ( int  index,
QList< QgsLayerTreeNode *>  nodes 
)
protected

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

Definition at line 111 of file qgslayertreenode.cpp.

◆ isExpanded()

bool QgsLayerTreeNode::isExpanded ( ) const

Return whether the node should be shown as expanded or collapsed in GUI.

Definition at line 62 of file qgslayertreenode.cpp.

◆ name()

virtual QString QgsLayerTreeNode::name ( ) const
pure virtual

Return name of the node.

Note
added in 2.18.1

Implemented in QgsLayerTreeLayer, and QgsLayerTreeGroup.

◆ nameChanged

void QgsLayerTreeNode::nameChanged ( QgsLayerTreeNode node,
QString  name 
)
signal

Emitted when the name of the node is changed.

Note
added in 2.18.1

◆ nodeType()

NodeType QgsLayerTreeNode::nodeType ( )
inline

Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree namespace for that.

Definition at line 80 of file qgslayertreenode.h.

◆ parent()

QgsLayerTreeNode* QgsLayerTreeNode::parent ( )
inline

Get pointer to the parent. If parent is a null pointer, the node is a root node.

Definition at line 82 of file qgslayertreenode.h.

◆ readCommonXML()

void QgsLayerTreeNode::readCommonXML ( QDomElement element)
protected

Definition at line 100 of file qgslayertreenode.cpp.

◆ readXML()

QgsLayerTreeNode * QgsLayerTreeNode::readXML ( QDomElement element,
bool  looseMatch = false 
)
static

Read layer tree from XML.

Returns new instance. If the looseMatch parameter is true then child legend layers will use looser matching criteria, eg testing layer source instead of layer IDs.

Definition at line 50 of file qgslayertreenode.cpp.

◆ removeChildrenPrivate()

void QgsLayerTreeNode::removeChildrenPrivate ( int  from,
int  count,
bool  destroy = true 
)
protected

Low-level removal of children from the node.

Definition at line 144 of file qgslayertreenode.cpp.

◆ removeCustomProperty()

void QgsLayerTreeNode::removeCustomProperty ( const QString key)

Remove a custom property from layer.

Properties are stored in a map and saved in project file.

Definition at line 89 of file qgslayertreenode.cpp.

◆ removedChildren

void QgsLayerTreeNode::removedChildren ( QgsLayerTreeNode node,
int  indexFrom,
int  indexTo 
)
signal

Emitted when one or more nodes has been removed from a node within the tree.

◆ setCustomProperty()

void QgsLayerTreeNode::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.

Definition at line 78 of file qgslayertreenode.cpp.

◆ setExpanded()

void QgsLayerTreeNode::setExpanded ( bool  expanded)

Set whether the node should be shown as expanded or collapsed in GUI.

Definition at line 68 of file qgslayertreenode.cpp.

◆ setName()

virtual void QgsLayerTreeNode::setName ( const QString name)
pure virtual

Set name of the node.

Emits nameChanged signal.

Note
added in 2.18.1

Implemented in QgsLayerTreeLayer, and QgsLayerTreeGroup.

◆ takeChild()

bool QgsLayerTreeNode::takeChild ( QgsLayerTreeNode node)

Remove a child from a node.

Definition at line 163 of file qgslayertreenode.cpp.

◆ visibilityChanged

void QgsLayerTreeNode::visibilityChanged ( QgsLayerTreeNode node,
Qt::CheckState  state 
)
signal

Emitted when check state of a node within the tree has been changed.

◆ willAddChildren

void QgsLayerTreeNode::willAddChildren ( QgsLayerTreeNode node,
int  indexFrom,
int  indexTo 
)
signal

Emitted when one or more nodes will be added to a node within the tree.

◆ willRemoveChildren

void QgsLayerTreeNode::willRemoveChildren ( QgsLayerTreeNode node,
int  indexFrom,
int  indexTo 
)
signal

Emitted when one or more nodes will be removed from a node within the tree.

◆ writeCommonXML()

void QgsLayerTreeNode::writeCommonXML ( QDomElement element)
protected

Definition at line 105 of file qgslayertreenode.cpp.

◆ writeXML()

virtual void QgsLayerTreeNode::writeXML ( QDomElement parentElement)
pure virtual

Write layer tree to XML.

Implemented in QgsLayerTreeLayer, and QgsLayerTreeGroup.

Member Data Documentation

◆ mChildren

QList<QgsLayerTreeNode*> QgsLayerTreeNode::mChildren
protected

list of children - node is responsible for their deletion

Definition at line 166 of file qgslayertreenode.h.

◆ mExpanded

bool QgsLayerTreeNode::mExpanded
protected

whether the node should be shown in GUI as expanded

Definition at line 168 of file qgslayertreenode.h.

◆ mNodeType

NodeType QgsLayerTreeNode::mNodeType
protected

type of the node - determines which subclass is used

Definition at line 162 of file qgslayertreenode.h.

◆ mParent

QgsLayerTreeNode* QgsLayerTreeNode::mParent
protected

pointer to the parent node - null in case of root node

Definition at line 164 of file qgslayertreenode.h.

◆ mProperties

QgsObjectCustomProperties QgsLayerTreeNode::mProperties
protected

custom properties attached to the node

Definition at line 170 of file qgslayertreenode.h.


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