QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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;
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, QString key );
128  void expandedChanged( QgsLayerTreeNode *node, bool expanded );
129 
130  protected:
131 
132  QgsLayerTreeNode( NodeType t );
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:
151  QList<QgsLayerTreeNode*> mChildren;
153  bool mExpanded;
156 };
157 
158 
159 
160 
161 #endif // QGSLAYERTREENODE_H