QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgslayerdefinition.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayerdefinition.h
3 ---------------------
4 begin : January 2015
5 copyright : (C) 2015 by Nathan Woodrow
6 email : woodrow dot nathan 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#ifndef QGSLAYERDEFINITION_H
16#define QGSLAYERDEFINITION_H
17
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgis.h"
23
24#include <QString>
25#include <QVector>
26#include <QDomNode>
27#include <QSet>
28
29class QDomDocument;
30
33class QgsMapLayer;
35class QgsProject;
36
45class CORE_EXPORT QgsLayerDefinition
46{
47 public:
48
59 static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr );
60
72 static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, QgsReadWriteContext &context, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr );
73
87 static bool exportLayerDefinition( const QString &path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT );
88
101 static bool exportLayerDefinition( const QString &path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, Qgis::FilePathType pathType, QString &errorMessage SIP_OUT );
102
106 static bool exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT, const QgsReadWriteContext &context );
107
117 static QDomDocument exportLayerDefinitionLayers( const QList<QgsMapLayer *> &layers, const QgsReadWriteContext &context );
118
124 static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context ) SIP_FACTORY;
125
131 static QList<QgsMapLayer *> loadLayerDefinitionLayers( const QString &qlrfile ) SIP_FACTORY;
132
137 class CORE_EXPORT DependencySorter
138 {
139 public:
140
145 explicit DependencySorter( const QDomDocument &doc );
146
151 explicit DependencySorter( const QString &fileName );
152
154 QVector<QDomNode> sortedLayerNodes() const { return mSortedLayerNodes; }
155
157 QStringList sortedLayerIds() const { return mSortedLayerIds; }
158
160 bool hasCycle() const { return mHasCycle; }
161
163 bool hasMissingDependency() const { return mHasMissingDependency; }
164
170 bool isLayerDependent( const QString &layerId ) const;
171
172 private:
173 QVector<QDomNode> mSortedLayerNodes;
174 QStringList mSortedLayerIds;
175 QSet<QString> mDependentLayerIds;
176 bool mHasCycle;
177 bool mHasMissingDependency;
178 void init( const QDomDocument &doc );
179 };
180
181 private:
182
183 static QList<QgsMapLayer *> loadLayerDefinitionLayersInternal( QDomDocument &document, QgsReadWriteContext &context, QString &errorMessage );
184
185
186};
187
188#endif // QGSLAYERDEFINITION_H
LayerTreeInsertionMethod
Layer tree insertion methods.
Definition qgis.h:4225
@ OptimalInInsertionGroup
Layers are added at optimal locations across the insertion point's group.
FilePathType
File path types.
Definition qgis.h:1523
Class used to work with layer dependencies stored in a XML project or layer definition file.
bool hasMissingDependency() const
Whether some dependency is missing.
QStringList sortedLayerIds() const
Gets the layer IDs in an order where they can be loaded incrementally without dependency break.
bool hasCycle() const
Whether some cyclic dependency has been detected.
QVector< QDomNode > sortedLayerNodes() const
Gets the layer nodes in an order where they can be loaded incrementally without dependency break.
The QgsLayerDefinition class holds generic methods for loading/exporting QLR files.
Layer tree group node serves as a container for layers and further groups.
This class is a base class for nodes in a layer tree.
Base class for all map layer types.
Definition qgsmaplayer.h:76
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
The class is used as a container of context for various read/write operations on other objects.
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
A structure to define the insertion point to the layer tree.