QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsarrowsymbollayer.h
Go to the documentation of this file.
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 class QgsFillSymbol;
24 
25 
33 class CORE_EXPORT QgsArrowSymbolLayer : public QgsLineSymbolLayer
34 {
35  public:
39 
47  static QgsSymbolLayer *create( const QVariantMap &properties = QVariantMap() ) SIP_FACTORY;
48 
49  QgsArrowSymbolLayer *clone() const override SIP_FACTORY;
50  QgsSymbol *subSymbol() override;
51  bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
52  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
53  bool hasDataDefinedProperties() const override;
54  bool usesMapUnits() const override;
55 
57  double arrowWidth() const { return mArrowWidth; }
59  void setArrowWidth( double width ) { mArrowWidth = width; }
61  QgsUnitTypes::RenderUnit arrowWidthUnit() const { return mArrowWidthUnit; }
63  void setArrowWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowWidthUnit = unit; }
65  QgsMapUnitScale arrowWidthUnitScale() const { return mArrowWidthUnitScale; }
67  void setArrowWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowWidthUnitScale = scale; }
68 
70  double arrowStartWidth() const { return mArrowStartWidth; }
72  void setArrowStartWidth( double width ) { mArrowStartWidth = width; }
74  QgsUnitTypes::RenderUnit arrowStartWidthUnit() const { return mArrowStartWidthUnit; }
76  void setArrowStartWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowStartWidthUnit = unit; }
78  QgsMapUnitScale arrowStartWidthUnitScale() const { return mArrowStartWidthUnitScale; }
80  void setArrowStartWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowStartWidthUnitScale = scale; }
81 
83  double headLength() const { return mHeadLength; }
85  void setHeadLength( double length ) { mHeadLength = length; }
87  QgsUnitTypes::RenderUnit headLengthUnit() const { return mHeadLengthUnit; }
89  void setHeadLengthUnit( QgsUnitTypes::RenderUnit unit ) { mHeadLengthUnit = unit; }
91  QgsMapUnitScale headLengthUnitScale() const { return mHeadLengthUnitScale; }
93  void setHeadLengthUnitScale( const QgsMapUnitScale &scale ) { mHeadLengthUnitScale = scale; }
94 
96  double headThickness() const { return mHeadThickness; }
98  void setHeadThickness( double thickness ) { mHeadThickness = thickness; }
100  QgsUnitTypes::RenderUnit headThicknessUnit() const { return mHeadThicknessUnit; }
102  void setHeadThicknessUnit( QgsUnitTypes::RenderUnit unit ) { mHeadThicknessUnit = unit; }
104  QgsMapUnitScale headThicknessUnitScale() const { return mHeadThicknessUnitScale; }
106  void setHeadThicknessUnitScale( const QgsMapUnitScale &scale ) { mHeadThicknessUnitScale = scale; }
107 
109  bool isCurved() const { return mIsCurved; }
111  void setIsCurved( bool isCurved ) { mIsCurved = isCurved; }
112 
114  bool isRepeated() const { return mIsRepeated; }
116  void setIsRepeated( bool isRepeated ) { mIsRepeated = isRepeated; }
117 
119  enum HeadType
120  {
121  HeadSingle, //< One single head at the end
122  HeadReversed, //< One single head at the beginning
123  HeadDouble //< Two heads
124  };
125 
127  HeadType headType() const { return mHeadType; }
129  void setHeadType( HeadType type ) { mHeadType = type; }
130 
133  {
134  ArrowPlain, //< Regular arrow
135  ArrowLeftHalf, //< Halved arrow, only the left side of the arrow is rendered (for straight arrows) or the side toward the exterior (for curved arrows)
136  ArrowRightHalf //< Halved arrow, only the right side of the arrow is rendered (for straight arrows) or the side toward the interior (for curved arrows)
137  };
138 
140  ArrowType arrowType() const { return mArrowType; }
142  void setArrowType( ArrowType type ) { mArrowType = type; }
143 
144  QVariantMap properties() const override;
145  QString layerType() const override;
146  void startRender( QgsSymbolRenderContext &context ) override;
147  void stopRender( QgsSymbolRenderContext &context ) override;
148  void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
149  void setColor( const QColor &c ) override;
150  QColor color() const override;
151  bool canCauseArtifactsBetweenAdjacentTiles() const override;
152 
153  private:
154 #ifdef SIP_RUN
156 #endif
157 
159  std::unique_ptr<QgsFillSymbol> mSymbol;
160 
161  double mArrowWidth = 1.0;
163  QgsMapUnitScale mArrowWidthUnitScale;
164 
165  double mArrowStartWidth = 1.0;
167  QgsMapUnitScale mArrowStartWidthUnitScale;
168 
169  double mHeadLength = 1.5;
171  QgsMapUnitScale mHeadLengthUnitScale;
172  double mHeadThickness = 1.5;
174  QgsMapUnitScale mHeadThicknessUnitScale;
175 
176  HeadType mHeadType = HeadSingle;
177  ArrowType mArrowType = ArrowPlain;
178  bool mIsCurved = true;
179  bool mIsRepeated = true;
180 
181  double mScaledArrowWidth = 1.0;
182  double mScaledArrowStartWidth = 1.0;
183  double mScaledHeadLength = 1.5;
184  double mScaledHeadThickness = 1.5;
185  double mScaledOffset = 0.0;
186  HeadType mComputedHeadType = HeadSingle;
187  ArrowType mComputedArrowType = ArrowPlain;
188 
189  std::unique_ptr<QgsExpressionContextScope> mExpressionScope;
190 
191  void _resolveDataDefined( QgsSymbolRenderContext & );
192 };
193 
194 #endif
195 
196 
Line symbol layer used for representing lines as arrows.
bool isCurved() const
Returns whether it is a curved arrow or a straight one.
QgsUnitTypes::RenderUnit headLengthUnit() const
Gets the unit for the head length.
ArrowType arrowType() const
Gets the current arrow type.
HeadType
Possible head types.
HeadType headType() const
Gets the current head type.
void setArrowStartWidth(double width)
Sets the arrow start width.
bool isRepeated() const
Returns whether the arrow is repeated along the line or not.
QgsUnitTypes::RenderUnit arrowWidthUnit() const
Gets the unit for the arrow width.
void setArrowWidth(double width)
Sets the arrow width.
QgsUnitTypes::RenderUnit arrowStartWidthUnit() const
Gets the unit for the arrow start width.
void setArrowType(ArrowType type)
Sets the arrow type.
void setHeadLengthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the head length.
~QgsArrowSymbolLayer() override
QgsMapUnitScale headThicknessUnitScale() const
Gets the scale for the head height.
void setIsCurved(bool isCurved)
Sets whether it is a curved arrow or a straight one.
void setHeadThickness(double thickness)
Sets the arrow head height.
void setIsRepeated(bool isRepeated)
Sets whether the arrow is repeated along the line.
double arrowStartWidth() const
Gets current arrow start width. Only meaningful for single headed arrows.
QgsUnitTypes::RenderUnit headThicknessUnit() const
Gets the unit for the head height.
void setArrowStartWidthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the arrow start width.
void setHeadThicknessUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the head height.
void setHeadType(HeadType type)
Sets the head type.
QgsMapUnitScale arrowStartWidthUnitScale() const
Gets the scale for the arrow start width.
double headThickness() const
Gets the current arrow head height.
void setArrowWidthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the arrow width.
ArrowType
Possible arrow types.
void setArrowWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the arrow width.
QgsMapUnitScale arrowWidthUnitScale() const
Gets the scale for the arrow width.
void setArrowStartWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the arrow start width.
void setHeadLengthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the head length.
void setHeadThicknessUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the head height.
QgsMapUnitScale headLengthUnitScale() const
Gets the scale for the head length.
void setHeadLength(double length)
Sets the arrow head length.
double headLength() const
Gets the current arrow head length.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:30
virtual void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context)=0
Renders the line symbol layer along the line joining points, using the given render context.
virtual double width() const
Returns the estimated width for the line symbol layer.
Struct for storing maximum and minimum scales for measurements in map units.
Contains information about the context of a rendering operation.
Qgis::SymbolType type() const
virtual QColor color() const
The fill color.
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
virtual QVariantMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
virtual QString layerType() const =0
Returns a string that represents this layer type.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
virtual bool canCauseArtifactsBetweenAdjacentTiles() const
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
virtual void setColor(const QColor &color)
The fill color.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76