QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
31 class CORE_EXPORT QgsArrowSymbolLayer : public QgsLineSymbolLayer
32 {
33  public:
36 
44  static QgsSymbolLayer *create( const QVariantMap &properties = QVariantMap() ) SIP_FACTORY;
45 
46  QgsArrowSymbolLayer *clone() const override SIP_FACTORY;
47  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 
54  double arrowWidth() const { return mArrowWidth; }
56  void setArrowWidth( double width ) { mArrowWidth = width; }
58  QgsUnitTypes::RenderUnit arrowWidthUnit() const { return mArrowWidthUnit; }
60  void setArrowWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowWidthUnit = unit; }
62  QgsMapUnitScale arrowWidthUnitScale() const { return mArrowWidthUnitScale; }
64  void setArrowWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowWidthUnitScale = scale; }
65 
67  double arrowStartWidth() const { return mArrowStartWidth; }
69  void setArrowStartWidth( double width ) { mArrowStartWidth = width; }
71  QgsUnitTypes::RenderUnit arrowStartWidthUnit() const { return mArrowStartWidthUnit; }
73  void setArrowStartWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowStartWidthUnit = unit; }
75  QgsMapUnitScale arrowStartWidthUnitScale() const { return mArrowStartWidthUnitScale; }
77  void setArrowStartWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowStartWidthUnitScale = scale; }
78 
80  double headLength() const { return mHeadLength; }
82  void setHeadLength( double length ) { mHeadLength = length; }
84  QgsUnitTypes::RenderUnit headLengthUnit() const { return mHeadLengthUnit; }
86  void setHeadLengthUnit( QgsUnitTypes::RenderUnit unit ) { mHeadLengthUnit = unit; }
88  QgsMapUnitScale headLengthUnitScale() const { return mHeadLengthUnitScale; }
90  void setHeadLengthUnitScale( const QgsMapUnitScale &scale ) { mHeadLengthUnitScale = scale; }
91 
93  double headThickness() const { return mHeadThickness; }
95  void setHeadThickness( double thickness ) { mHeadThickness = thickness; }
97  QgsUnitTypes::RenderUnit headThicknessUnit() const { return mHeadThicknessUnit; }
99  void setHeadThicknessUnit( QgsUnitTypes::RenderUnit unit ) { mHeadThicknessUnit = unit; }
101  QgsMapUnitScale headThicknessUnitScale() const { return mHeadThicknessUnitScale; }
103  void setHeadThicknessUnitScale( const QgsMapUnitScale &scale ) { mHeadThicknessUnitScale = scale; }
104 
106  bool isCurved() const { return mIsCurved; }
108  void setIsCurved( bool isCurved ) { mIsCurved = isCurved; }
109 
111  bool isRepeated() const { return mIsRepeated; }
113  void setIsRepeated( bool isRepeated ) { mIsRepeated = isRepeated; }
114 
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 
124  HeadType headType() const { return mHeadType; }
126  void setHeadType( HeadType type ) { mHeadType = type; }
127 
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 
137  ArrowType arrowType() const { return mArrowType; }
139  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
153 #endif
154 
156  std::unique_ptr<QgsFillSymbol> mSymbol;
157 
158  double mArrowWidth = 1.0;
160  QgsMapUnitScale mArrowWidthUnitScale;
161 
162  double mArrowStartWidth = 1.0;
164  QgsMapUnitScale mArrowStartWidthUnitScale;
165 
166  double mHeadLength = 1.5;
168  QgsMapUnitScale mHeadLengthUnitScale;
169  double mHeadThickness = 1.5;
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 
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.
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.
double arrowWidth() const
Gets current 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.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
void setHeadLength(double length)
Sets the arrow head length.
double headLength() const
Gets the current arrow head length.
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.
virtual QColor color() const
The fill color.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
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.
QgsSymbol::SymbolType type() const
virtual bool canCauseArtifactsBetweenAdjacentTiles() const
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
virtual bool usesMapUnits() const
Returns true if the symbol layer has any components which use map unit based sizes.
virtual void setColor(const QColor &color)
The fill color.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:65
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
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