QGIS API Documentation  2.14.11-Essen
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 
32 
34 {
35  public:
37  double width = DEFAULT_SIMPLELINE_WIDTH,
38  Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE );
39 
40  // static stuff
41 
42  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
43  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
44 
45  // implemented from base classes
46 
47  QString layerType() const override;
48 
49  void startRender( QgsSymbolV2RenderContext& context ) override;
50 
51  void stopRender( QgsSymbolV2RenderContext& context ) override;
52 
53  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;
54 
55  //overridden so that clip path can be set when using draw inside polygon option
56  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) override;
57 
58  QgsStringMap properties() const override;
59 
60  QgsSimpleLineSymbolLayerV2* clone() const override;
61 
63  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
64 
65  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
66 
67  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
68  QgsSymbolV2::OutputUnit outputUnit() const override;
69 
70  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
71  QgsMapUnitScale mapUnitScale() const override;
72 
73  double estimateMaxBleed() const override;
74 
75  // new stuff
76 
77  Qt::PenStyle penStyle() const { return mPenStyle; }
78  void setPenStyle( Qt::PenStyle style ) { mPenStyle = style; }
79 
80  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
81  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
82 
83  Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
84  void setPenCapStyle( Qt::PenCapStyle style ) { mPenCapStyle = style; }
85 
86  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
87  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
88 
89  void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
90  QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
91 
92  const QgsMapUnitScale& customDashPatternMapUnitScale() const { return mCustomDashPatternMapUnitScale; }
93  void setCustomDashPatternMapUnitScale( const QgsMapUnitScale& scale ) { mCustomDashPatternMapUnitScale = scale; }
94 
95  QVector<qreal> customDashVector() const { return mCustomDashVector; }
96  void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
97 
98  //Returns true if the line should only be drawn inside the polygon
99  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
100  //Set to true if the line should only be drawn inside the polygon
101  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
102 
104  Qt::PenStyle dxfPenStyle() const override;
105 
106  double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext &context ) const override;
107  double dxfOffset( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const override;
108  QColor dxfColor( QgsSymbolV2RenderContext &context ) const override;
109 
110  protected:
111  Qt::PenStyle mPenStyle;
112  Qt::PenJoinStyle mPenJoinStyle;
113  Qt::PenCapStyle mPenCapStyle;
116 
117  //use a custom dash dot pattern instead of the predefined ones
121 
124 
126 
127  private:
128  //helper functions for data defined symbology
129  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset );
130  void applySizeScale( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen );
131 };
132 
134 
135 #define DEFAULT_MARKERLINE_ROTATE true
136 #define DEFAULT_MARKERLINE_INTERVAL 3
137 
139 {
140  public:
142  double interval = DEFAULT_MARKERLINE_INTERVAL );
143 
145 
150  {
156  CurvePoint
157  };
158 
159  // static stuff
160 
168  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
169 
177  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
178 
179  // implemented from base classes
180 
181  QString layerType() const override;
182 
183  void startRender( QgsSymbolV2RenderContext& context ) override;
184 
185  void stopRender( QgsSymbolV2RenderContext& context ) override;
186 
187  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;
188 
189  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) override;
190 
191  QgsStringMap properties() const override;
192 
193  QgsMarkerLineSymbolLayerV2* clone() const override;
194 
196  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
197 
198  void setColor( const QColor& color ) override;
199  virtual QColor color() const override;
200 
201  QgsSymbolV2* subSymbol() override;
202  bool setSubSymbol( QgsSymbolV2* symbol ) override;
203 
204  virtual void setWidth( double width ) override;
205  virtual double width() const override;
206 
207  double estimateMaxBleed() const override;
208 
209  // new stuff
210 
216  bool rotateMarker() const { return mRotateMarker; }
217 
221  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
222 
226  double interval() const { return mInterval; }
227 
231  void setInterval( double interval ) { mInterval = interval; }
232 
236  Placement placement() const { return mPlacement; }
237 
241  void setPlacement( Placement p ) { mPlacement = p; }
242 
253  double offsetAlongLine() const { return mOffsetAlongLine; }
254 
266  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
267 
273  QgsSymbolV2::OutputUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
274 
280  void setOffsetAlongLineUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetAlongLineUnit = unit; }
281 
285  const QgsMapUnitScale& offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
286 
290  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetAlongLineMapUnitScale = scale; }
291 
292  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
293  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
294 
295  void setIntervalMapUnitScale( const QgsMapUnitScale& scale ) { mIntervalMapUnitScale = scale; }
296  const QgsMapUnitScale& intervalMapUnitScale() const { return mIntervalMapUnitScale; }
297 
298  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
299  QgsSymbolV2::OutputUnit outputUnit() const override;
300 
301  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
302  QgsMapUnitScale mapUnitScale() const override;
303 
304  QSet<QString> usedAttributes() const override;
305 
306  void setDataDefinedProperty( const QString& property, QgsDataDefined* dataDefined ) override;
307 
308 
309  protected:
310 
311  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
312  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
313  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
314  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
315 
317  double mInterval;
322  double mOffsetAlongLine; //distance to offset along line before marker is drawn
323  QgsSymbolV2::OutputUnit mOffsetAlongLineUnit; //unit for offset along line
325 
326  private:
327 
338  void renderOffsetVertexAlongLine( const QPolygonF& points, int vertex, double distance, QgsSymbolV2RenderContext &context );
339 };
340 
341 #endif
342 
343 
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:62
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
Qt::PenJoinStyle penJoinStyle() const
virtual QColor dxfColor(QgsSymbolV2RenderContext &context) const
#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:392
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
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
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
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.