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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgsvectorlayerdiagramprovider.h
       3                 :            :   --------------------------------------
       4                 :            :   Date                 : September 2015
       5                 :            :   Copyright            : (C) 2015 by Martin Dobias
       6                 :            :   Email                : wonder dot sk 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                 :            : 
      16                 :            : #ifndef QGSVECTORLAYERDIAGRAMPROVIDER_H
      17                 :            : #define QGSVECTORLAYERDIAGRAMPROVIDER_H
      18                 :            : 
      19                 :            : #define SIP_NO_FILE
      20                 :            : 
      21                 :            : #include "qgis_core.h"
      22                 :            : #include "qgslabelingengine.h"
      23                 :            : #include "qgslabelfeature.h"
      24                 :            : #include "qgsdiagramrenderer.h"
      25                 :            : 
      26                 :            : /**
      27                 :            :  * \ingroup core
      28                 :            :  * \brief Class that adds extra information to QgsLabelFeature for labeling of diagrams
      29                 :            :  *
      30                 :            :  * \note this class is not a part of public API yet. See notes in QgsLabelingEngine
      31                 :            :  * \note not available in Python bindings
      32                 :            :  */
      33                 :          0 : class QgsDiagramLabelFeature : public QgsLabelFeature
      34                 :            : {
      35                 :            :   public:
      36                 :            :     //! Create label feature, takes ownership of the geometry instance
      37                 :          0 :     QgsDiagramLabelFeature( QgsFeatureId id, geos::unique_ptr geometry, QSizeF size )
      38                 :          0 :       : QgsLabelFeature( id, std::move( geometry ), size ) {}
      39                 :            : 
      40                 :            :     //! Store feature's attributes - used for rendering of diagrams
      41                 :          0 :     void setAttributes( const QgsAttributes &attrs ) { mAttributes = attrs; }
      42                 :            :     //! Gets feature's attributes - used for rendering of diagrams
      43                 :          0 :     const QgsAttributes &attributes() { return mAttributes; }
      44                 :            : 
      45                 :            :   protected:
      46                 :            :     //! Stores attribute values for diagram rendering
      47                 :            :     QgsAttributes mAttributes;
      48                 :            : };
      49                 :            : 
      50                 :            : 
      51                 :            : class QgsAbstractFeatureSource;
      52                 :            : 
      53                 :            : /**
      54                 :            :  * \ingroup core
      55                 :            :  * \brief The QgsVectorLayerDiagramProvider class implements support for diagrams within
      56                 :            :  * the labeling engine. Parameters for the diagrams are taken from the layer settings.
      57                 :            :  *
      58                 :            :  * \note this class is not a part of public API yet. See notes in QgsLabelingEngine
      59                 :            :  * \note not available in Python bindings
      60                 :            :  * \since QGIS 2.12
      61                 :            :  */
      62                 :            : class CORE_EXPORT QgsVectorLayerDiagramProvider : public QgsAbstractLabelProvider
      63                 :            : {
      64                 :            :   public:
      65                 :            : 
      66                 :            :     //! Convenience constructor to initialize the provider from given vector layer
      67                 :            :     explicit QgsVectorLayerDiagramProvider( QgsVectorLayer *layer, bool ownFeatureLoop = true );
      68                 :            : 
      69                 :            :     //! Clean up
      70                 :            :     ~QgsVectorLayerDiagramProvider() override;
      71                 :            : 
      72                 :            :     QList<QgsLabelFeature *> labelFeatures( QgsRenderContext &context ) override;
      73                 :            : 
      74                 :            :     void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
      75                 :            : 
      76                 :            :     // new virtual methods
      77                 :            : 
      78                 :            :     /**
      79                 :            :      * Prepare for registration of features. Must be called after provider has been added to engine (uses its map settings)
      80                 :            :      * \param context render context.
      81                 :            :      * \param attributeNames list of attribute names to which additional required attributes shall be added
      82                 :            :      * \returns Whether the preparation was successful - if not, the provider shall not be used
      83                 :            :      */
      84                 :            :     virtual bool prepare( const QgsRenderContext &context, QSet<QString> &attributeNames );
      85                 :            : 
      86                 :            :     /**
      87                 :            :      * Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures
      88                 :            :      *
      89                 :            :      * \param feature feature for diagram
      90                 :            :      * \param context render context. The QgsExpressionContext contained within the render context
      91                 :            :      * must have already had the feature and fields sets prior to calling this method.
      92                 :            :      * \param obstacleGeometry optional obstacle geometry, if a different geometry to the feature's geometry
      93                 :            :      * should be used as an obstacle for labels (e.g., if the feature has been rendered with an offset point
      94                 :            :      * symbol, the obstacle geometry should represent the bounds of the offset symbol). If not set,
      95                 :            :      * the feature's original geometry will be used as an obstacle for labels. Ownership of obstacleGeometry
      96                 :            :      * is transferred.
      97                 :            :      */
      98                 :            :     virtual void registerFeature( QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry = QgsGeometry() );
      99                 :            : 
     100                 :            :     /**
     101                 :            :      * Sets a \a geometry to use to clip features to when registering them as diagrams.
     102                 :            :      *
     103                 :            :      * \since QGIS 3.16
     104                 :            :      */
     105                 :            :     void setClipFeatureGeometry( const QgsGeometry &geometry );
     106                 :            : 
     107                 :            :   protected:
     108                 :            :     //! initialization method - called from constructors
     109                 :            :     void init();
     110                 :            :     //! helper method to register one diagram feature
     111                 :            :     QgsLabelFeature *registerDiagram( QgsFeature &feat, QgsRenderContext &context, const QgsGeometry &obstacleGeometry = QgsGeometry() );
     112                 :            : 
     113                 :            :   protected:
     114                 :            : 
     115                 :            :     //! Diagram layer settings
     116                 :            :     QgsDiagramLayerSettings mSettings;
     117                 :            :     //! Diagram renderer instance (owned by mSettings)
     118                 :            :     QgsDiagramRenderer *mDiagRenderer = nullptr;
     119                 :            : 
     120                 :            :     // these are needed only if using own renderer loop
     121                 :            : 
     122                 :            :     //! Layer's fields
     123                 :            :     QgsFields mFields;
     124                 :            :     //! Layer's CRS
     125                 :            :     QgsCoordinateReferenceSystem mLayerCrs;
     126                 :            :     //! Layer's feature source
     127                 :            :     QgsAbstractFeatureSource *mSource = nullptr;
     128                 :            :     //! Whether layer's feature source is owned
     129                 :            :     bool mOwnsSource;
     130                 :            : 
     131                 :            :     //! List of generated label features (owned by the provider)
     132                 :            :     QList<QgsLabelFeature *> mFeatures;
     133                 :            : 
     134                 :            :     QgsGeometry mLabelClipFeatureGeom;
     135                 :            : };
     136                 :            : 
     137                 :            : #endif // QGSVECTORLAYERDIAGRAMPROVIDER_H

Generated by: LCOV version 1.14