QGIS API Documentation  3.2.0-Bonn (bc43194)
qgslinesymbollayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslinesymbollayer.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 "qgis_core.h"
20 #include "qgis.h"
21 #include "qgssymbollayer.h"
22 
23 #include <QPen>
24 #include <QVector>
25 
26 class QgsExpression;
27 
28 #define DEFAULT_SIMPLELINE_COLOR QColor(35,35,35)
29 #define DEFAULT_SIMPLELINE_WIDTH DEFAULT_LINE_WIDTH
30 #define DEFAULT_SIMPLELINE_PENSTYLE Qt::SolidLine
31 #define DEFAULT_SIMPLELINE_JOINSTYLE Qt::BevelJoin
32 #define DEFAULT_SIMPLELINE_CAPSTYLE Qt::SquareCap
33 
38 class CORE_EXPORT QgsSimpleLineSymbolLayer : public QgsLineSymbolLayer
39 {
40  public:
42  double width = DEFAULT_SIMPLELINE_WIDTH,
43  Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE );
44 
45  // static stuff
46 
47  static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() ) SIP_FACTORY;
48  static QgsSymbolLayer *createFromSld( QDomElement &element ) SIP_FACTORY;
49 
50  // implemented from base classes
51 
52  QString layerType() const override;
53 
54  void startRender( QgsSymbolRenderContext &context ) override;
55 
56  void stopRender( QgsSymbolRenderContext &context ) override;
57 
58  void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
59 
60  //overridden so that clip path can be set when using draw inside polygon option
61  void renderPolygonStroke( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context ) override;
62 
63  QgsStringMap properties() const override;
64 
65  QgsSimpleLineSymbolLayer *clone() const override SIP_FACTORY;
66 
67  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const override;
68 
69  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
70 
71  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
72  QgsUnitTypes::RenderUnit outputUnit() const override;
73 
74  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
75  QgsMapUnitScale mapUnitScale() const override;
76 
77  double estimateMaxBleed( const QgsRenderContext &context ) const override;
78 
79  // new stuff
80 
81  Qt::PenStyle penStyle() const { return mPenStyle; }
82  void setPenStyle( Qt::PenStyle style ) { mPenStyle = style; }
83 
84  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
85  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
86 
87  Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
88  void setPenCapStyle( Qt::PenCapStyle style ) { mPenCapStyle = style; }
89 
90  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
91  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
92 
98  void setCustomDashPatternUnit( QgsUnitTypes::RenderUnit unit ) { mCustomDashPatternUnit = unit; }
99 
104  QgsUnitTypes::RenderUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
105 
106  const QgsMapUnitScale &customDashPatternMapUnitScale() const { return mCustomDashPatternMapUnitScale; }
107  void setCustomDashPatternMapUnitScale( const QgsMapUnitScale &scale ) { mCustomDashPatternMapUnitScale = scale; }
108 
109  QVector<qreal> customDashVector() const { return mCustomDashVector; }
110  void setCustomDashVector( const QVector<qreal> &vector ) { mCustomDashVector = vector; }
111 
112  //Returns true if the line should only be drawn inside the polygon
113  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
114  //Set to true if the line should only be drawn inside the polygon
115  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
116 
117  QVector<qreal> dxfCustomDashPattern( QgsUnitTypes::RenderUnit &unit ) const override;
118  Qt::PenStyle dxfPenStyle() const override;
119 
120  double dxfWidth( const QgsDxfExport &e, QgsSymbolRenderContext &context ) const override;
121  double dxfOffset( const QgsDxfExport &e, QgsSymbolRenderContext &context ) const override;
122  QColor dxfColor( QgsSymbolRenderContext &context ) const override;
123 
124  protected:
125  Qt::PenStyle mPenStyle;
126  Qt::PenJoinStyle mPenJoinStyle = DEFAULT_SIMPLELINE_JOINSTYLE;
127  Qt::PenCapStyle mPenCapStyle = DEFAULT_SIMPLELINE_CAPSTYLE;
128  QPen mPen;
129  QPen mSelPen;
130 
131  //use a custom dash dot pattern instead of the predefined ones
132  bool mUseCustomDashPattern = false;
135 
137  QVector<qreal> mCustomDashVector;
138 
139  bool mDrawInsidePolygon = false;
140 
141  private:
142  //helper functions for data defined symbology
143  void applyDataDefinedSymbology( QgsSymbolRenderContext &context, QPen &pen, QPen &selPen, double &offset );
144 };
145 
147 
148 #define DEFAULT_MARKERLINE_ROTATE true
149 #define DEFAULT_MARKERLINE_INTERVAL 3
150 
156 {
157  public:
159  double interval = DEFAULT_MARKERLINE_INTERVAL );
160 
165  {
171  CurvePoint
172  };
173 
174  // static stuff
175 
183  static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() ) SIP_FACTORY;
184 
192  static QgsSymbolLayer *createFromSld( QDomElement &element ) SIP_FACTORY;
193 
194  // implemented from base classes
195 
196  QString layerType() const override;
197 
198  void startRender( QgsSymbolRenderContext &context ) override;
199 
200  void stopRender( QgsSymbolRenderContext &context ) override;
201 
202  void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
203 
204  void renderPolygonStroke( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context ) override;
205 
206  QgsStringMap properties() const override;
207 
208  QgsMarkerLineSymbolLayer *clone() const override SIP_FACTORY;
209 
210  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const override;
211 
212  void setColor( const QColor &color ) override;
213  QColor color() const override;
214 
215  QgsSymbol *subSymbol() override;
216  bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
217 
218  void setWidth( double width ) override;
219  double width() const override;
220 
221  double estimateMaxBleed( const QgsRenderContext &context ) const override;
222 
223  // new stuff
224 
230  bool rotateMarker() const { return mRotateMarker; }
231 
235  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
236 
242  double interval() const { return mInterval; }
243 
250  void setInterval( double interval ) { mInterval = interval; }
251 
255  Placement placement() const { return mPlacement; }
256 
260  void setPlacement( Placement p ) { mPlacement = p; }
261 
273  double offsetAlongLine() const { return mOffsetAlongLine; }
274 
287  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
288 
295  QgsUnitTypes::RenderUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
296 
303  void setOffsetAlongLineUnit( QgsUnitTypes::RenderUnit unit ) { mOffsetAlongLineUnit = unit; }
304 
309  const QgsMapUnitScale &offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
310 
315  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale &scale ) { mOffsetAlongLineMapUnitScale = scale; }
316 
323  void setIntervalUnit( QgsUnitTypes::RenderUnit unit ) { mIntervalUnit = unit; }
324 
330  QgsUnitTypes::RenderUnit intervalUnit() const { return mIntervalUnit; }
331 
332  void setIntervalMapUnitScale( const QgsMapUnitScale &scale ) { mIntervalMapUnitScale = scale; }
333  const QgsMapUnitScale &intervalMapUnitScale() const { return mIntervalMapUnitScale; }
334 
335  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
336  QgsUnitTypes::RenderUnit outputUnit() const override;
337 
338  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
339  QgsMapUnitScale mapUnitScale() const override;
340 
341  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
342 
343  void setDataDefinedProperty( QgsSymbolLayer::Property key, const QgsProperty &property ) override;
344 
345 
346  protected:
347 
348  void renderPolylineInterval( const QPolygonF &points, QgsSymbolRenderContext &context );
349  void renderPolylineVertex( const QPolygonF &points, QgsSymbolRenderContext &context, Placement placement = Vertex );
350  void renderPolylineCentral( const QPolygonF &points, QgsSymbolRenderContext &context );
351  double markerAngle( const QPolygonF &points, bool isRing, int vertex );
352 
354  double mInterval;
357  std::unique_ptr< QgsMarkerSymbol > mMarker;
359  double mOffsetAlongLine; //distance to offset along line before marker is drawn
360  QgsUnitTypes::RenderUnit mOffsetAlongLineUnit; //unit for offset along line
362 
363  private:
364 
365 #ifdef SIP_RUN
367 #endif
368 
380  void renderOffsetVertexAlongLine( const QPolygonF &points, int vertex, double distance, QgsSymbolRenderContext &context );
381 };
382 
383 #endif
384 
385 
const QgsMapUnitScale & intervalMapUnitScale() const
Class for parsing and evaluation of expressions (formerly called "search strings").
virtual QVector< qreal > dxfCustomDashPattern(QgsUnitTypes::RenderUnit &unit) const
Gets dash pattern.
double interval() const
Returns the interval between individual markers.
QgsUnitTypes::RenderUnit customDashPatternUnit() const
Returns the units for lengths used in the custom dash pattern.
void setMapUnitScale(const QgsMapUnitScale &scale) override
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
void setUseCustomDashPattern(bool b)
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets offset.
void setRotateMarker(bool rotate)
Shall the marker be rotated.
QgsMapUnitScale mIntervalMapUnitScale
#define DEFAULT_MARKERLINE_INTERVAL
#define DEFAULT_SIMPLELINE_JOINSTYLE
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for markers...
virtual QgsStringMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const override
Gets line width.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:501
QgsMapUnitScale mOffsetAlongLineMapUnitScale
virtual void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context)=0
void setInterval(double interval)
Sets the interval between individual markers.
void setCustomDashPatternUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for lengths used in the custom dash pattern.
std::unique_ptr< QgsMarkerSymbol > mMarker
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
Placement
Defines how/where the marker should be placed on the line.
void setPlacement(Placement p)
The placement of the markers.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsUnitTypes::RenderUnit mIntervalUnit
QVector< qreal > customDashVector() const
#define DEFAULT_SIMPLELINE_CAPSTYLE
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
#define DEFAULT_SIMPLELINE_PENSTYLE
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsUnitTypes::RenderUnit mOffsetAlongLineUnit
#define DEFAULT_SIMPLELINE_COLOR
Qt::PenJoinStyle penJoinStyle() const
#define SIP_FACTORY
Definition: qgis_sip.h:69
A store for object properties.
Definition: qgsproperty.h:229
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for markers...
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
void setPenStyle(Qt::PenStyle style)
virtual double estimateMaxBleed(const QgsRenderContext &context) const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void setOffsetAlongLineUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit used for calculating the offset along line for markers.
void setPenCapStyle(Qt::PenCapStyle style)
QgsUnitTypes::RenderUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
virtual Qt::PenStyle dxfPenStyle() const
Gets pen style.
#define DEFAULT_SIMPLELINE_WIDTH
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
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.
Struct for storing maximum and minimum scales for measurements in map units.
virtual void stopRender(QgsSymbolRenderContext &context)=0
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
virtual QColor dxfColor(QgsSymbolRenderContext &context) const
Gets color.
Qt::PenStyle penStyle() const
void setIntervalUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the interval between markers.
void setDrawInsidePolygon(bool drawInsidePolygon)
void setCustomDashVector(const QVector< qreal > &vector)
QVector< qreal > mCustomDashVector
Vector with an even number of entries for the.
virtual void renderPolygonStroke(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context)
const QgsMapUnitScale & customDashPatternMapUnitScale() const
QgsMapUnitScale mCustomDashPatternMapUnitScale
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the marker placement.
Placement placement() const
The placement of the markers.
Qt::PenCapStyle penCapStyle() const
QgsUnitTypes::RenderUnit intervalUnit() const
Returns the units for the interval between markers.
#define DEFAULT_MARKERLINE_ROTATE
QgsMapUnitScale mapUnitScale() const override
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Property
Data definable properties.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:100
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
void setPenJoinStyle(Qt::PenJoinStyle style)
virtual void startRender(QgsSymbolRenderContext &context)=0
virtual QString layerType() const =0
Returns a string that represents this layer type.