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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :  qgsarrowsymbollayer.h
       3                 :            :  ---------------------
       4                 :            :  begin                : January 2016
       5                 :            :  copyright            : (C) 2016 by Hugo Mercier
       6                 :            :  email                : hugo dot mercier at oslandia 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 QGSARROWSYMBOLLAYER_H
      17                 :            : #define QGSARROWSYMBOLLAYER_H
      18                 :            : 
      19                 :            : #include "qgis_core.h"
      20                 :            : #include "qgis.h"
      21                 :            : #include "qgssymbollayer.h"
      22                 :            : 
      23                 :            : 
      24                 :            : /**
      25                 :            :  * \ingroup core
      26                 :            :  * \class QgsArrowSymbolLayer
      27                 :            :  * \brief Line symbol layer used for representing lines as arrows.
      28                 :            :  * \since QGIS 2.16
      29                 :            :  */
      30                 :            : 
      31                 :          6 : class CORE_EXPORT QgsArrowSymbolLayer : public QgsLineSymbolLayer
      32                 :            : {
      33                 :            :   public:
      34                 :            :     //! Simple constructor
      35                 :            :     QgsArrowSymbolLayer();
      36                 :            : 
      37                 :            :     /**
      38                 :            :      * Create a new QgsArrowSymbolLayer
      39                 :            :      *
      40                 :            :      * \param properties A property map to deserialize saved information from properties()
      41                 :            :      *
      42                 :            :      * \returns A new QgsArrowSymbolLayer
      43                 :            :      */
      44                 :            :     static QgsSymbolLayer *create( const QVariantMap &properties = QVariantMap() ) SIP_FACTORY;
      45                 :            : 
      46                 :            :     QgsArrowSymbolLayer *clone() const override SIP_FACTORY;
      47                 :          0 :     QgsSymbol *subSymbol() override { return mSymbol.get(); }
      48                 :            :     bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
      49                 :            :     QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
      50                 :            :     bool hasDataDefinedProperties() const override;
      51                 :            :     bool usesMapUnits() const override;
      52                 :            : 
      53                 :            :     //! Gets current arrow width
      54                 :          0 :     double arrowWidth() const { return mArrowWidth; }
      55                 :            :     //! Sets the arrow width
      56                 :          5 :     void setArrowWidth( double width ) { mArrowWidth = width; }
      57                 :            :     //! Gets the unit for the arrow width
      58                 :          0 :     QgsUnitTypes::RenderUnit arrowWidthUnit() const { return mArrowWidthUnit; }
      59                 :            :     //! Sets the unit for the arrow width
      60                 :          5 :     void setArrowWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowWidthUnit = unit; }
      61                 :            :     //! Gets the scale for the arrow width
      62                 :          0 :     QgsMapUnitScale arrowWidthUnitScale() const { return mArrowWidthUnitScale; }
      63                 :            :     //! Sets the scale for the arrow width
      64                 :          5 :     void setArrowWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowWidthUnitScale = scale; }
      65                 :            : 
      66                 :            :     //! Gets current arrow start width. Only meaningful for single headed arrows
      67                 :          0 :     double arrowStartWidth() const { return mArrowStartWidth; }
      68                 :            :     //! Sets the arrow start width
      69                 :          5 :     void setArrowStartWidth( double width ) { mArrowStartWidth = width; }
      70                 :            :     //! Gets the unit for the arrow start width
      71                 :          0 :     QgsUnitTypes::RenderUnit arrowStartWidthUnit() const { return mArrowStartWidthUnit; }
      72                 :            :     //! Sets the unit for the arrow start width
      73                 :          5 :     void setArrowStartWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowStartWidthUnit = unit; }
      74                 :            :     //! Gets the scale for the arrow start width
      75                 :          0 :     QgsMapUnitScale arrowStartWidthUnitScale() const { return mArrowStartWidthUnitScale; }
      76                 :            :     //! Sets the scale for the arrow start width
      77                 :          5 :     void setArrowStartWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowStartWidthUnitScale = scale; }
      78                 :            : 
      79                 :            :     //! Gets the current arrow head length
      80                 :          0 :     double headLength() const { return mHeadLength; }
      81                 :            :     //! Sets the arrow head length
      82                 :          5 :     void setHeadLength( double length ) { mHeadLength = length; }
      83                 :            :     //! Gets the unit for the head length
      84                 :          0 :     QgsUnitTypes::RenderUnit headLengthUnit() const { return mHeadLengthUnit; }
      85                 :            :     //! Sets the unit for the head length
      86                 :          5 :     void setHeadLengthUnit( QgsUnitTypes::RenderUnit unit ) { mHeadLengthUnit = unit; }
      87                 :            :     //! Gets the scale for the head length
      88                 :          0 :     QgsMapUnitScale headLengthUnitScale() const { return mHeadLengthUnitScale; }
      89                 :            :     //! Sets the scale for the head length
      90                 :          5 :     void setHeadLengthUnitScale( const QgsMapUnitScale &scale ) { mHeadLengthUnitScale = scale; }
      91                 :            : 
      92                 :            :     //! Gets the current arrow head height
      93                 :          0 :     double headThickness() const { return mHeadThickness; }
      94                 :            :     //! Sets the arrow head height
      95                 :          5 :     void setHeadThickness( double thickness ) { mHeadThickness = thickness; }
      96                 :            :     //! Gets the unit for the head height
      97                 :          0 :     QgsUnitTypes::RenderUnit headThicknessUnit() const { return mHeadThicknessUnit; }
      98                 :            :     //! Sets the unit for the head height
      99                 :          5 :     void setHeadThicknessUnit( QgsUnitTypes::RenderUnit unit ) { mHeadThicknessUnit = unit; }
     100                 :            :     //! Gets the scale for the head height
     101                 :          0 :     QgsMapUnitScale headThicknessUnitScale() const { return mHeadThicknessUnitScale; }
     102                 :            :     //! Sets the scale for the head height
     103                 :          5 :     void setHeadThicknessUnitScale( const QgsMapUnitScale &scale ) { mHeadThicknessUnitScale = scale; }
     104                 :            : 
     105                 :            :     //! Returns whether it is a curved arrow or a straight one
     106                 :          0 :     bool isCurved() const { return mIsCurved; }
     107                 :            :     //! Sets whether it is a curved arrow or a straight one
     108                 :          5 :     void setIsCurved( bool isCurved ) { mIsCurved = isCurved; }
     109                 :            : 
     110                 :            :     //! Returns whether the arrow is repeated along the line or not
     111                 :          0 :     bool isRepeated() const { return mIsRepeated; }
     112                 :            :     //! Sets whether the arrow is repeated along the line
     113                 :          5 :     void setIsRepeated( bool isRepeated ) { mIsRepeated = isRepeated; }
     114                 :            : 
     115                 :            :     //! Possible head types
     116                 :            :     enum HeadType
     117                 :            :     {
     118                 :            :       HeadSingle,   //< One single head at the end
     119                 :            :       HeadReversed, //< One single head at the beginning
     120                 :            :       HeadDouble    //< Two heads
     121                 :            :     };
     122                 :            : 
     123                 :            :     //! Gets the current head type
     124                 :          0 :     HeadType headType() const { return mHeadType; }
     125                 :            :     //! Sets the head type
     126                 :          5 :     void setHeadType( HeadType type ) { mHeadType = type; }
     127                 :            : 
     128                 :            :     //! Possible arrow types
     129                 :            :     enum ArrowType
     130                 :            :     {
     131                 :            :       ArrowPlain,     //< Regular arrow
     132                 :            :       ArrowLeftHalf,  //< Halved arrow, only the left side of the arrow is rendered (for straight arrows) or the side toward the exterior (for curved arrows)
     133                 :            :       ArrowRightHalf  //< Halved arrow, only the right side of the arrow is rendered (for straight arrows) or the side toward the interior (for curved arrows)
     134                 :            :     };
     135                 :            : 
     136                 :            :     //! Gets the current arrow type
     137                 :          0 :     ArrowType arrowType() const { return mArrowType; }
     138                 :            :     //! Sets the arrow type
     139                 :          5 :     void setArrowType( ArrowType type ) { mArrowType = type; }
     140                 :            : 
     141                 :            :     QVariantMap properties() const override;
     142                 :            :     QString layerType() const override;
     143                 :            :     void startRender( QgsSymbolRenderContext &context ) override;
     144                 :            :     void stopRender( QgsSymbolRenderContext &context ) override;
     145                 :            :     void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
     146                 :            :     void setColor( const QColor &c ) override;
     147                 :            :     QColor color() const override;
     148                 :            :     bool canCauseArtifactsBetweenAdjacentTiles() const override;
     149                 :            : 
     150                 :            :   private:
     151                 :            : #ifdef SIP_RUN
     152                 :            :     QgsArrowSymbolLayer( const QgsArrowSymbolLayer & );
     153                 :            : #endif
     154                 :            : 
     155                 :            :     //! Filling sub symbol
     156                 :            :     std::unique_ptr<QgsFillSymbol> mSymbol;
     157                 :            : 
     158                 :            :     double mArrowWidth = 1.0;
     159                 :            :     QgsUnitTypes::RenderUnit mArrowWidthUnit = QgsUnitTypes::RenderMillimeters;
     160                 :            :     QgsMapUnitScale mArrowWidthUnitScale;
     161                 :            : 
     162                 :            :     double mArrowStartWidth = 1.0;
     163                 :            :     QgsUnitTypes::RenderUnit mArrowStartWidthUnit = QgsUnitTypes::RenderMillimeters;
     164                 :            :     QgsMapUnitScale mArrowStartWidthUnitScale;
     165                 :            : 
     166                 :            :     double mHeadLength = 1.5;
     167                 :            :     QgsUnitTypes::RenderUnit mHeadLengthUnit = QgsUnitTypes::RenderMillimeters;
     168                 :            :     QgsMapUnitScale mHeadLengthUnitScale;
     169                 :            :     double mHeadThickness = 1.5;
     170                 :            :     QgsUnitTypes::RenderUnit mHeadThicknessUnit = QgsUnitTypes::RenderMillimeters;
     171                 :            :     QgsMapUnitScale mHeadThicknessUnitScale;
     172                 :            : 
     173                 :            :     HeadType mHeadType = HeadSingle;
     174                 :            :     ArrowType mArrowType = ArrowPlain;
     175                 :            :     bool mIsCurved = true;
     176                 :            :     bool mIsRepeated = true;
     177                 :            : 
     178                 :            :     double mScaledArrowWidth = 1.0;
     179                 :            :     double mScaledArrowStartWidth = 1.0;
     180                 :            :     double mScaledHeadLength = 1.5;
     181                 :            :     double mScaledHeadThickness = 1.5;
     182                 :            :     double mScaledOffset = 0.0;
     183                 :            :     HeadType mComputedHeadType = HeadSingle;
     184                 :            :     ArrowType mComputedArrowType = ArrowPlain;
     185                 :            : 
     186                 :            :     std::unique_ptr<QgsExpressionContextScope> mExpressionScope;
     187                 :            : 
     188                 :            :     void _resolveDataDefined( QgsSymbolRenderContext & );
     189                 :            : };
     190                 :            : 
     191                 :            : #endif
     192                 :            : 
     193                 :            : 

Generated by: LCOV version 1.14