QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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;
110 
111  signals:
112 
114  void willAddChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
116  void addedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
118  void willRemoveChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
120  void removedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
122  void visibilityChanged( QgsLayerTreeNode* node, Qt::CheckState state );
124  void customPropertyChanged( QgsLayerTreeNode* node, QString key );
126  void expandedChanged( QgsLayerTreeNode* node, bool expanded );
127 
128  protected:
129 
130  QgsLayerTreeNode( NodeType t );
131  QgsLayerTreeNode( const QgsLayerTreeNode& other );
132 
133  // low-level utility functions
134 
135  void readCommonXML( QDomElement& element );
136  void writeCommonXML( QDomElement& element );
137 
139  void insertChildrenPrivate( int index, QList<QgsLayerTreeNode*> nodes );
141  void removeChildrenPrivate( int from, int count );
142 
143 
144  protected:
150  QList<QgsLayerTreeNode*> mChildren;
152  bool mExpanded;
155 };
156 
157 
158 
159 
160 #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