QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgslayertreegroup.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayertreegroup.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 QGSLAYERTREEGROUP_H
17#define QGSLAYERTREEGROUP_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsgrouplayer.h"
22#include "qgslayertreenode.h"
23#include "qgsmaplayerref.h"
24
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
29class QgsMapLayer;
32class QgsGroupLayer;
33
44class CORE_EXPORT QgsLayerTreeGroup : public QgsLayerTreeNode
45{
46 Q_OBJECT
47 public:
51 QgsLayerTreeGroup( const QString &name = QString(), bool checked = true );
52
53#ifndef SIP_RUN
55#endif
56
57#ifdef SIP_RUN
58 // clang-format off
59 SIP_PYOBJECT __repr__();
60 % MethodCode
61 QString str = u"<QgsLayerTreeGroup: %1>"_s.arg( sipCpp->name() );
62 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
63 % End
64// clang-format on
65#endif
66
70 QString name() const override;
71
75 void setName( const QString &n ) override;
76
80 QgsLayerTreeGroup *insertGroup( int index, const QString &name );
81
85 QgsLayerTreeGroup *addGroup( const QString &name );
86
90 QgsLayerTreeLayer *insertLayer( int index, QgsMapLayer *layer );
91
96
102 QgsLayerTreeCustomNode *insertCustomNode( int index, const QString &id, const QString &name = QString() );
103
110
116 QgsLayerTreeCustomNode *addCustomNode( const QString &id, const QString &name = QString() );
117
121 void insertChildNodes( int index, const QList<QgsLayerTreeNode *> &nodes SIP_TRANSFER );
122
126 void insertChildNode( int index, QgsLayerTreeNode *node SIP_TRANSFER );
127
132
136 void removeChildNode( QgsLayerTreeNode *node );
137
141 void removeLayer( QgsMapLayer *layer );
142
148 void removeCustomNode( QgsLayerTreeCustomNode *customNode );
149
153 void removeChildren( int from, int count );
154
159
163 void removeAllChildren();
164
168 QgsLayerTreeLayer *findLayer( QgsMapLayer *layer ) const;
169
173 QgsLayerTreeLayer *findLayer( const QString &layerId ) const;
174
180 QList<QgsLayerTreeLayer *> findLayers() const;
181
187 QgsLayerTreeCustomNode *findCustomNode( const QString &id ) const;
188
195 QList<QgsLayerTreeNode *> findLayersAndCustomNodes() const;
196
211 void reorderGroupLayers( const QList< QgsMapLayer * > &order );
212
228 void reorderGroupLayersAndCustomNodes( const QList< QgsLayerTreeNode * > &order );
229
238 QList<QgsMapLayer *> layerOrderRespectingGroupLayers() const SIP_SKIP;
239
249 QList<QgsLayerTreeNode *> layerAndCustomNodeOrderRespectingGroupLayers() const SIP_SKIP;
250
254 QStringList findLayerIds() const;
255
259 QStringList findCustomNodeIds() const;
260
264 QgsLayerTreeGroup *findGroup( const QString &name );
265
269 QList<QgsLayerTreeGroup *> findGroups( bool recursive = false ) const;
270
275 static QgsLayerTreeGroup *readXml( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY; // cppcheck-suppress duplInheritedMember
276
281 static QgsLayerTreeGroup *readXml( const QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
282
286 void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
287
292 void readChildrenFromXml( const QDomElement &element, const QgsReadWriteContext &context );
293
297 QString dump() const override;
298
302 QgsLayerTreeGroup *clone() const override SIP_FACTORY;
303
307 void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
308
312 void setItemVisibilityCheckedRecursive( bool checked ) override;
313
317 bool isMutuallyExclusive() const;
318
324 void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
325
335
347 void setGroupLayer( QgsGroupLayer *layer );
348
364
370
376
387
397 bool hasWmsTimeDimension() const;
398
399 protected slots:
400
402
403 protected:
408
409 QString mName;
410
412
414 bool mMutuallyExclusive = false;
415
421
423
425 void makeOrphan() override SIP_SKIP;
426
427 private:
428#ifdef SIP_RUN
429
433 QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
434#endif
435
436 QgsLayerTreeGroup &operator=( const QgsLayerTreeGroup & ) = delete;
437
444 static void readLegacyServerProperties( QgsLayerTreeGroup *groupNode );
445
446 void init();
447 void updateGroupLayers();
448 void refreshParentGroupLayerMembers();
449
450 QgsMapLayerRef mGroupLayer;
451
455 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
456};
457
458
459#endif // QGSLAYERTREEGROUP_H
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
Layer tree custom node serves as a node for objects that are not layers nor groups.
QStringList findCustomNodeIds() const
Find custom node IDs.
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position.
QgsLayerTreeCustomNode * insertCustomNode(int index, const QString &id, const QString &name=QString())
Insert a new custom node with the given id and name at specified index.
QgsLayerTreeCustomNode * findCustomNode(const QString &id) const
Find custom node representing an object specified by its ID.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
QgsGroupLayer * convertToGroupLayer(const QgsGroupLayer::LayerOptions &options)
Converts the group to a QgsGroupLayer.
void setHasWmsTimeDimension(const bool hasWmsTimeDimension)
Sets whether the WMS time dimension should be computed for this group or not.
QgsLayerTreeGroup * insertGroup(int index, const QString &name)
Insert a new group node with given name at specified position.
void readChildrenFromXml(const QDomElement &element, const QgsReadWriteContext &context)
Read children from XML and append them to the group.
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group.
QList< QgsLayerTreeNode * > findLayersAndCustomNodes() const
Find all layer and custom nodes.
QList< QgsLayerTreeGroup * > findGroups(bool recursive=false) const
Find group layer nodes.
QString name() const override
Returns the group's name.
QgsLayerTreeGroup(const QString &name=QString(), bool checked=true)
Constructor.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
QList< QgsMapLayer * > layerOrderRespectingGroupLayers() const
Returns an ordered list of map layers in the group, ignoring any layers which are child layers of Qgs...
void removeCustomNode(QgsLayerTreeCustomNode *customNode)
Remove a custom node from this group.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the layer tree group.
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
QList< QgsLayerTreeNode * > layerAndCustomNodeOrderRespectingGroupLayers() const
Returns an ordered list of map layers and custom nodes in the group, ignoring any layers which are ch...
void insertChildNodes(int index, const QList< QgsLayerTreeNode * > &nodes)
Insert existing nodes at specified position.
void removeAllChildren()
Remove all child nodes.
bool mMutuallyExclusive
Whether the group is mutually exclusive (i.e. only one child can be checked at a time).
void setIsMutuallyExclusive(bool enabled, int initialChildIndex=-1)
Set whether the group is mutually exclusive (only one child can be checked at a time).
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
bool isMutuallyExclusive() const
Returns whether the group is mutually exclusive (only one child can be checked at a time).
QgsLayerTreeCustomNode * addCustomNode(const QString &id, const QString &name=QString())
Append a new custom node with the given id and name.
void updateChildVisibilityMutuallyExclusive()
Set check state of children - if mutually exclusive.
bool hasWmsTimeDimension() const
Returns whether the WMS time dimension should be computed for this group or not.
void setGroupLayer(QgsGroupLayer *layer)
Sets the associated group layer, if the layer tree group will be treated as group layer during map re...
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name.
void removeChildren(int from, int count)
Remove child nodes from index "from".
void removeChildrenGroupWithoutLayers()
Remove all child group nodes without layers.
QgsLayerTreeLayer * addLayer(QgsMapLayer *layer)
Append a new layer node for given map layer.
void removeLayer(QgsMapLayer *layer)
Remove map layer's node from this group.
QgsLayerTreeLayer * insertLayer(int index, QgsMapLayer *layer)
Insert a new layer node for given map layer at specified position.
void nodeVisibilityChanged(QgsLayerTreeNode *node)
void reorderGroupLayers(const QList< QgsMapLayer * > &order)
Reorders layers in the group to match the order specified by order.
int mMutuallyExclusiveChildIndex
Keeps track which child has been most recently selected (so if the whole group is unchecked and check...
void reorderGroupLayersAndCustomNodes(const QList< QgsLayerTreeNode * > &order)
Reorders layers and custom nodes in the group to match the order specified by order.
QgsGroupLayer * groupLayer()
Returns a reference to the associated group layer, if the layer tree group will be treated as group l...
Layer tree node points to a map layer.
virtual void setName(const QString &name)=0
Set name of the node.
virtual void makeOrphan()
Sets parent to nullptr and disconnects all external and forwarded signals.
virtual QString dump() const =0
Returns string with layer tree structure. For debug purposes only.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
virtual QString name() const =0
Returns name of the node.
QgsLayerTreeNode(NodeType t, bool checked=true)
Constructor.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules).
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
virtual void resolveReferences(const QgsProject *project, bool looseMatching=false)=0
Turn textual references to layers into map layer object from project.
Manages QGIS Server properties for a map layer.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
A container for the context for various read/write operations on objects.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
_LayerRef< QgsMapLayer > QgsMapLayerRef
Setting options for loading group layers.