QGIS API Documentation  2.14.0-Essen
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 
87  static QgsLayerTreeNode *readXML( QDomElement &element );
89  virtual void writeXML( QDomElement &parentElement ) = 0;
90 
92  virtual QString dump() const = 0;
93 
95  virtual QgsLayerTreeNode *clone() const = 0;
96 
98  bool isExpanded() const;
100  void setExpanded( bool expanded );
101 
103  void setCustomProperty( const QString &key, const QVariant &value );
105  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
107  void removeCustomProperty( const QString &key );
109  QStringList customProperties() const;
111  bool takeChild( QgsLayerTreeNode *node );
112 
113  signals:
114 
116  void willAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
118  void addedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
120  void willRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
122  void removedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
124  void visibilityChanged( QgsLayerTreeNode *node, Qt::CheckState state );
126  void customPropertyChanged( QgsLayerTreeNode *node, const QString& key );
128  void expandedChanged( QgsLayerTreeNode *node, bool expanded );
129 
130  protected:
131 
133  QgsLayerTreeNode( const QgsLayerTreeNode &other );
134 
135  // low-level utility functions
136 
137  void readCommonXML( QDomElement &element );
138  void writeCommonXML( QDomElement &element );
139 
141  void insertChildrenPrivate( int index, QList<QgsLayerTreeNode*> nodes );
143  void removeChildrenPrivate( int from, int count, bool destroy = true );
144 
145  protected:
153  bool mExpanded;
156 };
157 
158 
159 
160 
161 #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