QGIS API Documentation  3.4.3-Madeira (2f64a3c)
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 
238  double estimateMaxBleed( const QgsRenderContext &context ) const override;
239 
240  // new stuff
241 
247  bool rotateMarker() const { return mRotateMarker; }
248 
252  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
253 
259  double interval() const { return mInterval; }
260 
267  void setInterval( double interval ) { mInterval = interval; }
268 
272  Placement placement() const { return mPlacement; }
273 
277  void setPlacement( Placement p ) { mPlacement = p; }
278 
290  double offsetAlongLine() const { return mOffsetAlongLine; }
291 
304  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
305 
312  QgsUnitTypes::RenderUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
313 
320  void setOffsetAlongLineUnit( QgsUnitTypes::RenderUnit unit ) { mOffsetAlongLineUnit = unit; }
321 
326  const QgsMapUnitScale &offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
327 
332  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale &scale ) { mOffsetAlongLineMapUnitScale = scale; }
333 
340  void setIntervalUnit( QgsUnitTypes::RenderUnit unit ) { mIntervalUnit = unit; }
341 
347  QgsUnitTypes::RenderUnit intervalUnit() const { return mIntervalUnit; }
348 
349  void setIntervalMapUnitScale( const QgsMapUnitScale &scale ) { mIntervalMapUnitScale = scale; }
350  const QgsMapUnitScale &intervalMapUnitScale() const { return mIntervalMapUnitScale; }
351 
352  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
353  QgsUnitTypes::RenderUnit outputUnit() const override;
354 
355  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
356  QgsMapUnitScale mapUnitScale() const override;
357 
358  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
359 
360  void setDataDefinedProperty( QgsSymbolLayer::Property key, const QgsProperty &property ) override;
361 
362 
363  protected:
364 
365  void renderPolylineInterval( const QPolygonF &points, QgsSymbolRenderContext &context );
366  void renderPolylineVertex( const QPolygonF &points, QgsSymbolRenderContext &context, Placement placement = Vertex );
367  void renderPolylineCentral( const QPolygonF &points, QgsSymbolRenderContext &context );
368  double markerAngle( const QPolygonF &points, bool isRing, int vertex );
369 
371  double mInterval;
374  std::unique_ptr< QgsMarkerSymbol > mMarker;
376  double mOffsetAlongLine; //distance to offset along line before marker is drawn
377  QgsUnitTypes::RenderUnit mOffsetAlongLineUnit; //unit for offset along line
379 
380  private:
381 
382 #ifdef SIP_RUN
384 #endif
385 
397  void renderOffsetVertexAlongLine( const QPolygonF &points, int vertex, double distance, QgsSymbolRenderContext &context );
398 };
399 
400 #endif
401 
402 
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
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
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:570
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.
bool drawInsidePolygon() const
Returns true if the line should only be drawn inside polygons, and any portion of the line which fall...
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)
Sets whether the line should only be drawn inside polygons, and any portion of the line which falls o...
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: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 QString layerType() const =0
Returns a string that represents this layer type.