QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
98  static QgsLayerTreeNode *readXML( QDomElement &element, bool looseMatch = false );
99 
101  virtual void writeXML( QDomElement &parentElement ) = 0;
102 
104  virtual QString dump() const = 0;
105 
107  virtual QgsLayerTreeNode *clone() const = 0;
108 
110  bool isExpanded() const;
112  void setExpanded( bool expanded );
113 
115  void setCustomProperty( const QString &key, const QVariant &value );
117  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
119  void removeCustomProperty( const QString &key );
121  QStringList customProperties() const;
123  bool takeChild( QgsLayerTreeNode *node );
124 
125  signals:
126 
128  void willAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
130  void addedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
132  void willRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
134  void removedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
136  void visibilityChanged( QgsLayerTreeNode *node, Qt::CheckState state );
138  void customPropertyChanged( QgsLayerTreeNode *node, const QString& key );
140  void expandedChanged( QgsLayerTreeNode *node, bool expanded );
143  void nameChanged( QgsLayerTreeNode* node, QString name );
144 
145  protected:
146 
148  QgsLayerTreeNode( const QgsLayerTreeNode &other );
149 
150  // low-level utility functions
151 
152  void readCommonXML( QDomElement &element );
153  void writeCommonXML( QDomElement &element );
154 
156  void insertChildrenPrivate( int index, QList<QgsLayerTreeNode*> nodes );
158  void removeChildrenPrivate( int from, int count, bool destroy = true );
159 
160  protected:
168  bool mExpanded;
171 };
172 
173 
174 
175 
176 #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.
const char * name() const
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.
void setName(const char *name)
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