QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
22 #include <QString>
23 #include <QVector>
24 #include <QDomNode>
25 
26 class QDomDocument;
27 
28 class QgsLayerTreeGroup;
29 class QgsLayerTreeNode;
30 class QgsMapLayer;
32 class QgsProject;
33 
42 class CORE_EXPORT QgsLayerDefinition
43 {
44  public:
46  static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT );
48  static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, QgsReadWriteContext &context );
50  static bool exportLayerDefinition( QString path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT );
52  static bool exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT, const QgsReadWriteContext &context );
53 
63  static QDomDocument exportLayerDefinitionLayers( const QList<QgsMapLayer *> &layers, const QgsReadWriteContext &context );
64 
70  static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context ) SIP_FACTORY;
71 
77  static QList<QgsMapLayer *> loadLayerDefinitionLayers( const QString &qlrfile ) SIP_FACTORY;
78 
83  class CORE_EXPORT DependencySorter
84  {
85  public:
86 
91  DependencySorter( const QDomDocument &doc );
92 
97  DependencySorter( const QString &fileName );
98 
100  QVector<QDomNode> sortedLayerNodes() const { return mSortedLayerNodes; }
101 
103  QStringList sortedLayerIds() const { return mSortedLayerIds; }
104 
106  bool hasCycle() const { return mHasCycle; }
107 
109  bool hasMissingDependency() const { return mHasMissingDependency; }
110 
111  private:
112  QVector<QDomNode> mSortedLayerNodes;
113  QStringList mSortedLayerIds;
114  bool mHasCycle;
115  bool mHasMissingDependency;
116  void init( const QDomDocument &doc );
117  };
118 };
119 
120 #endif // QGSLAYERDEFINITION_H
QgsLayerDefinition
The QgsLayerDefinition class holds generic methods for loading/exporting QLR files.
Definition: qgslayerdefinition.h:42
QgsLayerTreeNode
Definition: qgslayertreenode.h:74
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsProject
Definition: qgsproject.h:92
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:100
qgis_sip.h
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
QgsLayerDefinition::DependencySorter::hasCycle
bool hasCycle() const
Whether some cyclic dependency has been detected.
Definition: qgslayerdefinition.h:106
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:103
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsLayerDefinition::DependencySorter
Definition: qgslayerdefinition.h:83
QgsLayerDefinition::DependencySorter::hasMissingDependency
bool hasMissingDependency() const
Whether some dependency is missing.
Definition: qgslayerdefinition.h:109