QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
23
24#include <QDomNode>
25#include <QSet>
26#include <QString>
27#include <QVector>
28
29class QDomDocument;
30
33class QgsMapLayer;
35class QgsProject;
36
45class CORE_EXPORT QgsLayerDefinition
46{
47 public:
58 static bool loadLayerDefinition(
59 const QString &path,
60 QgsProject *project,
61 QgsLayerTreeGroup *rootGroup,
62 QString &errorMessage SIP_OUT,
64 const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr
65 );
66
78 static bool loadLayerDefinition(
79 QDomDocument doc,
80 QgsProject *project,
81 QgsLayerTreeGroup *rootGroup,
82 QString &errorMessage SIP_OUT,
83 QgsReadWriteContext &context,
85 const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr
86 );
87
101 static bool exportLayerDefinition( const QString &path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT );
102
115 static bool exportLayerDefinition( const QString &path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, Qgis::FilePathType pathType, QString &errorMessage SIP_OUT );
116
120 static bool exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT, const QgsReadWriteContext &context );
121
131 static QDomDocument exportLayerDefinitionLayers( const QList<QgsMapLayer *> &layers, const QgsReadWriteContext &context );
132
138 static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context ) SIP_FACTORY;
139
145 static QList<QgsMapLayer *> loadLayerDefinitionLayers( const QString &qlrfile ) SIP_FACTORY;
146
151 class CORE_EXPORT DependencySorter
152 {
153 public:
158 explicit DependencySorter( const QDomDocument &doc );
159
164 explicit DependencySorter( const QString &fileName );
165
167 QVector<QDomNode> sortedLayerNodes() const { return mSortedLayerNodes; }
168
170 QStringList sortedLayerIds() const { return mSortedLayerIds; }
171
173 bool hasCycle() const { return mHasCycle; }
174
176 bool hasMissingDependency() const { return mHasMissingDependency; }
177
183 bool isLayerDependent( const QString &layerId ) const;
184
185 private:
186 QVector<QDomNode> mSortedLayerNodes;
187 QStringList mSortedLayerIds;
188 QSet<QString> mDependentLayerIds;
189 bool mHasCycle;
190 bool mHasMissingDependency;
191 void init( const QDomDocument &doc );
192 };
193
194 private:
195 static QList<QgsMapLayer *> loadLayerDefinitionLayersInternal( QDomDocument &document, QgsReadWriteContext &context, QString &errorMessage );
196};
197
198#endif // QGSLAYERDEFINITION_H
LayerTreeInsertionMethod
Layer tree insertion methods.
Definition qgis.h:4666
@ OptimalInInsertionGroup
Layers are added at optimal locations across the insertion point's group.
Definition qgis.h:4669
FilePathType
File path types.
Definition qgis.h:1755
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.
DependencySorter(const QDomDocument &doc)
Constructor.
QVector< QDomNode > sortedLayerNodes() const
Gets the layer nodes in an order where they can be loaded incrementally without dependency break.
Holds generic methods for loading/exporting QLR files.
static QDomDocument exportLayerDefinitionLayers(const QList< QgsMapLayer * > &layers, const QgsReadWriteContext &context)
Returns the given layer as a layer definition document Layer definitions store the data source as wel...
static QList< QgsMapLayer * > loadLayerDefinitionLayers(QDomDocument &document, QgsReadWriteContext &context)
Creates new layers from a layer definition document.
static bool loadLayerDefinition(const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, Qgis::LayerTreeInsertionMethod insertMethod=Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint=nullptr)
Loads the QLR at path into QGIS.
static bool exportLayerDefinition(const QString &path, const QList< QgsLayerTreeNode * > &selectedTreeNodes, QString &errorMessage)
Exports the selected layer tree nodes to a QLR file.
Layer tree group node serves as a container for layers and further groups.
Base class for nodes in a layer tree.
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_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
A structure to define the insertion point to the layer tree.