QGIS API Documentation  3.0.2-Girona (307d082)
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 QGSARROWSYMBOLLAYERV2_H
17 #define QGSARROWSYMBOLLAYERV2_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 QgsStringMap &properties = QgsStringMap() ) 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 
52  double arrowWidth() const { return mArrowWidth; }
54  void setArrowWidth( double width ) { mArrowWidth = width; }
56  QgsUnitTypes::RenderUnit arrowWidthUnit() const { return mArrowWidthUnit; }
58  void setArrowWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowWidthUnit = unit; }
60  QgsMapUnitScale arrowWidthUnitScale() const { return mArrowWidthUnitScale; }
62  void setArrowWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowWidthUnitScale = scale; }
63 
65  double arrowStartWidth() const { return mArrowStartWidth; }
67  void setArrowStartWidth( double width ) { mArrowStartWidth = width; }
69  QgsUnitTypes::RenderUnit arrowStartWidthUnit() const { return mArrowStartWidthUnit; }
71  void setArrowStartWidthUnit( QgsUnitTypes::RenderUnit unit ) { mArrowStartWidthUnit = unit; }
73  QgsMapUnitScale arrowStartWidthUnitScale() const { return mArrowStartWidthUnitScale; }
75  void setArrowStartWidthUnitScale( const QgsMapUnitScale &scale ) { mArrowStartWidthUnitScale = scale; }
76 
78  double headLength() const { return mHeadLength; }
80  void setHeadLength( double length ) { mHeadLength = length; }
82  QgsUnitTypes::RenderUnit headLengthUnit() const { return mHeadLengthUnit; }
84  void setHeadLengthUnit( QgsUnitTypes::RenderUnit unit ) { mHeadLengthUnit = unit; }
86  QgsMapUnitScale headLengthUnitScale() const { return mHeadLengthUnitScale; }
88  void setHeadLengthUnitScale( const QgsMapUnitScale &scale ) { mHeadLengthUnitScale = scale; }
89 
91  double headThickness() const { return mHeadThickness; }
93  void setHeadThickness( double thickness ) { mHeadThickness = thickness; }
95  QgsUnitTypes::RenderUnit headThicknessUnit() const { return mHeadThicknessUnit; }
97  void setHeadThicknessUnit( QgsUnitTypes::RenderUnit unit ) { mHeadThicknessUnit = unit; }
99  QgsMapUnitScale headThicknessUnitScale() const { return mHeadThicknessUnitScale; }
101  void setHeadThicknessUnitScale( const QgsMapUnitScale &scale ) { mHeadThicknessUnitScale = scale; }
102 
104  bool isCurved() const { return mIsCurved; }
106  void setIsCurved( bool isCurved ) { mIsCurved = isCurved; }
107 
109  bool isRepeated() const { return mIsRepeated; }
111  void setIsRepeated( bool isRepeated ) { mIsRepeated = isRepeated; }
112 
114  enum HeadType
115  {
116  HeadSingle, //< One single head at the end
117  HeadReversed, //< One single head at the beginning
118  HeadDouble //< Two heads
119  };
120 
122  HeadType headType() const { return mHeadType; }
124  void setHeadType( HeadType type ) { mHeadType = type; }
125 
128  {
129  ArrowPlain, //< Regular arrow
130  ArrowLeftHalf, //< Halved arrow, only the left side of the arrow is rendered (for straight arrows) or the side toward the exterior (for curved arrows)
131  ArrowRightHalf //< Halved arrow, only the right side of the arrow is rendered (for straight arrows) or the side toward the interior (for curved arrows)
132  };
133 
135  ArrowType arrowType() const { return mArrowType; }
137  void setArrowType( ArrowType type ) { mArrowType = type; }
138 
139  QgsStringMap properties() const override;
140  QString layerType() const override;
141  void startRender( QgsSymbolRenderContext &context ) override;
142  void stopRender( QgsSymbolRenderContext &context ) override;
143  void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
144  void setColor( const QColor &c ) override;
145  QColor color() const override;
146 
147  private:
148 #ifdef SIP_RUN
150 #endif
151 
153  std::unique_ptr<QgsFillSymbol> mSymbol;
154 
155  double mArrowWidth = 1.0;
157  QgsMapUnitScale mArrowWidthUnitScale;
158 
159  double mArrowStartWidth = 1.0;
161  QgsMapUnitScale mArrowStartWidthUnitScale;
162 
163  double mHeadLength = 1.5;
165  QgsMapUnitScale mHeadLengthUnitScale;
166  double mHeadThickness = 1.5;
168  QgsMapUnitScale mHeadThicknessUnitScale;
169 
170  HeadType mHeadType = HeadSingle;
171  ArrowType mArrowType = ArrowPlain;
172  bool mIsCurved = true;
173  bool mIsRepeated = true;
174 
175  double mScaledArrowWidth = 1.0;
176  double mScaledArrowStartWidth = 1.0;
177  double mScaledHeadLength = 1.5;
178  double mScaledHeadThickness = 1.5;
179  double mScaledOffset = 0.0;
180  HeadType mComputedHeadType = HeadSingle;
181  ArrowType mComputedArrowType = ArrowPlain;
182 
183  std::unique_ptr<QgsExpressionContextScope> mExpressionScope;
184 
185  void _resolveDataDefined( QgsSymbolRenderContext & );
186 };
187 
188 #endif
189 
190 
void setHeadThicknessUnitScale(const QgsMapUnitScale &scale)
Set the scale for the head height.
void setHeadLengthUnit(QgsUnitTypes::RenderUnit unit)
Set the unit for the head length.
QgsUnitTypes::RenderUnit headThicknessUnit() const
Get the unit for the head height.
double arrowStartWidth() const
Get current arrow start width. Only meaningful for single headed arrows.
double arrowWidth() const
Get current arrow width.
void setArrowWidthUnit(QgsUnitTypes::RenderUnit unit)
Set the unit for the arrow width.
QgsMapUnitScale arrowStartWidthUnitScale() const
Get the scale for the arrow start width.
QgsMapUnitScale headLengthUnitScale() const
Get the scale for the head length.
void setHeadThicknessUnit(QgsUnitTypes::RenderUnit unit)
Set the unit for the head height.
ArrowType arrowType() const
Get the current arrow type.
virtual QgsStringMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QMap< QString, QString > QgsStringMap
Definition: qgis.h:479
virtual double width() const
virtual void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context)=0
QgsSymbol * subSymbol() override
Returns the symbol&#39;s sub symbol, if present.
virtual void setColor(const QColor &color)
The fill color.
bool isRepeated() const
Return whether the arrow is repeated along the line or not.
virtual bool setSubSymbol(QgsSymbol *symbol)
set layer&#39;s subsymbol. takes ownership of the passed symbol
void setHeadLength(double length)
Set the arrow head length.
void setHeadThickness(double thickness)
Set the arrow head height.
QgsUnitTypes::RenderUnit arrowStartWidthUnit() const
Get the unit for the arrow start width.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
virtual QColor color() const
The fill color.
void setArrowWidth(double width)
Set the arrow width.
ArrowType
Possible arrow types.
bool isCurved() const
Return whether it is a curved arrow or a straight one.
double headLength() const
Get the current arrow head length.
void setIsRepeated(bool isRepeated)
Set whether the arrow is repeated along the line.
QgsSymbol::SymbolType type() const
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsMapUnitScale arrowWidthUnitScale() const
Get the scale for the arrow width.
QgsUnitTypes::RenderUnit arrowWidthUnit() const
Get the unit for the arrow width.
void setIsCurved(bool isCurved)
Set whether it is a curved arrow or a straight one.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
Contains information about the context of a rendering operation.
void setHeadLengthUnitScale(const QgsMapUnitScale &scale)
Set the scale for the head length.
void setArrowType(ArrowType type)
Set the arrow type.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Struct for storing maximum and minimum scales for measurements in map units.
void setArrowWidthUnitScale(const QgsMapUnitScale &scale)
Set the scale for the arrow width.
QgsUnitTypes::RenderUnit headLengthUnit() const
Get the unit for the head length.
void setHeadType(HeadType type)
Set the head type.
QgsMapUnitScale headThicknessUnitScale() const
Get the scale for the head height.
Line symbol layer used for representing lines as arrows.
HeadType
Possible head types.
void setArrowStartWidthUnit(QgsUnitTypes::RenderUnit unit)
Set the unit for the arrow start width.
HeadType headType() const
Get the current head type.
void setArrowStartWidth(double width)
Set the arrow start width.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:100
void setArrowStartWidthUnitScale(const QgsMapUnitScale &scale)
Set the scale for the arrow start width.
virtual void startRender(QgsSymbolRenderContext &context)=0
virtual QString layerType() const =0
Returns a string that represents this layer type.
double headThickness() const
Get the current arrow head height.