QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsLayerTreeNode Class Reference

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 willAddChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes will be added to a node within the tree.
void addedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes have been added to a node within the tree.
void willRemoveChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes will be removed from a node within the tree.
void removedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes has been removed from a node within the tree.
void visibilityChanged (QgsLayerTreeNode *node, Qt::CheckState state)
 Emitted when check state of a node within the tree has been changed.
void customPropertyChanged (QgsLayerTreeNode *node, QString key)
 Emitted when a custom property of a node within the tree has been changed or removed.
void expandedChanged (QgsLayerTreeNode *node, bool expanded)
 Emitted when the collapsed/expanded state of a node within the tree has been changed.

Public Member Functions

 ~QgsLayerTreeNode ()
NodeType nodeType ()
 Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree namespace for that.
QgsLayerTreeNodeparent ()
 Get pointer to the parent. If parent is a null pointer, the node is a root node.
QList< QgsLayerTreeNode * > children ()
 Get list of children of the node. Children are owned by the parent.
virtual void writeXML (QDomElement &parentElement)=0
 Write layer tree to XML.
virtual QString dump () const =0
 Return string with layer tree structure. For debug purposes only.
virtual QgsLayerTreeNodeclone () const =0
 Create a copy of the node. Returns new instance.
bool isExpanded () const
 Return whether the node should be shown as expanded or collapsed in GUI.
void setExpanded (bool expanded)
 Set whether the node should be shown as expanded or collapsed in GUI.
void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for the node.
QVariant customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const
 Read a custom property from layer.
void removeCustomProperty (const QString &key)
 Remove a custom property from layer.
QStringList customProperties () const
 Return list of keys stored in custom properties.

Static Public Member Functions

static QgsLayerTreeNodereadXML (QDomElement &element)
 Read layer tree from XML. Returns new instance.

Protected Member Functions

 QgsLayerTreeNode (NodeType t)
 QgsLayerTreeNode (const QgsLayerTreeNode &other)
void readCommonXML (QDomElement &element)
void writeCommonXML (QDomElement &element)
void insertChildrenPrivate (int index, QList< QgsLayerTreeNode * > nodes)
 Low-level insertion of children to the node. The children must not have any parent yet!
void removeChildrenPrivate (int from, int count)
 Low-level removal of children from the node.

Protected Attributes

NodeType mNodeType
 type of the node - determines which subclass is used
QgsLayerTreeNodemParent
 pointer to the parent node - null in case of root node
QList< QgsLayerTreeNode * > mChildren
 list of children - node is responsible for their deletion
bool mExpanded
 whether the node should be shown in GUI as expanded
QgsObjectCustomProperties mProperties
 custom properties attached to the node

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

Member Enumeration Documentation

Enumeration of possible tree node types.

Enumerator:
NodeGroup 

container of other groups and layers

NodeLayer 

leaf node pointing to a layer

Constructor & Destructor Documentation

QgsLayerTreeNode::~QgsLayerTreeNode ( )
QgsLayerTreeNode::QgsLayerTreeNode ( QgsLayerTreeNode::NodeType  t)
protected
QgsLayerTreeNode::QgsLayerTreeNode ( const QgsLayerTreeNode other)
protected

Member Function Documentation

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.

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

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

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

Create a copy of the node. Returns new instance.

Implemented in QgsLayerTreeGroup, and QgsLayerTreeLayer.

QStringList QgsLayerTreeNode::customProperties ( ) const

Return list of keys stored in custom properties.

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.

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

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

virtual QString QgsLayerTreeNode::dump ( ) const
pure virtual

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

Implemented in QgsLayerTreeGroup, and QgsLayerTreeLayer.

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

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

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!

bool QgsLayerTreeNode::isExpanded ( ) const

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

NodeType QgsLayerTreeNode::nodeType ( )
inline

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

QgsLayerTreeNode* QgsLayerTreeNode::parent ( )
inline

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

void QgsLayerTreeNode::readCommonXML ( QDomElement &  element)
protected
QgsLayerTreeNode * QgsLayerTreeNode::readXML ( QDomElement &  element)
static

Read layer tree from XML. Returns new instance.

Reimplemented in QgsLayerTreeGroup, and QgsLayerTreeLayer.

void QgsLayerTreeNode::removeChildrenPrivate ( int  from,
int  count 
)
protected

Low-level removal of children from the node.

void QgsLayerTreeNode::removeCustomProperty ( const QString &  key)

Remove a custom property from layer.

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

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.

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.

void QgsLayerTreeNode::setExpanded ( bool  expanded)

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

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

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

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.

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.

void QgsLayerTreeNode::writeCommonXML ( QDomElement &  element)
protected
virtual void QgsLayerTreeNode::writeXML ( QDomElement &  parentElement)
pure virtual

Write layer tree to XML.

Implemented in QgsLayerTreeGroup, and QgsLayerTreeLayer.

Member Data Documentation

QList<QgsLayerTreeNode*> QgsLayerTreeNode::mChildren
protected

list of children - node is responsible for their deletion

bool QgsLayerTreeNode::mExpanded
protected

whether the node should be shown in GUI as expanded

NodeType QgsLayerTreeNode::mNodeType
protected

type of the node - determines which subclass is used

QgsLayerTreeNode* QgsLayerTreeNode::mParent
protected

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

QgsObjectCustomProperties QgsLayerTreeNode::mProperties
protected

custom properties attached to the node


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