QGIS API Documentation  2.17.0-Master (8784312)
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 
64  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
65 
66  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
67 
68  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
69  QgsSymbolV2::OutputUnit outputUnit() const override;
70 
71  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
72  QgsMapUnitScale mapUnitScale() const override;
73 
74  double estimateMaxBleed() const override;
75 
76  // new stuff
77 
78  Qt::PenStyle penStyle() const { return mPenStyle; }
79  void setPenStyle( Qt::PenStyle style ) { mPenStyle = style; }
80 
81  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
82  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
83 
84  Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
85  void setPenCapStyle( Qt::PenCapStyle style ) { mPenCapStyle = style; }
86 
87  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
88  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
89 
90  void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
91  QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
92 
93  const QgsMapUnitScale& customDashPatternMapUnitScale() const { return mCustomDashPatternMapUnitScale; }
94  void setCustomDashPatternMapUnitScale( const QgsMapUnitScale& scale ) { mCustomDashPatternMapUnitScale = scale; }
95 
96  QVector<qreal> customDashVector() const { return mCustomDashVector; }
97  void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
98 
99  //Returns true if the line should only be drawn inside the polygon
100  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
101  //Set to true if the line should only be drawn inside the polygon
102  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
103 
105  Qt::PenStyle dxfPenStyle() const override;
106 
107  double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext &context ) const override;
108  double dxfOffset( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const override;
109  QColor dxfColor( QgsSymbolV2RenderContext &context ) const override;
110 
111  protected:
112  Qt::PenStyle mPenStyle;
113  Qt::PenJoinStyle mPenJoinStyle;
114  Qt::PenCapStyle mPenCapStyle;
117 
118  //use a custom dash dot pattern instead of the predefined ones
122 
125 
127 
128  private:
129  //helper functions for data defined symbology
130  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset );
131  void applySizeScale( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen );
132 };
133 
135 
136 #define DEFAULT_MARKERLINE_ROTATE true
137 #define DEFAULT_MARKERLINE_INTERVAL 3
138 
143 {
144  public:
146  double interval = DEFAULT_MARKERLINE_INTERVAL );
147 
149 
154  {
160  CurvePoint
161  };
162 
163  // static stuff
164 
172  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
173 
181  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
182 
183  // implemented from base classes
184 
185  QString layerType() const override;
186 
187  void startRender( QgsSymbolV2RenderContext& context ) override;
188 
189  void stopRender( QgsSymbolV2RenderContext& context ) override;
190 
191  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;
192 
193  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) override;
194 
195  QgsStringMap properties() const override;
196 
197  QgsMarkerLineSymbolLayerV2* clone() const override;
198 
199  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
200 
201  void setColor( const QColor& color ) override;
202  virtual QColor color() const override;
203 
204  QgsSymbolV2* subSymbol() override;
205  bool setSubSymbol( QgsSymbolV2* symbol ) override;
206 
207  virtual void setWidth( double width ) override;
208  virtual double width() const override;
209 
210  double estimateMaxBleed() const override;
211 
212  // new stuff
213 
219  bool rotateMarker() const { return mRotateMarker; }
220 
224  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
225 
229  double interval() const { return mInterval; }
230 
234  void setInterval( double interval ) { mInterval = interval; }
235 
239  Placement placement() const { return mPlacement; }
240 
244  void setPlacement( Placement p ) { mPlacement = p; }
245 
256  double offsetAlongLine() const { return mOffsetAlongLine; }
257 
269  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
270 
276  QgsSymbolV2::OutputUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
277 
283  void setOffsetAlongLineUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetAlongLineUnit = unit; }
284 
288  const QgsMapUnitScale& offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
289 
293  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetAlongLineMapUnitScale = scale; }
294 
295  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
296  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
297 
298  void setIntervalMapUnitScale( const QgsMapUnitScale& scale ) { mIntervalMapUnitScale = scale; }
299  const QgsMapUnitScale& intervalMapUnitScale() const { return mIntervalMapUnitScale; }
300 
301  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
302  QgsSymbolV2::OutputUnit outputUnit() const override;
303 
304  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
305  QgsMapUnitScale mapUnitScale() const override;
306 
307  QSet<QString> usedAttributes() const override;
308 
309  void setDataDefinedProperty( const QString& property, QgsDataDefined* dataDefined ) override;
310 
311 
312  protected:
313 
314  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
315  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
316  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
317  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
318 
320  double mInterval;
325  double mOffsetAlongLine; //distance to offset along line before marker is drawn
326  QgsSymbolV2::OutputUnit mOffsetAlongLineUnit; //unit for offset along line
328 
329  private:
330 
341  void renderOffsetVertexAlongLine( const QPolygonF& points, int vertex, double distance, QgsSymbolV2RenderContext &context );
342 };
343 
344 #endif
345 
346 
virtual QSet< QString > usedAttributes() const
Returns the set of attributes referenced by the layer.
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
QgsSymbolV2::OutputUnit customDashPatternUnit() const
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsSymbolV2::OutputUnit intervalUnit() const
#define DEFAULT_SIMPLELINE_PENSTYLE
#define DEFAULT_MARKERLINE_ROTATE
QgsSymbolV2::OutputUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:65
virtual Qt::PenStyle dxfPenStyle() const
get pen style
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 double width() const
#define DEFAULT_MARKERLINE_INTERVAL
const QgsMapUnitScale & customDashPatternMapUnitScale() const
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
Placement
Defines how/where the marker should be placed on the line.
QgsMapUnitScale mCustomDashPatternMapUnitScale
QgsSymbolV2::OutputUnit outputUnit() const override
QVector< qreal > customDashVector() const
const QgsMapUnitScale & intervalMapUnitScale() const
void setPenJoinStyle(Qt::PenJoinStyle style)
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
QMap< QString, QString > QgsStringMap
Definition: qgis.h:492
Qt::PenStyle penStyle() const
QgsMapUnitScale mOffsetAlongLineMapUnitScale
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
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.
QgsSymbolV2::OutputUnit mIntervalUnit
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
virtual QVector< qreal > dxfCustomDashPattern(QgsSymbolV2::OutputUnit &unit) const
get dash pattern
QVector< qreal > mCustomDashVector
Vector with an even number of entries for the.
#define DEFAULT_SIMPLELINE_WIDTH
virtual void setWidth(double width)
bool rotateMarker() const
Shall the marker be rotated.
virtual QgsStringMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
double interval() const
The interval between individual markers.
virtual QColor color() const
The fill color.
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for markers...
virtual void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)
void setOffsetAlongLineUnit(QgsSymbolV2::OutputUnit unit)
Sets the unit used for calculating the offset along line for markers.
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 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 QColor dxfColor(QgsSymbolV2RenderContext &context) const
get color
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
virtual void setColor(const QColor &color)
The fill color.
Placement placement() const
The placement of the markers.
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const
get offset
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const override
get line width
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for markers...
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
set layer&#39;s subsymbol. takes ownership of the passed symbol
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
Qt::PenJoinStyle penJoinStyle() const
Qt::PenCapStyle penCapStyle() const
virtual Q_DECL_DEPRECATED void setDataDefinedProperty(const QString &property, const QString &expressionString)
Sets a data defined expression for a property.