QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgslayertree.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertree.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 QGSLAYERTREE_H
17 #define QGSLAYERTREE_H
18 
19 #include "qgslayertreenode.h"
20 #include "qgslayertreegroup.h"
21 #include "qgslayertreelayer.h"
22 
32 class CORE_EXPORT QgsLayerTree : public QgsLayerTreeGroup
33 {
34  Q_OBJECT
35 
36  public:
37 
43  static inline bool isGroup( QgsLayerTreeNode *node )
44  {
45  return node && node->nodeType() == QgsLayerTreeNode::NodeGroup;
46  }
47 
53  static inline bool isLayer( const QgsLayerTreeNode *node )
54  {
55  return node && node->nodeType() == QgsLayerTreeNode::NodeLayer;
56  }
57 
64  static inline QgsLayerTreeGroup *toGroup( QgsLayerTreeNode *node ) SIP_SKIP
65  {
66  return static_cast<QgsLayerTreeGroup *>( node );
67  }
68 
75  static inline QgsLayerTreeLayer *toLayer( QgsLayerTreeNode *node ) SIP_SKIP
76  {
77  return static_cast<QgsLayerTreeLayer *>( node );
78  }
79 
86  static inline const QgsLayerTreeLayer *toLayer( const QgsLayerTreeNode *node ) SIP_SKIP
87  {
88  return static_cast< const QgsLayerTreeLayer *>( node );
89  }
90 
94  QgsLayerTree();
95 
107  QList<QgsMapLayer *> customLayerOrder() const;
108 
120  void setCustomLayerOrder( const QList<QgsMapLayer *> &customLayerOrder );
121 
133  void setCustomLayerOrder( const QStringList &customLayerOrder ) SIP_PYNAME( setCustomLayerOrderByIds );
134 
145  QList<QgsMapLayer *> layerOrder() const;
146 
155  bool hasCustomLayerOrder() const;
156 
165  void setHasCustomLayerOrder( bool hasCustomLayerOrder );
166 
175  static QgsLayerTree *readXml( QDomElement &element, const QgsReadWriteContext &context );
176 
183  void readLayerOrderFromXml( const QDomElement &doc );
184 
185  void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
186 
187  QgsLayerTree *clone() const override SIP_FACTORY;
188 
194  void clear();
195 
196  signals:
197 
203  void customLayerOrderChanged();
204 
210  void layerOrderChanged();
211 
219  void hasCustomLayerOrderChanged( bool hasCustomLayerOrder );
220 
221  private slots:
222  void nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
223  void nodeRemovedChildren();
224 
225  private:
227  QgsLayerTree( const QgsLayerTree &other );
228  void addMissingLayers();
229  QgsWeakMapLayerPointerList mCustomLayerOrder;
230  bool mHasCustomLayerOrder = false;
231 
232  QgsLayerTree &operator= ( const QgsLayerTree & ) = delete;
233 };
234 
235 #endif // QGSLAYERTREE_H
QgsLayerTreeNode::NodeGroup
@ NodeGroup
Container of other groups and layers.
Definition: qgslayertreenode.h:101
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsLayerTreeNode
Definition: qgslayertreenode.h:74
QgsWeakMapLayerPointerList
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1677
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsLayerTreeGroup::writeXml
void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context) override
Write group (tree) as XML element <layer-tree-group> and add it to the given parent element.
Definition: qgslayertreegroup.cpp:299
QgsLayerTreeNode::NodeLayer
@ NodeLayer
Leaf node pointing to a layer.
Definition: qgslayertreenode.h:102
qgslayertreelayer.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayerTreeNode::nodeType
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
Definition: qgslayertreenode.h:108
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLayerTree
Definition: qgslayertree.h:32
qgslayertreegroup.h
QgsLayerTreeLayer
Definition: qgslayertreelayer.h:43
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
QgsLayerTreeGroup::readXml
static QgsLayerTreeGroup * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read group (tree) from XML element <layer-tree-group> and return the newly created group (or nullptr ...
Definition: qgslayertreegroup.cpp:268
qgslayertreenode.h
QgsLayerTreeGroup::clone
QgsLayerTreeGroup * clone() const override
Returns a clone of the group.
Definition: qgslayertreegroup.cpp:347