QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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.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
Layer tree group node serves as a container for layers and further groups.
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
Definition: qgsmaplayer.h:63
The QgsLayerDefinition class holds generic methods for loading/exporting QLR files.
Class used to work with layer dependencies stored in a XML project or layer definition file...
bool hasCycle() const
Whether some cyclic dependency has been detected.
This class is a base class for nodes in a layer tree.
Reads and writes project states.
Definition: qgsproject.h:89
bool hasMissingDependency() const
Whether some dependency is missing.
#define SIP_FACTORY
Definition: qgis_sip.h:69
#define SIP_OUT
Definition: qgis_sip.h:51
QVector< QDomNode > sortedLayerNodes() const
Gets the layer nodes in an order where they can be loaded incrementally without dependency break...
QStringList sortedLayerIds() const
Gets the layer IDs in an order where they can be loaded incrementally without dependency break...