QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
180 
181  QgsStringMap properties() const;
182 
183  QgsSymbolLayerV2* clone() const;
184 
185  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
186 
187  void setColor( const QColor& color );
188 
190  bool setSubSymbol( QgsSymbolV2* symbol );
191 
192  virtual void setWidth( double width );
193  virtual double width() const;
194 
195  double estimateMaxBleed() const;
196 
197  // new stuff
198 
199  bool rotateMarker() const { return mRotateMarker; }
200  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
201 
202  double interval() const { return mInterval; }
203  void setInterval( double interval ) { mInterval = interval; }
204 
205  double offset() const { return mOffset; }
206  void setOffset( double offset ) { mOffset = offset; }
207 
208  Placement placement() const { return mPlacement; }
209  void setPlacement( Placement p ) { mPlacement = p; }
210 
221  double offsetAlongLine() const { return mOffsetAlongLine; }
222 
234  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
235 
241  QgsSymbolV2::OutputUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
242 
248  void setOffsetAlongLineUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetAlongLineUnit = unit; }
249 
253  const QgsMapUnitScale& offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
254 
258  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetAlongLineMapUnitScale = scale; }
259 
260  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
261  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
262 
263  void setIntervalMapUnitScale( const QgsMapUnitScale& scale ) { mIntervalMapUnitScale = scale; }
264  const QgsMapUnitScale& intervalMapUnitScale() const { return mIntervalMapUnitScale; }
265 
266  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
267  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
268 
269  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
270  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
271 
274 
275  void setMapUnitScale( const QgsMapUnitScale& scale );
277 
278  protected:
279 
280  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
281  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
282  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
283  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
284 
286  double mInterval;
290  double mOffset;
294  double mOffsetAlongLine; //distance to offset along line before marker is drawn
295  QgsSymbolV2::OutputUnit mOffsetAlongLineUnit; //unit for offset along line
297 
298  private:
299 
310  void renderOffsetVertexAlongLine( const QPolygonF& points, int vertex, double distance, QgsSymbolV2RenderContext &context );
311 };
312 
313 #endif
314 
315