QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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"
22
23#include <QString>
24#include <QVector>
25#include <QDomNode>
26
27class QDomDocument;
28
31class QgsMapLayer;
33class QgsProject;
34
43class CORE_EXPORT QgsLayerDefinition
44{
45 public:
47 static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT );
49 static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, QgsReadWriteContext &context );
50
64 static bool exportLayerDefinition( const QString &path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT );
65
78 static bool exportLayerDefinition( const QString &path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, Qgis::FilePathType pathType, QString &errorMessage SIP_OUT );
79
83 static bool exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT, const QgsReadWriteContext &context );
84
94 static QDomDocument exportLayerDefinitionLayers( const QList<QgsMapLayer *> &layers, const QgsReadWriteContext &context );
95
101 static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context ) SIP_FACTORY;
102
108 static QList<QgsMapLayer *> loadLayerDefinitionLayers( const QString &qlrfile ) SIP_FACTORY;
109
114 class CORE_EXPORT DependencySorter
115 {
116 public:
117
122 DependencySorter( const QDomDocument &doc );
123
128 DependencySorter( const QString &fileName );
129
131 QVector<QDomNode> sortedLayerNodes() const { return mSortedLayerNodes; }
132
134 QStringList sortedLayerIds() const { return mSortedLayerIds; }
135
137 bool hasCycle() const { return mHasCycle; }
138
140 bool hasMissingDependency() const { return mHasMissingDependency; }
141
142 private:
143 QVector<QDomNode> mSortedLayerNodes;
144 QStringList mSortedLayerIds;
145 bool mHasCycle;
146 bool mHasMissingDependency;
147 void init( const QDomDocument &doc );
148 };
149
150 private:
151
152 static QList<QgsMapLayer *> loadLayerDefinitionLayersInternal( QDomDocument &document, QgsReadWriteContext &context, QString &errorMessage );
153
154
155};
156
157#endif // QGSLAYERDEFINITION_H
FilePathType
File path types.
Definition: qgis.h:983
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:73
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:105
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