QGIS API Documentation  2.99.0-Master (37c43df)
qgslayertreenode.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreenode.h
3  --------------------------------------
4  Date : May 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSLAYERTREENODE_H
17 #define QGSLAYERTREENODE_H
18 
19 #include <QObject>
20 
22 
23 class QDomElement;
24 
65 class CORE_EXPORT QgsLayerTreeNode : public QObject
66 {
67  Q_OBJECT
68  public:
69 
71  enum NodeType
72  {
74  NodeLayer
75  };
76 
78 
80  NodeType nodeType() { return mNodeType; }
82  QgsLayerTreeNode *parent() { return mParent; }
84  QList<QgsLayerTreeNode*> children() { return mChildren; }
85 
88  virtual QString name() const = 0;
91  virtual void setName( const QString& name ) = 0;
92 
94  static QgsLayerTreeNode *readXml( QDomElement &element );
96  virtual void writeXml( QDomElement &parentElement ) = 0;
97 
99  virtual QString dump() const = 0;
100 
102  virtual QgsLayerTreeNode *clone() const = 0;
103 
105  bool isExpanded() const;
107  void setExpanded( bool expanded );
108 
110  void setCustomProperty( const QString &key, const QVariant &value );
112  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
114  void removeCustomProperty( const QString &key );
116  QStringList customProperties() const;
118  bool takeChild( QgsLayerTreeNode *node );
119 
120  signals:
121 
123  void willAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
125  void addedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
127  void willRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
129  void removedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
131  void visibilityChanged( QgsLayerTreeNode *node, Qt::CheckState state );
133  void customPropertyChanged( QgsLayerTreeNode *node, const QString& key );
135  void expandedChanged( QgsLayerTreeNode *node, bool expanded );
138  void nameChanged( QgsLayerTreeNode* node, QString name );
139 
140  protected:
141 
143  QgsLayerTreeNode( const QgsLayerTreeNode &other );
144 
145  // low-level utility functions
146 
147  void readCommonXml( QDomElement &element );
148  void writeCommonXml( QDomElement &element );
149 
151  void insertChildrenPrivate( int index, QList<QgsLayerTreeNode*> nodes );
153  void removeChildrenPrivate( int from, int count, bool destroy = true );
154 
155  protected:
161  QList<QgsLayerTreeNode*> mChildren;
163  bool mExpanded;
166 };
167 
168 
169 
170 
171 #endif // QGSLAYERTREENODE_H
static unsigned index
bool mExpanded
whether the node should be shown in GUI as expanded
NodeType nodeType()
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
NodeType
Enumeration of possible tree node types.
NodeType mNodeType
type of the node - determines which subclass is used
QgsLayerTreeNode * parent()
Get pointer to the parent. If parent is a null pointer, the node is a root node.
QgsLayerTreeNode * mParent
pointer to the parent node - null in case of root node
This class is a base class for nodes in a layer tree.
QList< QgsLayerTreeNode * > mChildren
list of children - node is responsible for their deletion
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Container of other groups and layers.
QgsObjectCustomProperties mProperties
custom properties attached to the node