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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgsweakrelation.h - QgsWeakRelation
       3                 :            : 
       4                 :            :  ---------------------
       5                 :            :  begin                : 5.12.2019
       6                 :            :  copyright            : (C) 2019 by Alessandro Pasotti
       7                 :            :  email                : elpaso at itopen dot it
       8                 :            :  ***************************************************************************
       9                 :            :  *                                                                         *
      10                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      11                 :            :  *   it under the terms of the GNU General Public License as published by  *
      12                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      13                 :            :  *   (at your option) any later version.                                   *
      14                 :            :  *                                                                         *
      15                 :            :  ***************************************************************************/
      16                 :            : #ifndef QGSWEAKRELATION_H
      17                 :            : #define QGSWEAKRELATION_H
      18                 :            : 
      19                 :            : #define SIP_NO_FILE
      20                 :            : 
      21                 :            : #include "qgis_core.h"
      22                 :            : #include "qgsrelation.h"
      23                 :            : #include "qgsvectorlayerref.h"
      24                 :            : 
      25                 :            : /**
      26                 :            :  * The QgsWeakRelation class represent a QgsRelation with possibly
      27                 :            :  * unresolved layers or unmatched fields.
      28                 :            :  *
      29                 :            :  * This class is used to store relation information attached to a
      30                 :            :  * layer style, a method to attempt relation resolution is also
      31                 :            :  * implemented and can be used to create a QgsRelation after the
      32                 :            :  * dependent layers are loaded and available.
      33                 :            :  *
      34                 :            :  * \note not available in Python bindings
      35                 :            :  * \ingroup core
      36                 :            :  * \since QGIS 3.12
      37                 :            :  */
      38                 :          0 : class CORE_EXPORT QgsWeakRelation
      39                 :            : {
      40                 :            :   public:
      41                 :            : 
      42                 :            :     /**
      43                 :            :      * Enum to distinguish if the layer is referenced or referencing
      44                 :            :      * \since QGIS 3.16
      45                 :            :      */
      46                 :            :     enum WeakRelationType
      47                 :            :     {
      48                 :            :       Referencing, //!< The layer is referencing
      49                 :            :       Referenced //!< The layer is referenced
      50                 :            :     };
      51                 :            : 
      52                 :            : 
      53                 :            :     /**
      54                 :            :      * Creates a QgsWeakRelation
      55                 :            :      */
      56                 :            :     QgsWeakRelation( const QString &relationId,
      57                 :            :                      const QString &relationName,
      58                 :            :                      const QgsRelation::RelationStrength strength,
      59                 :            :                      const QString &referencingLayerId,
      60                 :            :                      const QString &referencingLayerName,
      61                 :            :                      const QString &referencingLayerSource,
      62                 :            :                      const QString &referencingLayerProviderKey,
      63                 :            :                      const QString &referencedLayerId,
      64                 :            :                      const QString &referencedLayerName,
      65                 :            :                      const QString &referencedLayerSource,
      66                 :            :                      const QString &referencedLayerProviderKey,
      67                 :            :                      const QList<QgsRelation::FieldPair> &fieldPairs
      68                 :            :                    );
      69                 :            : 
      70                 :            :     /**
      71                 :            :      * Resolves a weak relation in the given \a project returning a possibly invalid QgsRelation
      72                 :            :      * and without performing any kind of validity check.
      73                 :            :      *
      74                 :            :      * \note Client code should never assume that the returned relation is valid and the
      75                 :            :      * layer components are not NULL.
      76                 :            :      */
      77                 :            :     QgsRelation resolvedRelation( const QgsProject *project, QgsVectorLayerRef::MatchType matchType = QgsVectorLayerRef::MatchType::All ) const;
      78                 :            : 
      79                 :            :     /**
      80                 :            :      * Returns a weak reference to the referencing layer
      81                 :            :      */
      82                 :            :     QgsVectorLayerRef referencingLayer() const;
      83                 :            : 
      84                 :            :     /**
      85                 :            :      * Returns a weak reference to the referenced layer
      86                 :            :      */
      87                 :            :     QgsVectorLayerRef referencedLayer() const;
      88                 :            : 
      89                 :            :     /**
      90                 :            :      * Returns the strength of the relation
      91                 :            :      */
      92                 :            :     QgsRelation::RelationStrength strength() const;
      93                 :            : 
      94                 :            :     /**
      95                 :            :      * Returns the list of field pairs
      96                 :            :      */
      97                 :            :     QList<QgsRelation::FieldPair> fieldPairs() const;
      98                 :            : 
      99                 :            :     /**
     100                 :            :      * Returns a weak relation for the given layer
     101                 :            :      * \param layer the layer of the weak relation
     102                 :            :      * \param type determines if the layer is referencing or referenced
     103                 :            :      * \param node the QDomNode
     104                 :            :      * \param resolver the path resolver
     105                 :            :      * \since QGIS 3.16
     106                 :            :      */
     107                 :            :     static QgsWeakRelation readXml( const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver );
     108                 :            : 
     109                 :            :     /**
     110                 :            :      * Writes a weak relation infoto an XML structure. Used for saving .qgs projects
     111                 :            :      *
     112                 :            :      * \param layer the layer which we save the weak relation for
     113                 :            :      * \param type determines if the layer is referencing or referenced
     114                 :            :      * \param relation the relation to save as a weak relation
     115                 :            :      * \param node The parent node in which the relation will be created
     116                 :            :      * \param doc  The document in which the relation will be saved
     117                 :            :      * \since QGIS 3.16
     118                 :            :      */
     119                 :            :     static void writeXml( const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc );
     120                 :            : 
     121                 :            :   private:
     122                 :            : 
     123                 :            :     QgsVectorLayerRef mReferencingLayer;
     124                 :            :     QgsVectorLayerRef mReferencedLayer;
     125                 :            :     QString mRelationId;
     126                 :            :     QString mRelationName;
     127                 :            :     QgsRelation::RelationStrength mStrength = QgsRelation::RelationStrength::Association;
     128                 :            :     QList<QgsRelation::FieldPair> mFieldPairs;
     129                 :            : 
     130                 :            :     friend class TestQgsWeakRelation;
     131                 :            : 
     132                 :            : };
     133                 :            : 
     134                 :            : #endif // QGSWEAKRELATION_H

Generated by: LCOV version 1.14