LCOV - code coverage report
Current view: top level - core - qgslayerdefinition.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 4 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       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;
      31                 :            : class QgsReadWriteContext;
      32                 :            : class QgsProject;
      33                 :            : 
      34                 :            : /**
      35                 :            :  * \ingroup core
      36                 :            :  * \brief The QgsLayerDefinition class holds generic methods for loading/exporting QLR files.
      37                 :            :  *
      38                 :            :  * QLR files are an export of the layer xml including the style and datasource location.  There is no link
      39                 :            :  * to the QLR file once loaded.  Consider the QLR file a mini project file for layers and styles.  QLR
      40                 :            :  * files also store the layer tree info for the exported layers, including group information.
      41                 :            :  */
      42                 :            : class CORE_EXPORT QgsLayerDefinition
      43                 :            : {
      44                 :            :   public:
      45                 :            :     //! Loads the QLR at path into QGIS.  New layers are added to given project into layer tree specified by rootGroup
      46                 :            :     static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT );
      47                 :            :     //! Loads the QLR from the XML document.  New layers are added to given project into layer tree specified by rootGroup
      48                 :            :     static bool loadLayerDefinition( QDomDocument doc,  QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, QgsReadWriteContext &context );
      49                 :            :     //! Export the selected layer tree nodes to a QLR file
      50                 :            :     static bool exportLayerDefinition( QString path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT );
      51                 :            :     //! Export the selected layer tree nodes to a QLR-XML document
      52                 :            :     static bool exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT, const QgsReadWriteContext &context );
      53                 :            : 
      54                 :            :     /**
      55                 :            :      * Returns the given layer as a layer definition document
      56                 :            :      *  Layer definitions store the data source as well as styling and custom properties.
      57                 :            :      *
      58                 :            :      *  Layer definitions can be used to load a layer and styling all from a single file.
      59                 :            :      *
      60                 :            :      *  This is a low-level routine that does not write layer tree.
      61                 :            :      *  \see exportLayerDefinition()
      62                 :            :      */
      63                 :            :     static QDomDocument exportLayerDefinitionLayers( const QList<QgsMapLayer *> &layers, const QgsReadWriteContext &context );
      64                 :            : 
      65                 :            :     /**
      66                 :            :      * Creates new layers from a layer definition document.
      67                 :            :      * This is a low-level routine that does not resolve layer ID conflicts, dependencies and joins
      68                 :            :      * \see loadLayerDefinition()
      69                 :            :      */
      70                 :            :     static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context ) SIP_FACTORY;
      71                 :            : 
      72                 :            :     /**
      73                 :            :      * Creates new layers from a layer definition file (.QLR)
      74                 :            :      * This is a low-level routine that does not resolve layer ID conflicts, dependencies and joins
      75                 :            :      * \see loadLayerDefinition()
      76                 :            :      */
      77                 :            :     static QList<QgsMapLayer *> loadLayerDefinitionLayers( const QString &qlrfile ) SIP_FACTORY;
      78                 :            : 
      79                 :            :     /**
      80                 :            :      * \ingroup core
      81                 :            :      * \brief Class used to work with layer dependencies stored in a XML project or layer definition file
      82                 :            :      */
      83                 :          0 :     class CORE_EXPORT DependencySorter
      84                 :            :     {
      85                 :            :       public:
      86                 :            : 
      87                 :            :         /**
      88                 :            :          * Constructor
      89                 :            :          * \param doc The XML document containing maplayer elements
      90                 :            :          */
      91                 :            :         DependencySorter( const QDomDocument &doc );
      92                 :            : 
      93                 :            :         /**
      94                 :            :          * Constructor
      95                 :            :          * \param fileName The filename where the XML document is stored
      96                 :            :          */
      97                 :            :         DependencySorter( const QString &fileName );
      98                 :            : 
      99                 :            :         //! Gets the layer nodes in an order where they can be loaded incrementally without dependency break
     100                 :          0 :         QVector<QDomNode> sortedLayerNodes() const { return mSortedLayerNodes; }
     101                 :            : 
     102                 :            :         //! Gets the layer IDs in an order where they can be loaded incrementally without dependency break
     103                 :            :         QStringList sortedLayerIds() const { return mSortedLayerIds; }
     104                 :            : 
     105                 :            :         //! Whether some cyclic dependency has been detected
     106                 :          0 :         bool hasCycle() const { return mHasCycle; }
     107                 :            : 
     108                 :            :         //! Whether some dependency is missing
     109                 :          0 :         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                 :            :   private:
     120                 :            : 
     121                 :            :     static QList<QgsMapLayer *> loadLayerDefinitionLayersInternal( QDomDocument &document, QgsReadWriteContext &context, QString &errorMessage );
     122                 :            : 
     123                 :            : 
     124                 :            : };
     125                 :            : 
     126                 :            : #endif // QGSLAYERDEFINITION_H

Generated by: LCOV version 1.14