QGIS API Documentation  2.6.0-Brighton
 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 
63 class CORE_EXPORT QgsLayerTreeNode : public QObject
64 {
65  Q_OBJECT
66  public:
67 
69  enum NodeType
70  {
72  NodeLayer
73  };
74 
76 
78  NodeType nodeType() { return mNodeType; }
80  QgsLayerTreeNode* parent() { return mParent; }
82  QList<QgsLayerTreeNode*> children() { return mChildren; }
83 
85  static QgsLayerTreeNode* readXML( QDomElement& element );
87  virtual void writeXML( QDomElement& parentElement ) = 0;
88 
90  virtual QString dump() const = 0;
91 
93  virtual QgsLayerTreeNode* clone() const = 0;
94 
96  bool isExpanded() const;
98  void setExpanded( bool expanded );
99 
101  void setCustomProperty( const QString& key, const QVariant& value );
103  QVariant customProperty( const QString& key, const QVariant& defaultValue = QVariant() ) const;
105  void removeCustomProperty( const QString& key );
107  QStringList customProperties() const;
108 
109  signals:
110 
112  void willAddChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
114  void addedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
116  void willRemoveChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
118  void removedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
120  void visibilityChanged( QgsLayerTreeNode* node, Qt::CheckState state );
122  void customPropertyChanged( QgsLayerTreeNode* node, QString key );
124  void expandedChanged( QgsLayerTreeNode* node, bool expanded );
125 
126  protected:
127 
128  QgsLayerTreeNode( NodeType t );
129  QgsLayerTreeNode( const QgsLayerTreeNode& other );
130 
131  // low-level utility functions
132 
133  void readCommonXML( QDomElement& element );
134  void writeCommonXML( QDomElement& element );
135 
137  void insertChildrenPrivate( int index, QList<QgsLayerTreeNode*> nodes );
139  void removeChildrenPrivate( int from, int count );
140 
141 
142  protected:
148  QList<QgsLayerTreeNode*> mChildren;
150  bool mExpanded;
153 };
154 
155 
156 
157 
158 #endif // QGSLAYERTREENODE_H