LCOV - code coverage report
Current view: top level - core/symbology - qgsmergedfeaturerenderer.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 9 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :     qgsmergedfeaturerenderer.h
       3                 :            :     ---------------------
       4                 :            :     begin                : December 2020
       5                 :            :     copyright            : (C) 2020 by Nyall Dawson
       6                 :            :     email                : nyall dot dawson 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 QGSMERGEDFEATURERENDERER_H
      16                 :            : #define QGSMERGEDFEATURERENDERER_H
      17                 :            : 
      18                 :            : #include "qgis_core.h"
      19                 :            : #include "qgis_sip.h"
      20                 :            : #include "qgis.h"
      21                 :            : #include "qgsrenderer.h"
      22                 :            : #include "qgsexpression.h"
      23                 :            : #include "qgsfeature.h"
      24                 :            : #include "qgsgeometry.h"
      25                 :            : 
      26                 :            : /**
      27                 :            :  * \ingroup core
      28                 :            :  * \brief QgsMergedFeatureRenderer is a polygon or line-only feature renderer used to
      29                 :            :  * renderer a set of features merged (or dissolved) into a single geometry.
      30                 :            :  *
      31                 :            :  * It is designed on top of another feature renderer, which is called "embedded"
      32                 :            :  * Most of the methods are then only proxies to the embedded renderer. E.g. if
      33                 :            :  * the embedded renderer is a categorized renderer, then all the matching features
      34                 :            :  * for each categorized class will be dissolved together. Features from different
      35                 :            :  * classes will NOT be dissolved together.
      36                 :            :  *
      37                 :            :  * \since QGIS 3.18
      38                 :            :  */
      39                 :          0 : class CORE_EXPORT QgsMergedFeatureRenderer : public QgsFeatureRenderer
      40                 :            : {
      41                 :            :   public:
      42                 :            : 
      43                 :            :     /**
      44                 :            :      * Constructor for QgsMergedFeatureRenderer.
      45                 :            :      * \param embeddedRenderer optional embeddedRenderer. Ownership will be transferred.
      46                 :            :      */
      47                 :            :     QgsMergedFeatureRenderer( QgsFeatureRenderer *embeddedRenderer SIP_TRANSFER );
      48                 :            : 
      49                 :            :     //! Direct copies are forbidden. Use clone() instead.
      50                 :            :     QgsMergedFeatureRenderer( const QgsMergedFeatureRenderer & ) = delete;
      51                 :            :     //! Direct copies are forbidden. Use clone() instead.
      52                 :            :     QgsMergedFeatureRenderer &operator=( const QgsMergedFeatureRenderer & ) = delete;
      53                 :            : 
      54                 :            :     //! Creates a renderer out of an XML, for loading
      55                 :            :     static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
      56                 :            : 
      57                 :            :     QgsMergedFeatureRenderer *clone() const override SIP_FACTORY;
      58                 :            :     void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
      59                 :            : 
      60                 :            :     /**
      61                 :            :      * Renders a given feature.
      62                 :            :      * This will here collect features. The actual rendering will be postponed to stopRender()
      63                 :            :      * \param feature the feature to render
      64                 :            :      * \param context the rendering context
      65                 :            :      * \param layer the symbol layer to render, if that makes sense
      66                 :            :      * \param selected whether this feature has been selected (this will add decorations)
      67                 :            :      * \param drawVertexMarker whether this feature has vertex markers (in edit mode usually)
      68                 :            :      * \returns TRUE if the rendering was OK
      69                 :            :      */
      70                 :            :     bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
      71                 :            : 
      72                 :            :     /**
      73                 :            :      * The actual rendering will take place here.
      74                 :            :      * Features collected during renderFeature() are rendered using the embedded feature renderer
      75                 :            :      */
      76                 :            :     void stopRender( QgsRenderContext &context ) override;
      77                 :            : 
      78                 :            :     QString dump() const override;
      79                 :            :     QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
      80                 :            :     bool filterNeedsGeometry() const override;
      81                 :            :     QgsFeatureRenderer::Capabilities capabilities() override;
      82                 :            :     QgsSymbolList symbols( QgsRenderContext &context ) const override;
      83                 :            :     QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
      84                 :            :     QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
      85                 :            :     QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
      86                 :            :     QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
      87                 :            :     QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
      88                 :            :     QgsLegendSymbolList legendSymbolItems() const override;
      89                 :            :     bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
      90                 :            :     QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
      91                 :            :     void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) override;
      92                 :            :     const QgsFeatureRenderer *embeddedRenderer() const override;
      93                 :            :     void setLegendSymbolItem( const QString &key, QgsSymbol *symbol ) override;
      94                 :            :     bool legendSymbolItemsCheckable() const override;
      95                 :            :     bool legendSymbolItemChecked( const QString &key ) override;
      96                 :            :     void checkLegendSymbolItem( const QString &key, bool state = true ) override;
      97                 :            :     bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
      98                 :            : 
      99                 :            :     /**
     100                 :            :      * Creates a QgsMergedFeatureRenderer by a conversion from an existing renderer.
     101                 :            :      * \returns a new renderer if the conversion was possible, otherwise NULLPTR.
     102                 :            :      */
     103                 :            :     static QgsMergedFeatureRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
     104                 :            : 
     105                 :            :   protected:
     106                 :            : 
     107                 :            :     /**
     108                 :            :      * Constructor for QgsMergedFeatureRenderer.
     109                 :            :      * \param type renderer ID string
     110                 :            :      * \param embeddedRenderer optional embeddedRenderer. Ownership will be transferred.
     111                 :            :      */
     112                 :            :     QgsMergedFeatureRenderer( const QString &type, QgsFeatureRenderer *embeddedRenderer SIP_TRANSFER );
     113                 :            : 
     114                 :            :     /**
     115                 :            :      * Operations to apply to collected geometries prior to rendering.
     116                 :            :      */
     117                 :            :     enum GeometryOperation
     118                 :            :     {
     119                 :            :       Merge, //!< Merge features (union/dissolve)
     120                 :            :       InvertOnly, //!< Invert features only (polygons only)
     121                 :            :       MergeAndInvert, //!< Merge and invert features (polygons only)
     122                 :            :     };
     123                 :            : 
     124                 :            :     //! Operation to apply to collected geometries
     125                 :            :     GeometryOperation mOperation = Merge;
     126                 :            : 
     127                 :            :     //! Embedded renderer
     128                 :            :     std::unique_ptr<QgsFeatureRenderer> mSubRenderer;
     129                 :            : 
     130                 :            :   private:
     131                 :            : 
     132                 :            :     //! Structure where the reversed geometry is built during renderFeature
     133                 :          0 :     struct CombinedFeature
     134                 :            :     {
     135                 :            :       QVector<QgsGeometry> geometries; //< list of geometries
     136                 :            :       QgsFeature feature;             //< one feature (for attriute-based rendering)
     137                 :            :     };
     138                 :            :     typedef QVector<CombinedFeature> FeatureCategoryVector;
     139                 :            :     //! Where features are stored, based on the index of their symbol category \see mSymbolCategories
     140                 :            :     FeatureCategoryVector mFeaturesCategories;
     141                 :            : 
     142                 :            :     //! Maps a category to an index
     143                 :            :     QMap<QByteArray, int> mSymbolCategories;
     144                 :            : 
     145                 :            :     //! The polygon used as exterior ring that covers the current extent
     146                 :            :     QgsPolygonXY mExtentPolygon;
     147                 :            : 
     148                 :            :     //! The context used for rendering
     149                 :            :     QgsRenderContext mContext;
     150                 :            : 
     151                 :            :     //! Fields of each feature
     152                 :            :     QgsFields mFields;
     153                 :            : 
     154                 :            :     /**
     155                 :            :      * Class used to represent features that must be rendered
     156                 :            :      *  with decorations (selection, vertex markers)
     157                 :            :      */
     158                 :          0 :     struct FeatureDecoration
     159                 :            :     {
     160                 :            :       QgsFeature feature;
     161                 :            :       bool selected;
     162                 :            :       bool drawMarkers;
     163                 :            :       int layer;
     164                 :          0 :       FeatureDecoration( const QgsFeature &a_feature, bool a_selected, bool a_drawMarkers, int a_layer )
     165                 :          0 :         : feature( a_feature )
     166                 :          0 :         , selected( a_selected )
     167                 :          0 :         , drawMarkers( a_drawMarkers )
     168                 :          0 :         , layer( a_layer )
     169                 :          0 :       {}
     170                 :            :     };
     171                 :            :     QList<FeatureDecoration> mFeatureDecorations;
     172                 :            : 
     173                 :            : };
     174                 :            : 
     175                 :            : 
     176                 :            : #endif // QGSMERGEDFEATURERENDERER_H

Generated by: LCOV version 1.14