QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
121  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
122 
132  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
133 
134  QVector<qreal> dxfCustomDashPattern( QgsUnitTypes::RenderUnit &unit ) const override;
135  Qt::PenStyle dxfPenStyle() const override;
136 
137  double dxfWidth( const QgsDxfExport &e, QgsSymbolRenderContext &context ) const override;
138  double dxfOffset( const QgsDxfExport &e, QgsSymbolRenderContext &context ) const override;
139  QColor dxfColor( QgsSymbolRenderContext &context ) const override;
140 
141  protected:
142  Qt::PenStyle mPenStyle;
143  Qt::PenJoinStyle mPenJoinStyle = DEFAULT_SIMPLELINE_JOINSTYLE;
144  Qt::PenCapStyle mPenCapStyle = DEFAULT_SIMPLELINE_CAPSTYLE;
145  QPen mPen;
146  QPen mSelPen;
147 
148  //use a custom dash dot pattern instead of the predefined ones
149  bool mUseCustomDashPattern = false;
152 
154  QVector<qreal> mCustomDashVector;
155 
156  bool mDrawInsidePolygon = false;
157 
158  private:
159  //helper functions for data defined symbology
160  void applyDataDefinedSymbology( QgsSymbolRenderContext &context, QPen &pen, QPen &selPen, double &offset );
161 };
162 
164 
165 #define DEFAULT_MARKERLINE_ROTATE true
166 #define DEFAULT_MARKERLINE_INTERVAL 3
167 
173 {
174  public:
176  double interval = DEFAULT_MARKERLINE_INTERVAL );
177 
182  {
188  CurvePoint
189  };
190 
191  // static stuff
192 
200  static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() ) SIP_FACTORY;
201 
209  static QgsSymbolLayer *createFromSld( QDomElement &element ) SIP_FACTORY;
210 
211  // implemented from base classes
212 
213  QString layerType() const override;
214 
215  void startRender( QgsSymbolRenderContext &context ) override;
216 
217  void stopRender( QgsSymbolRenderContext &context ) override;
218 
219  void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
220 
221  void renderPolygonStroke( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context ) override;
222 
223  QgsStringMap properties() const override;
224 
225  QgsMarkerLineSymbolLayer *clone() const override SIP_FACTORY;
226 
227  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const override;
228 
229  void setColor( const QColor &color ) override;
230  QColor color() const override;
231 
232  QgsSymbol *subSymbol() override;
233  bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
234 
235  void setWidth( double width ) override;
236  double width() const override;
237  double width( const QgsRenderContext &context ) const override;
238 
239  double estimateMaxBleed( const QgsRenderContext &context ) const override;
240 
241  // new stuff
242 
248  bool rotateMarker() const { return mRotateMarker; }
249 
253  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
254 
260  double interval() const { return mInterval; }
261 
268  void setInterval( double interval ) { mInterval = interval; }
269 
273  Placement placement() const { return mPlacement; }
274 
278  void setPlacement( Placement p ) { mPlacement = p; }
279 
291  double offsetAlongLine() const { return mOffsetAlongLine; }
292 
305  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
306 
313  QgsUnitTypes::RenderUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
314 
321  void setOffsetAlongLineUnit( QgsUnitTypes::RenderUnit unit ) { mOffsetAlongLineUnit = unit; }
322 
327  const QgsMapUnitScale &offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
328 
333  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale &scale ) { mOffsetAlongLineMapUnitScale = scale; }
334 
341  void setIntervalUnit( QgsUnitTypes::RenderUnit unit ) { mIntervalUnit = unit; }
342 
348  QgsUnitTypes::RenderUnit intervalUnit() const { return mIntervalUnit; }
349 
350  void setIntervalMapUnitScale( const QgsMapUnitScale &scale ) { mIntervalMapUnitScale = scale; }
351  const QgsMapUnitScale &intervalMapUnitScale() const { return mIntervalMapUnitScale; }
352 
353  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
354  QgsUnitTypes::RenderUnit outputUnit() const override;
355 
356  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
357  QgsMapUnitScale mapUnitScale() const override;
358 
359  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
360  bool hasDataDefinedProperties() const override;
361 
362  void setDataDefinedProperty( QgsSymbolLayer::Property key, const QgsProperty &property ) override;
363 
364 
365  protected:
366 
367  void renderPolylineInterval( const QPolygonF &points, QgsSymbolRenderContext &context );
368  void renderPolylineVertex( const QPolygonF &points, QgsSymbolRenderContext &context, Placement placement = Vertex );
369  void renderPolylineCentral( const QPolygonF &points, QgsSymbolRenderContext &context );
370  double markerAngle( const QPolygonF &points, bool isRing, int vertex );
371 
373  double mInterval;
376  std::unique_ptr< QgsMarkerSymbol > mMarker;
378  double mOffsetAlongLine; //distance to offset along line before marker is drawn
379  QgsUnitTypes::RenderUnit mOffsetAlongLineUnit; //unit for offset along line
381 
382  private:
383 
384 #ifdef SIP_RUN
386 #endif
387 
399  void renderOffsetVertexAlongLine( const QPolygonF &points, int vertex, double distance, QgsSymbolRenderContext &context );
400 };
401 
402 #endif
403 
404 
Class for parsing and evaluation of expressions (formerly called "search strings").
Placement placement() const
The placement of the markers.
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
void setMapUnitScale(const QgsMapUnitScale &scale) override
virtual Qt::PenStyle dxfPenStyle() const
Gets pen style.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
void setUseCustomDashPattern(bool b)
double interval() const
Returns the interval between individual markers.
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets offset.
const QgsMapUnitScale & intervalMapUnitScale() const
void setRotateMarker(bool rotate)
Shall the marker be rotated.
QgsMapUnitScale mIntervalMapUnitScale
#define DEFAULT_MARKERLINE_INTERVAL
#define DEFAULT_SIMPLELINE_JOINSTYLE
QgsUnitTypes::RenderUnit customDashPatternUnit() const
Returns the units for lengths used in the custom dash pattern.
Qt::PenStyle penStyle() const
virtual QVector< qreal > dxfCustomDashPattern(QgsUnitTypes::RenderUnit &unit) const
Gets dash pattern.
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:577
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
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
QgsUnitTypes::RenderUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
#define DEFAULT_SIMPLELINE_CAPSTYLE
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
const QgsMapUnitScale & customDashPatternMapUnitScale() const
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for markers...
QVector< qreal > customDashVector() const
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
bool useCustomDashPattern() 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)
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
void setPenStyle(Qt::PenStyle style)
void setOffsetAlongLineUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit used for calculating the offset along line for markers.
Qt::PenJoinStyle penJoinStyle() const
void setPenCapStyle(Qt::PenCapStyle style)
#define DEFAULT_SIMPLELINE_WIDTH
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 QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
void setIntervalUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the interval between markers.
virtual double estimateMaxBleed(const QgsRenderContext &context) const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void setDrawInsidePolygon(bool drawInsidePolygon)
Sets whether the line should only be drawn inside polygons, and any portion of the line which falls o...
QgsUnitTypes::RenderUnit intervalUnit() const
Returns the units for the interval between markers.
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)
QgsMapUnitScale mCustomDashPatternMapUnitScale
bool drawInsidePolygon() const
Returns true if the line should only be drawn inside polygons, and any portion of the line which fall...
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the marker placement.
Qt::PenCapStyle penCapStyle() const
#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:110
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 QColor dxfColor(QgsSymbolRenderContext &context) const
Gets color.
virtual QString layerType() const =0
Returns a string that represents this layer type.
double offsetAlongLine() const
Returns the offset along the line for the marker placement.