QGIS API Documentation  2.99.0-Master (0a63d1f)
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 "qgis_core.h"
20 #include <QObject>
21 
23 
24 class QDomElement;
25 
66 class CORE_EXPORT QgsLayerTreeNode : public QObject
67 {
68  Q_OBJECT
69  public:
70 
72  enum NodeType
73  {
75  NodeLayer
76  };
77 
79 
81  NodeType nodeType() { return mNodeType; }
83  QgsLayerTreeNode *parent() { return mParent; }
85  QList<QgsLayerTreeNode*> children() { return mChildren; }
87  QList<QgsLayerTreeNode*> children() const { return mChildren; }
88 
91  virtual QString name() const = 0;
94  virtual void setName( const QString& name ) = 0;
95 
97  static QgsLayerTreeNode *readXml( QDomElement &element );
99  virtual void writeXml( QDomElement &parentElement ) = 0;
100 
102  virtual QString dump() const = 0;
103 
105  virtual QgsLayerTreeNode *clone() const = 0;
106 
109  bool isVisible() const;
110 
113  bool itemVisibilityChecked() const { return mChecked; }
114 
117  void setItemVisibilityChecked( bool checked );
118 
121  virtual void setItemVisibilityCheckedRecursive( bool checked );
122 
125  void setItemVisibilityCheckedParentRecursive( bool checked );
126 
129  bool isItemVisibilityCheckedRecursive() const;
130 
133  bool isItemVisibilityUncheckedRecursive() const;
134 
136  bool isExpanded() const;
138  void setExpanded( bool expanded );
139 
141  void setCustomProperty( const QString &key, const QVariant &value );
143  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
145  void removeCustomProperty( const QString &key );
147  QStringList customProperties() const;
149  bool takeChild( QgsLayerTreeNode *node );
150 
151  signals:
152 
154  void willAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
156  void addedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
158  void willRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
160  void removedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
162  void visibilityChanged( QgsLayerTreeNode *node );
164  void customPropertyChanged( QgsLayerTreeNode *node, const QString& key );
166  void expandedChanged( QgsLayerTreeNode *node, bool expanded );
169  void nameChanged( QgsLayerTreeNode* node, QString name );
170 
171  protected:
172 
174  QgsLayerTreeNode( NodeType t, bool checked = true );
175  QgsLayerTreeNode( const QgsLayerTreeNode &other );
176 
177  // low-level utility functions
178 
180  void readCommonXml( QDomElement &element );
182  void writeCommonXml( QDomElement &element );
183 
185  void insertChildrenPrivate( int index, QList<QgsLayerTreeNode*> nodes );
187  void removeChildrenPrivate( int from, int count, bool destroy = true );
188 
189  protected:
192  bool mChecked;
196  QList<QgsLayerTreeNode*> mChildren;
198  bool mExpanded;
201 };
202 
203 
204 
205 
206 #endif // QGSLAYERTREENODE_H
static unsigned index
bool itemVisibilityChecked() const
Returns whether a node is checked (independently of its ancestors or children)
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.
QList< QgsLayerTreeNode * > children() const
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