QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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;
48 
49  void startRender( QgsSymbolV2RenderContext& context );
50 
51  void stopRender( QgsSymbolV2RenderContext& context );
52 
53  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
54 
55  //overriden so that clip path can be set when using draw inside polygon option
56  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
57 
58  QgsStringMap properties() const;
59 
60  QgsSymbolLayerV2* clone() const;
61 
62  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
63 
64  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
65 
68 
69  void setMapUnitScale( const QgsMapUnitScale &scale );
71 
72  double estimateMaxBleed() const;
73 
74  // new stuff
75 
76  Qt::PenStyle penStyle() const { return mPenStyle; }
77  void setPenStyle( Qt::PenStyle style ) { mPenStyle = style; }
78 
79  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
80  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
81 
82  Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
83  void setPenCapStyle( Qt::PenCapStyle style ) { mPenCapStyle = style; }
84 
85  double offset() const { return mOffset; }
86  void setOffset( double offset ) { mOffset = offset; }
87 
88  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
89  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
90 
91  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
92  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
93 
94  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
95  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
96 
97  void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
98  QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
99 
100  const QgsMapUnitScale& customDashPatternMapUnitScale() const { return mCustomDashPatternMapUnitScale; }
101  void setCustomDashPatternMapUnitScale( const QgsMapUnitScale& scale ) { mCustomDashPatternMapUnitScale = scale; }
102 
103  QVector<qreal> customDashVector() const { return mCustomDashVector; }
104  void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
105 
106  //Returns true if the line should only be drawn inside the polygon
107  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
108  //Set to true if the line should only be drawn inside the polygon
109  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
110 
111  QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
112  Qt::PenStyle dxfPenStyle() const;
113 
114  double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
115  QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
116 
117  protected:
118  Qt::PenStyle mPenStyle;
119  Qt::PenJoinStyle mPenJoinStyle;
120  Qt::PenCapStyle mPenCapStyle;
121  QPen mPen;
122  QPen mSelPen;
123  double mOffset;
126 
127  //use a custom dash dot pattern instead of the predefined ones
131 
133  QVector<qreal> mCustomDashVector;
134 
136 
137  private:
138  //helper functions for data defined symbology
139  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset );
140 };
141 
143 
144 #define DEFAULT_MARKERLINE_ROTATE true
145 #define DEFAULT_MARKERLINE_INTERVAL 3
146 
148 {
149  public:
151  double interval = DEFAULT_MARKERLINE_INTERVAL );
152 
154 
156  {
161  CentralPoint
162  };
163 
164  // static stuff
165 
166  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
167  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
168 
169  // implemented from base classes
170 
171  QString layerType() const;
172 
173  void startRender( QgsSymbolV2RenderContext& context );
174 
175  void stopRender( QgsSymbolV2RenderContext& context );
176 
177  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
178 
179  QgsStringMap properties() const;
180 
181  QgsSymbolLayerV2* clone() const;
182 
183  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
184 
185  void setColor( const QColor& color );
186 
188  bool setSubSymbol( QgsSymbolV2* symbol );
189 
190  virtual void setWidth( double width );
191  virtual double width() const;
192 
193  double estimateMaxBleed() const;
194 
195  // new stuff
196 
197  bool rotateMarker() const { return mRotateMarker; }
198  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
199 
200  double interval() const { return mInterval; }
201  void setInterval( double interval ) { mInterval = interval; }
202 
203  double offset() const { return mOffset; }
204  void setOffset( double offset ) { mOffset = offset; }
205 
206  Placement placement() const { return mPlacement; }
207  void setPlacement( Placement p ) { mPlacement = p; }
208 
219  double offsetAlongLine() const { return mOffsetAlongLine; }
220 
232  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
233 
239  QgsSymbolV2::OutputUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
240 
246  void setOffsetAlongLineUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetAlongLineUnit = unit; }
247 
251  const QgsMapUnitScale& offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
252 
256  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetAlongLineMapUnitScale = scale; }
257 
258  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
259  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
260 
261  void setIntervalMapUnitScale( const QgsMapUnitScale& scale ) { mIntervalMapUnitScale = scale; }
262  const QgsMapUnitScale& intervalMapUnitScale() const { return mIntervalMapUnitScale; }
263 
264  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
265  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
266 
267  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
268  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
269 
272 
273  void setMapUnitScale( const QgsMapUnitScale& scale );
275 
276  protected:
277 
278  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
279  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
280  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
281  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
282 
284  double mInterval;
288  double mOffset;
292  double mOffsetAlongLine; //distance to offset along line before marker is drawn
293  QgsSymbolV2::OutputUnit mOffsetAlongLineUnit; //unit for offset along line
295 
296  private:
297 
308  void renderOffsetVertexAlongLine( const QPolygonF& points, int vertex, double distance , QgsSymbolV2RenderContext &context );
309 };
310 
311 #endif
312 
313 
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgslinesymbollayerv2.h:258
QgsSymbolV2::OutputUnit customDashPatternUnit() const
Definition: qgslinesymbollayerv2.h:98
Definition: qgslinesymbollayerv2.h:157
QgsMapUnitScale mOffsetMapUnitScale
Definition: qgslinesymbollayerv2.h:125
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QgsSymbolV2::OutputUnit intervalUnit() const
Definition: qgslinesymbollayerv2.h:259
#define DEFAULT_SIMPLELINE_PENSTYLE
Definition: qgslinesymbollayerv2.h:28
#define DEFAULT_MARKERLINE_ROTATE
Definition: qgslinesymbollayerv2.h:144
void setOutputUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgssymbollayerv2.cpp:375
Definition: qgslinesymbollayerv2.h:33
QgsSymbolV2::OutputUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
Definition: qgslinesymbollayerv2.h:239
OutputUnit
Definition: qgssymbolv2.h:47
virtual Qt::PenStyle dxfPenStyle() const
Definition: qgssymbollayerv2.cpp:116
virtual QgsSymbolLayerV2 * clone() const =0
const QgsMapUnitScale & offsetMapUnitScale() const
Definition: qgslinesymbollayerv2.h:92
virtual double width() const
Definition: qgssymbollayerv2.h:270
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbollayerv2.cpp:380
#define DEFAULT_MARKERLINE_INTERVAL
Definition: qgslinesymbollayerv2.h:145
const QgsMapUnitScale & customDashPatternMapUnitScale() const
Definition: qgslinesymbollayerv2.h:100
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgslinesymbollayerv2.h:97
Placement
Definition: qgslinesymbollayerv2.h:155
QgsMapUnitScale mCustomDashPatternMapUnitScale
Definition: qgslinesymbollayerv2.h:130
bool useCustomDashPattern() const
Definition: qgslinesymbollayerv2.h:94
double mOffsetAlongLine
Definition: qgslinesymbollayerv2.h:292
void setUseCustomDashPattern(bool b)
Definition: qgslinesymbollayerv2.h:95
double offset() const
Definition: qgslinesymbollayerv2.h:85
QVector< qreal > customDashVector() const
Definition: qgslinesymbollayerv2.h:103
const QgsMapUnitScale & intervalMapUnitScale() const
Definition: qgslinesymbollayerv2.h:262
void setPenJoinStyle(Qt::PenJoinStyle style)
Definition: qgslinesymbollayerv2.h:80
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgslinesymbollayerv2.h:264
Qt::PenCapStyle mPenCapStyle
Definition: qgslinesymbollayerv2.h:120
Definition: qgssymbollayerv2.h:45
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgslinesymbollayerv2.h:261
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgslinesymbollayerv2.h:91
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
Qt::PenStyle penStyle() const
Definition: qgslinesymbollayerv2.h:76
QgsMapUnitScale mOffsetAlongLineMapUnitScale
Definition: qgslinesymbollayerv2.h:294
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
Definition: qgssymbollayerv2.h:96
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the marker placement.
Definition: qgslinesymbollayerv2.h:232
virtual void startRender(QgsSymbolV2RenderContext &context)=0
void setInterval(double interval)
Definition: qgslinesymbollayerv2.h:201
QgsSymbolV2::OutputUnit mOffsetUnit
Definition: qgslinesymbollayerv2.h:124
bool mUseCustomDashPattern
Definition: qgslinesymbollayerv2.h:128
void setDrawInsidePolygon(bool drawInsidePolygon)
Definition: qgslinesymbollayerv2.h:109
void setRotateMarker(bool rotate)
Definition: qgslinesymbollayerv2.h:198
QgsSymbolV2::OutputUnit mIntervalUnit
Definition: qgslinesymbollayerv2.h:285
double mOffset
Definition: qgslinesymbollayerv2.h:123
virtual void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
Definition: qgssymbollayerv2.h:74
QPen mSelPen
Definition: qgslinesymbollayerv2.h:122
double mInterval
Definition: qgslinesymbollayerv2.h:284
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
Definition: qgslinesymbollayerv2.h:219
Placement mPlacement
Definition: qgslinesymbollayerv2.h:291
bool drawInsidePolygon() const
Definition: qgslinesymbollayerv2.h:107
virtual QVector< qreal > dxfCustomDashPattern(QgsSymbolV2::OutputUnit &unit) const
Definition: qgssymbollayerv2.cpp:110
const QgsMapUnitScale & offsetMapUnitScale() const
Definition: qgslinesymbollayerv2.h:268
Qt::PenJoinStyle mPenJoinStyle
Definition: qgslinesymbollayerv2.h:119
QVector< qreal > mCustomDashVector
Vector with an even number of entries for the.
Definition: qgslinesymbollayerv2.h:133
#define DEFAULT_SIMPLELINE_WIDTH
Definition: qgslinesymbollayerv2.h:27
virtual void setWidth(double width)
Definition: qgssymbollayerv2.h:269
Definition: qgslinesymbollayerv2.h:158
bool rotateMarker() const
Definition: qgslinesymbollayerv2.h:197
Definition: qgslinesymbollayerv2.h:160
virtual QgsStringMap properties() const =0
double interval() const
Definition: qgslinesymbollayerv2.h:200
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbollayerv2.cpp:390
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for markers...
Definition: qgslinesymbollayerv2.h:256
void setOffset(double offset)
Definition: qgslinesymbollayerv2.h:204
virtual void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)
Definition: qgssymbollayerv2.cpp:408
void setOffsetAlongLineUnit(QgsSymbolV2::OutputUnit unit)
Sets the unit used for calculating the offset along line for markers.
Definition: qgslinesymbollayerv2.h:246
QgsMapUnitScale mOffsetMapUnitScale
Definition: qgslinesymbollayerv2.h:290
void setPenCapStyle(Qt::PenCapStyle style)
Definition: qgslinesymbollayerv2.h:83
Definition: qgssymbolv2.h:43
void setCustomDashVector(const QVector< qreal > &vector)
Definition: qgslinesymbollayerv2.h:104
QgsSymbolV2::OutputUnit offsetUnit() const
Definition: qgslinesymbollayerv2.h:89
QgsMarkerSymbolV2 * mMarker
Definition: qgslinesymbollayerv2.h:287
virtual QColor dxfColor(const QgsSymbolV2RenderContext &context) const
Definition: qgssymbollayerv2.cpp:104
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgslinesymbollayerv2.h:267
virtual void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context)=0
void setOffset(double offset)
Definition: qgslinesymbollayerv2.h:86
Definition: qgslinesymbollayerv2.h:147
QgsSymbolV2::OutputUnit mCustomDashPatternUnit
Definition: qgslinesymbollayerv2.h:129
virtual QString layerType() const =0
virtual QgsSymbolV2 * subSymbol()
Definition: qgssymbollayerv2.h:83
Definition: qgssymbolv2.h:229
#define DEFAULT_SIMPLELINE_COLOR
Definition: qgslinesymbollayerv2.h:26
QgsMapUnitScale mIntervalMapUnitScale
Definition: qgslinesymbollayerv2.h:286
QgsSymbolV2::OutputUnit mOffsetAlongLineUnit
Definition: qgslinesymbollayerv2.h:293
void setPenStyle(Qt::PenStyle style)
Definition: qgslinesymbollayerv2.h:77
void setPlacement(Placement p)
Definition: qgslinesymbollayerv2.h:207
Definition: qgsmapunitscale.h:24
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgslinesymbollayerv2.h:101
bool mDrawInsidePolygon
Definition: qgslinesymbollayerv2.h:135
Definition: qgslinesymbollayerv2.h:159
Qt::PenStyle mPenStyle
Definition: qgslinesymbollayerv2.h:118
double offset() const
Definition: qgslinesymbollayerv2.h:203
QPen mPen
Definition: qgslinesymbollayerv2.h:121
virtual void setColor(const QColor &color)
Definition: qgssymbollayerv2.h:51
Placement placement() const
Definition: qgslinesymbollayerv2.h:206
Definition: qgssymbolv2.h:167
double mOffset
Definition: qgslinesymbollayerv2.h:288
QgsSymbolV2::OutputUnit mOffsetUnit
Definition: qgslinesymbollayerv2.h:289
bool mRotateMarker
Definition: qgslinesymbollayerv2.h:283
virtual double dxfWidth(const QgsDxfExport &e, const QgsSymbolV2RenderContext &context) const
Definition: qgssymbollayerv2.cpp:418
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for markers...
Definition: qgslinesymbollayerv2.h:251
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
Definition: qgssymbollayerv2.h:85
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgslinesymbollayerv2.h:88
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
Definition: qgssymbollayerv2.h:77
Definition: qgssymbollayerv2.h:261
Definition: qgsdxfexport.h:32
QgsSymbolV2::OutputUnit offsetUnit() const
Definition: qgslinesymbollayerv2.h:265
Qt::PenJoinStyle penJoinStyle() const
Definition: qgslinesymbollayerv2.h:79
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbollayerv2.cpp:385
Qt::PenCapStyle penCapStyle() const
Definition: qgslinesymbollayerv2.h:82