QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
27 class QDomDocument;
28 
29 class QgsLayerTreeGroup;
30 class QgsLayerTreeNode;
31 class QgsMapLayer;
33 class QgsProject;
34 
43 class 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
QgsLayerDefinition
The QgsLayerDefinition class holds generic methods for loading/exporting QLR files.
Definition: qgslayerdefinition.h:43
QgsLayerTreeNode
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:75
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
qgis.h
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayerDefinition::DependencySorter::sortedLayerNodes
QVector< QDomNode > sortedLayerNodes() const
Gets the layer nodes in an order where they can be loaded incrementally without dependency break.
Definition: qgslayerdefinition.h:131
qgis_sip.h
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:40
QgsLayerDefinition::DependencySorter::hasCycle
bool hasCycle() const
Whether some cyclic dependency has been detected.
Definition: qgslayerdefinition.h:137
Qgis::FilePathType
FilePathType
File path types.
Definition: qgis.h:751
QgsLayerDefinition::DependencySorter::sortedLayerIds
QStringList sortedLayerIds() const
Gets the layer IDs in an order where they can be loaded incrementally without dependency break.
Definition: qgslayerdefinition.h:134
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsLayerDefinition::DependencySorter
Class used to work with layer dependencies stored in a XML project or layer definition file.
Definition: qgslayerdefinition.h:114
QgsLayerDefinition::DependencySorter::hasMissingDependency
bool hasMissingDependency() const
Whether some dependency is missing.
Definition: qgslayerdefinition.h:140