QGIS API Documentation
2.8.2-Wien
|
This class is a base class for nodes in a layer tree. More...
#include <qgslayertreenode.h>
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. | |
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. | |
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 | willAddChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo) |
Emitted when one or more nodes will be 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. |
Public Member Functions | |
~QgsLayerTreeNode () | |
QList< QgsLayerTreeNode * > | children () |
Get list of children of the node. Children are owned by the parent. | |
virtual QgsLayerTreeNode * | clone () const =0 |
Create a copy of the node. Returns new instance. | |
QStringList | customProperties () const |
Return list of keys stored in custom properties. | |
QVariant | customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const |
Read a custom property from layer. | |
virtual QString | dump () const =0 |
Return string with layer tree structure. For debug purposes only. | |
bool | isExpanded () const |
Return whether the node should be shown as expanded or collapsed in GUI. | |
NodeType | nodeType () |
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree namespace for that. | |
QgsLayerTreeNode * | parent () |
Get pointer to the parent. If parent is a null pointer, the node is a root node. | |
void | removeCustomProperty (const QString &key) |
Remove a custom property from layer. | |
void | setCustomProperty (const QString &key, const QVariant &value) |
Set a custom property for the node. | |
void | setExpanded (bool expanded) |
Set whether the node should be shown as expanded or collapsed in GUI. | |
bool | takeChild (QgsLayerTreeNode *node) |
Remove a child from a node. | |
virtual void | writeXML (QDomElement &parentElement)=0 |
Write layer tree to XML. |
Static Public Member Functions | |
static QgsLayerTreeNode * | readXML (QDomElement &element) |
Read layer tree from XML. Returns new instance. |
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! | |
void | readCommonXML (QDomElement &element) |
void | removeChildrenPrivate (int from, int count, bool destroy=true) |
Low-level removal of children from the node. | |
void | writeCommonXML (QDomElement &element) |
Protected Attributes | |
QList< QgsLayerTreeNode * > | mChildren |
list of children - node is responsible for their deletion | |
bool | mExpanded |
whether the node should be shown in GUI as expanded | |
NodeType | mNodeType |
type of the node - determines which subclass is used | |
QgsLayerTreeNode * | mParent |
pointer to the parent node - null in case of root node | |
QgsObjectCustomProperties | mProperties |
custom properties attached to the node |
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:
Definition at line 65 of file qgslayertreenode.h.
Enumeration of possible tree node types.
Definition at line 71 of file qgslayertreenode.h.
QgsLayerTreeNode::~QgsLayerTreeNode | ( | ) |
Definition at line 45 of file qgslayertreenode.cpp.
|
protected |
Definition at line 25 of file qgslayertreenode.cpp.
|
protected |
Definition at line 32 of file qgslayertreenode.cpp.
|
signal |
Emitted when one or more nodes have been added to a node within the tree.
|
inline |
Get list of children of the node. Children are owned by the parent.
Definition at line 84 of file qgslayertreenode.h.
|
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.
Definition at line 95 of file qgslayertreenode.cpp.
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.
|
signal |
Emitted when a custom property of a node within the tree has been changed or removed.
|
pure virtual |
Return string with layer tree structure. For debug purposes only.
Implemented in QgsLayerTreeGroup, and QgsLayerTreeLayer.
|
signal |
Emitted when the collapsed/expanded state of a node within the tree has been changed.
|
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.
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.
|
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.
|
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.
|
protected |
Definition at line 100 of file qgslayertreenode.cpp.
|
static |
Read layer tree from XML. Returns new instance.
Reimplemented in QgsLayerTreeGroup, and QgsLayerTreeLayer.
Definition at line 50 of file qgslayertreenode.cpp.
|
protected |
Low-level removal of children from the node.
Definition at line 143 of file qgslayertreenode.cpp.
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.
|
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.
Definition at line 78 of file qgslayertreenode.cpp.
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.
bool QgsLayerTreeNode::takeChild | ( | QgsLayerTreeNode * | node | ) |
Remove a child from a node.
Definition at line 162 of file qgslayertreenode.cpp.
|
signal |
Emitted when check state of a node within the tree has been changed.
|
signal |
Emitted when one or more nodes will be added to a node within the tree.
|
signal |
Emitted when one or more nodes will be removed from a node within the tree.
|
protected |
Definition at line 105 of file qgslayertreenode.cpp.
|
pure virtual |
Write layer tree to XML.
Implemented in QgsLayerTreeGroup, and QgsLayerTreeLayer.
|
protected |
list of children - node is responsible for their deletion
Definition at line 151 of file qgslayertreenode.h.
|
protected |
whether the node should be shown in GUI as expanded
Definition at line 153 of file qgslayertreenode.h.
|
protected |
type of the node - determines which subclass is used
Definition at line 147 of file qgslayertreenode.h.
|
protected |
pointer to the parent node - null in case of root node
Definition at line 149 of file qgslayertreenode.h.
|
protected |
custom properties attached to the node
Definition at line 155 of file qgslayertreenode.h.