QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
65  {
66  return static_cast<QgsLayerTreeGroup *>( node );
67  }
68 
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 
233 #endif // QGSLAYERTREE_H
Layer tree group node serves as a container for layers and further groups.
The class is used as a container of context for various read/write operations on other objects...
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:75
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:43
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:64
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...
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:32
#define SIP_SKIP
Definition: qgis_sip.h:119
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:53
This class is a base class for nodes in a layer tree.
static QgsLayerTreeGroup * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on ...
#define SIP_FACTORY
Definition: qgis_sip.h:69
static const QgsLayerTreeLayer * toLayer(const QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:86
Leaf node pointing to a layer.
QgsLayerTreeGroup * clone() const override
Returns a clone of the group.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1489
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
Container of other groups and layers.
Layer tree node points to a map layer.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74