QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgslinesymbollayerv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslinesymbollayerv2.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 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 QGSLINESYMBOLLAYERV2_H
17 #define QGSLINESYMBOLLAYERV2_H
18 
19 #include "qgssymbollayerv2.h"
20 
21 #include <QPen>
22 #include <QVector>
23 
24 class QgsExpression;
25 
26 #define DEFAULT_SIMPLELINE_COLOR QColor(0,0,0)
27 #define DEFAULT_SIMPLELINE_WIDTH DEFAULT_LINE_WIDTH
28 #define DEFAULT_SIMPLELINE_PENSTYLE Qt::SolidLine
29 #define DEFAULT_SIMPLELINE_JOINSTYLE Qt::BevelJoin
30 #define DEFAULT_SIMPLELINE_CAPSTYLE Qt::SquareCap
31 
36 {
37  public:
39  double width = DEFAULT_SIMPLELINE_WIDTH,
40  Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE );
41 
42  // static stuff
43 
44  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
45  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
46 
47  // implemented from base classes
48 
49  QString layerType() const override;
50 
51  void startRender( QgsSymbolV2RenderContext& context ) override;
52 
53  void stopRender( QgsSymbolV2RenderContext& context ) override;
54 
55  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;
56 
57  //overridden so that clip path can be set when using draw inside polygon option
58  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) override;
59 
60  QgsStringMap properties() const override;
61 
62  QgsSimpleLineSymbolLayerV2* clone() const override;
63 
65  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
66 
67  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
68 
69  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
70  QgsSymbolV2::OutputUnit outputUnit() const override;
71 
72  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
73  QgsMapUnitScale mapUnitScale() const override;
74 
75  double estimateMaxBleed() const override;
76 
77  // new stuff
78 
79  Qt::PenStyle penStyle() const { return mPenStyle; }
80  void setPenStyle( Qt::PenStyle style ) { mPenStyle = style; }
81 
82  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
83  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
84 
85  Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
86  void setPenCapStyle( Qt::PenCapStyle style ) { mPenCapStyle = style; }
87 
88  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
89  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
90 
91  void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
92  QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
93 
94  const QgsMapUnitScale& customDashPatternMapUnitScale() const { return mCustomDashPatternMapUnitScale; }
95  void setCustomDashPatternMapUnitScale( const QgsMapUnitScale& scale ) { mCustomDashPatternMapUnitScale = scale; }
96 
97  QVector<qreal> customDashVector() const { return mCustomDashVector; }
98  void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
99 
100  //Returns true if the line should only be drawn inside the polygon
101  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
102  //Set to true if the line should only be drawn inside the polygon
103  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
104 
106  Qt::PenStyle dxfPenStyle() const override;
107 
108  double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext &context ) const override;
109  double dxfOffset( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const override;
110  QColor dxfColor( QgsSymbolV2RenderContext &context ) const override;
111 
112  protected:
113  Qt::PenStyle mPenStyle;
114  Qt::PenJoinStyle mPenJoinStyle;
115  Qt::PenCapStyle mPenCapStyle;
118 
119  //use a custom dash dot pattern instead of the predefined ones
123 
126 
128 
129  private:
130  //helper functions for data defined symbology
131  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset );
132  void applySizeScale( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen );
133 };
134 
136 
137 #define DEFAULT_MARKERLINE_ROTATE true
138 #define DEFAULT_MARKERLINE_INTERVAL 3
139 
144 {
145  public:
147  double interval = DEFAULT_MARKERLINE_INTERVAL );
148 
150 
155  {
161  CurvePoint
162  };
163 
164  // static stuff
165 
173  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
174 
182  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
183 
184  // implemented from base classes
185 
186  QString layerType() const override;
187 
188  void startRender( QgsSymbolV2RenderContext& context ) override;
189 
190  void stopRender( QgsSymbolV2RenderContext& context ) override;
191 
192  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;
193 
194  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) override;
195 
196  QgsStringMap properties() const override;
197 
198  QgsMarkerLineSymbolLayerV2* clone() const override;
199 
201  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
202 
203  void setColor( const QColor& color ) override;
204  virtual QColor color() const override;
205 
206  QgsSymbolV2* subSymbol() override;
207  bool setSubSymbol( QgsSymbolV2* symbol ) override;
208 
209  virtual void setWidth( double width ) override;
210  virtual double width() const override;
211 
212  double estimateMaxBleed() const override;
213 
214  // new stuff
215 
221  bool rotateMarker() const { return mRotateMarker; }
222 
226  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
227 
231  double interval() const { return mInterval; }
232 
236  void setInterval( double interval ) { mInterval = interval; }
237 
241  Placement placement() const { return mPlacement; }
242 
246  void setPlacement( Placement p ) { mPlacement = p; }
247 
258  double offsetAlongLine() const { return mOffsetAlongLine; }
259 
271  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
272 
278  QgsSymbolV2::OutputUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
279 
285  void setOffsetAlongLineUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetAlongLineUnit = unit; }
286 
290  const QgsMapUnitScale& offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
291 
295  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetAlongLineMapUnitScale = scale; }
296 
297  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
298  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
299 
300  void setIntervalMapUnitScale( const QgsMapUnitScale& scale ) { mIntervalMapUnitScale = scale; }
301  const QgsMapUnitScale& intervalMapUnitScale() const { return mIntervalMapUnitScale; }
302 
303  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
304  QgsSymbolV2::OutputUnit outputUnit() const override;
305 
306  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
307  QgsMapUnitScale mapUnitScale() const override;
308 
309  QSet<QString> usedAttributes() const override;
310 
311  void setDataDefinedProperty( const QString& property, QgsDataDefined* dataDefined ) override;
312 
313 
314  protected:
315 
316  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
317  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
318  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
319  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
320 
322  double mInterval;
327  double mOffsetAlongLine; //distance to offset along line before marker is drawn
328  QgsSymbolV2::OutputUnit mOffsetAlongLineUnit; //unit for offset along line
330 
331  private:
332 
343  void renderOffsetVertexAlongLine( const QPolygonF& points, int vertex, double distance, QgsSymbolV2RenderContext &context );
344 };
345 
346 #endif
347 
348 
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
Class for parsing and evaluation of expressions (formerly called "search strings").
Qt::PenCapStyle penCapStyle() const
#define DEFAULT_SIMPLELINE_PENSTYLE
#define DEFAULT_MARKERLINE_ROTATE
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:65
Placement placement() const
The placement of the markers.
virtual QgsSymbolLayerV2 * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
A container class for data source field mapping or expression.
virtual Qt::PenStyle dxfPenStyle() const
get pen style
Qt::PenJoinStyle penJoinStyle() const
virtual QColor dxfColor(QgsSymbolV2RenderContext &context) const
get color
#define DEFAULT_MARKERLINE_INTERVAL
virtual QSet< QString > usedAttributes() const
Returns the set of attributes referenced by the layer.
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
Placement
Defines how/where the marker should be placed on the line.
QgsMapUnitScale mCustomDashPatternMapUnitScale
Qt::PenStyle penStyle() const
QgsSymbolV2::OutputUnit outputUnit() const override
void setPenJoinStyle(Qt::PenJoinStyle style)
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
QMap< QString, QString > QgsStringMap
Definition: qgis.h:492
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
Writes the SLD element following the SLD v1.1 specs.
QgsMapUnitScale mOffsetAlongLineMapUnitScale
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for markers...
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the marker placement.
virtual void startRender(QgsSymbolV2RenderContext &context)=0
void setInterval(double interval)
The interval between individual markers.
void setDrawInsidePolygon(bool drawInsidePolygon)
void setRotateMarker(bool rotate)
Shall the marker be rotated.
virtual double width() const
QgsSymbolV2::OutputUnit mIntervalUnit
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
QgsSymbolV2::OutputUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
const QgsMapUnitScale & intervalMapUnitScale() const
double interval() const
The interval between individual markers.
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
QVector< qreal > mCustomDashVector
Vector with an even number of entries for the.
#define DEFAULT_SIMPLELINE_WIDTH
virtual void setWidth(double width)
virtual QgsStringMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QVector< qreal > customDashVector() const
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for markers...
virtual QVector< qreal > dxfCustomDashPattern(QgsSymbolV2::OutputUnit &unit) const
get dash pattern
virtual void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)
const QgsMapUnitScale & customDashPatternMapUnitScale() const
void setOffsetAlongLineUnit(QgsSymbolV2::OutputUnit unit)
Sets the unit used for calculating the offset along line for markers.
virtual QColor color() const
The fill color.
void setPenCapStyle(Qt::PenCapStyle style)
void setCustomDashVector(const QVector< qreal > &vector)
virtual void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context)=0
QgsSymbolV2::OutputUnit mCustomDashPatternUnit
virtual QString layerType() const =0
Returns a string that represents this layer type.
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const
get offset
QgsSymbolV2::OutputUnit intervalUnit() const
virtual QgsSymbolV2 * subSymbol()
#define DEFAULT_SIMPLELINE_COLOR
QgsMapUnitScale mapUnitScale() const override
QgsSymbolV2::OutputUnit mOffsetAlongLineUnit
void setPenStyle(Qt::PenStyle style)
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setPlacement(Placement p)
The placement of the markers.
Struct for storing maximum and minimum scales for measurements in map units.
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
virtual void setColor(const QColor &color)
The fill color.
QgsSymbolV2::OutputUnit customDashPatternUnit() const
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const override
get line width
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
set layer&#39;s subsymbol. takes ownership of the passed symbol
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
bool rotateMarker() const
Shall the marker be rotated.
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
virtual Q_DECL_DEPRECATED void setDataDefinedProperty(const QString &property, const QString &expressionString)
Sets a data defined expression for a property.