QGIS API Documentation  2.99.0-Master (90ae728)
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 
26 class QgsProject;
27 
68 class CORE_EXPORT QgsLayerTreeNode : public QObject
69 {
70  Q_OBJECT
71  public:
72 
74  enum NodeType
75  {
77  NodeLayer
78  };
79 
81 
83  NodeType nodeType() { return mNodeType; }
85  QgsLayerTreeNode *parent() { return mParent; }
87  QList<QgsLayerTreeNode*> children() { return mChildren; }
89  QList<QgsLayerTreeNode*> children() const { return mChildren; }
90 
93  virtual QString name() const = 0;
96  virtual void setName( const QString& name ) = 0;
97 
100  static QgsLayerTreeNode *readXml( QDomElement &element );
104  static QgsLayerTreeNode* readXml( QDomElement& element, const QgsProject* project );
105 
107  virtual void writeXml( QDomElement &parentElement ) = 0;
108 
110  virtual QString dump() const = 0;
111 
113  virtual QgsLayerTreeNode *clone() const = 0;
114 
118  virtual void resolveReferences( const QgsProject* project ) = 0;
119 
122  bool isVisible() const;
123 
126  bool itemVisibilityChecked() const { return mChecked; }
127 
130  void setItemVisibilityChecked( bool checked );
131 
134  virtual void setItemVisibilityCheckedRecursive( bool checked );
135 
138  void setItemVisibilityCheckedParentRecursive( bool checked );
139 
142  bool isItemVisibilityCheckedRecursive() const;
143 
146  bool isItemVisibilityUncheckedRecursive() const;
147 
149  bool isExpanded() const;
151  void setExpanded( bool expanded );
152 
154  void setCustomProperty( const QString &key, const QVariant &value );
156  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
158  void removeCustomProperty( const QString &key );
160  QStringList customProperties() const;
162  bool takeChild( QgsLayerTreeNode *node );
163 
164  signals:
165 
167  void willAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
169  void addedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
171  void willRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
173  void removedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
175  void visibilityChanged( QgsLayerTreeNode *node );
177  void customPropertyChanged( QgsLayerTreeNode *node, const QString& key );
179  void expandedChanged( QgsLayerTreeNode *node, bool expanded );
182  void nameChanged( QgsLayerTreeNode* node, QString name );
183 
184  protected:
185 
187  QgsLayerTreeNode( NodeType t, bool checked = true );
188  QgsLayerTreeNode( const QgsLayerTreeNode &other );
189 
190  // low-level utility functions
191 
193  void readCommonXml( QDomElement &element );
195  void writeCommonXml( QDomElement &element );
196 
198  void insertChildrenPrivate( int index, QList<QgsLayerTreeNode*> nodes );
200  void removeChildrenPrivate( int from, int count, bool destroy = true );
201 
202  protected:
205  bool mChecked;
207  QgsLayerTreeNode *mParent = nullptr;
209  QList<QgsLayerTreeNode*> mChildren;
211  bool mExpanded;
214 };
215 
216 
217 
218 
219 #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.
This class is a base class for nodes in a layer tree.
Reads and writes project states.
Definition: qgsproject.h:74
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