QGIS API Documentation 4.3.0-Master (6402a64e93b)
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
77 QString id() const override { return mId; }
78
82 QgsLayerTreeGroup *insertGroup( int index, const QString &name );
83
87 QgsLayerTreeGroup *addGroup( const QString &name );
88
92 QgsLayerTreeLayer *insertLayer( int index, QgsMapLayer *layer );
93
97 QgsLayerTreeLayer *addLayer( QgsMapLayer *layer );
98
104 QgsLayerTreeCustomNode *insertCustomNode( int index, const QString &id, const QString &name = QString() );
105
111 QgsLayerTreeCustomNode *insertCustomNode( int index, QgsLayerTreeCustomNode *node SIP_TRANSFER );
112
118 QgsLayerTreeCustomNode *addCustomNode( const QString &id, const QString &name = QString() );
119
123 void insertChildNodes( int index, const QList<QgsLayerTreeNode *> &nodes SIP_TRANSFER );
124
128 void insertChildNode( int index, QgsLayerTreeNode *node SIP_TRANSFER );
129
133 void addChildNode( QgsLayerTreeNode *node SIP_TRANSFER );
134
138 void removeChildNode( QgsLayerTreeNode *node );
139
143 void removeLayer( QgsMapLayer *layer );
144
150 void removeCustomNode( QgsLayerTreeCustomNode *customNode );
151
155 void removeChildren( int from, int count );
156
160 void removeChildrenGroupWithoutLayers();
161
165 void removeAllChildren();
166
170 QgsLayerTreeLayer *findLayer( QgsMapLayer *layer ) const;
171
175 QgsLayerTreeLayer *findLayer( const QString &layerId ) const;
176
182 QList<QgsLayerTreeLayer *> findLayers() const;
183
189 QgsLayerTreeCustomNode *findCustomNode( const QString &id ) const;
190
197 QList<QgsLayerTreeNode *> findLayersAndCustomNodes() const;
198
213 void reorderGroupLayers( const QList< QgsMapLayer * > &order );
214
230 void reorderGroupLayersAndCustomNodes( const QList< QgsLayerTreeNode * > &order );
231
240 QList<QgsMapLayer *> layerOrderRespectingGroupLayers() const SIP_SKIP;
241
251 QList<QgsLayerTreeNode *> layerAndCustomNodeOrderRespectingGroupLayers() const SIP_SKIP;
252
256 QStringList findLayerIds() const;
257
261 QStringList findCustomNodeIds() const;
262
266 QgsLayerTreeGroup *findGroup( const QString &name );
267
271 QList<QgsLayerTreeGroup *> findGroups( bool recursive = false ) const;
272
277 static QgsLayerTreeGroup *readXml( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY; // cppcheck-suppress duplInheritedMember
278
283 static QgsLayerTreeGroup *readXml( const QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
284
288 void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
289
294 void readChildrenFromXml( const QDomElement &element, const QgsReadWriteContext &context );
295
299 QString dump() const override;
300
304 QgsLayerTreeGroup *clone() const override SIP_FACTORY;
305
309 void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
310
314 void setItemVisibilityCheckedRecursive( bool checked ) override;
315
319 bool isMutuallyExclusive() const;
320
326 void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
327
336 QgsGroupLayer *groupLayer();
337
349 void setGroupLayer( QgsGroupLayer *layer );
350
365 QgsGroupLayer *convertToGroupLayer( const QgsGroupLayer::LayerOptions &options ) SIP_FACTORY;
366
371 QgsMapLayerServerProperties *serverProperties();
372
377 const QgsMapLayerServerProperties *serverProperties() const SIP_SKIP;
378
388 void setHasWmsTimeDimension( const bool hasWmsTimeDimension );
389
399 bool hasWmsTimeDimension() const;
400
412 Qgis::WmsGroupRequestMode wmsGroupRequestMode() const;
413
422 void setWmsGroupRequestMode( Qgis::WmsGroupRequestMode groupRequestMode );
423
424 protected slots:
425
426 void nodeVisibilityChanged( QgsLayerTreeNode *node );
427
428 protected:
432 void updateChildVisibilityMutuallyExclusive();
433
434 QString mName;
435
436 QString mId;
437
439
441 bool mMutuallyExclusive = false;
442
448
450
452 void makeOrphan() override SIP_SKIP;
453
454 private:
455#ifdef SIP_RUN
456
460 QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
461#endif
462
463 QgsLayerTreeGroup &operator=( const QgsLayerTreeGroup & ) = delete;
464
465 // only QgsLayerTreeUtils::regenerateGroupIds may assign a new id
466 friend class QgsLayerTreeUtils;
467 void setId( const QString &id );
468
475 static void readLegacyServerProperties( QgsLayerTreeGroup *groupNode );
476
477 void init();
478 void updateGroupLayers();
479 void refreshParentGroupLayerMembers();
480
481 QgsMapLayerRef mGroupLayer;
482
486 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
487
489};
490
491
492#endif // QGSLAYERTREEGROUP_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
WmsGroupRequestMode
Request mode of groups in a WMS context.
Definition qgis.h:6942
@ Normal
Group and children can be requested.
Definition qgis.h:6943
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.
Layer tree group node serves as a container for layers and further groups.
friend class QgsLayerTreeUtils
QString name() const override
Returns the group's name.
QgsLayerTreeGroup(const QString &name=QString(), bool checked=true)
Constructor.
bool mMutuallyExclusive
Whether the group is mutually exclusive (i.e. only one child can be checked at a time).
QString id() const override
Returns the node's unique identifier.
void makeOrphan() override
Sets parent to nullptr and disconnects all external and forwarded signals.
int mMutuallyExclusiveChildIndex
Keeps track which child has been most recently selected (so if the whole group is unchecked and check...
Layer tree node points to a map layer.
Base class for nodes in a layer tree.
virtual void setName(const QString &name)=0
Set name of the node.
virtual QString name() const =0
Returns name of the node.
QgsLayerTreeNode(NodeType t, bool checked=true)
Constructor.
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:114
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