QGIS API Documentation  2.2.0-Valmiera
 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  QgsStringMap properties() const;
56 
57  QgsSymbolLayerV2* clone() const;
58 
59  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
60 
61  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
62 
65 
66  double estimateMaxBleed() const;
67 
68  // new stuff
69 
70  Qt::PenStyle penStyle() const { return mPenStyle; }
71  void setPenStyle( Qt::PenStyle style ) { mPenStyle = style; }
72 
73  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
74  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
75 
76  Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
77  void setPenCapStyle( Qt::PenCapStyle style ) { mPenCapStyle = style; }
78 
79  double offset() const { return mOffset; }
80  void setOffset( double offset ) { mOffset = offset; }
81 
82  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
83  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
84 
85  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
86  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
87 
88  QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
89  void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
90 
91  QVector<qreal> customDashVector() const { return mCustomDashVector; }
92  void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
93 
94  //Returns true if the line should only be drawn inside the polygon
95  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
96  //Set to true if the line should only be drawn inside the polygon
97  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
98 
99  QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
100  Qt::PenStyle dxfPenStyle() const;
101 
102  double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
103  QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
104 
105  protected:
106  Qt::PenStyle mPenStyle;
107  Qt::PenJoinStyle mPenJoinStyle;
108  Qt::PenCapStyle mPenCapStyle;
109  QPen mPen;
110  QPen mSelPen;
111  double mOffset;
113 
114  //use a custom dash dot pattern instead of the predefined ones
117 
119  QVector<qreal> mCustomDashVector;
120 
122 
123  private:
124  //helper functions for data defined symbology
125  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset );
126 };
127 
129 
130 #define DEFAULT_MARKERLINE_ROTATE true
131 #define DEFAULT_MARKERLINE_INTERVAL 3
132 
134 {
135  public:
137  double interval = DEFAULT_MARKERLINE_INTERVAL );
138 
140 
142  {
147  CentralPoint
148  };
149 
150  // static stuff
151 
152  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
153  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
154 
155  // implemented from base classes
156 
157  QString layerType() const;
158 
159  void startRender( QgsSymbolV2RenderContext& context );
160 
161  void stopRender( QgsSymbolV2RenderContext& context );
162 
163  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
164 
165  QgsStringMap properties() const;
166 
167  QgsSymbolLayerV2* clone() const;
168 
169  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
170 
171  void setColor( const QColor& color );
172 
174  bool setSubSymbol( QgsSymbolV2* symbol );
175 
176  virtual void setWidth( double width );
177  virtual double width() const;
178 
179  double estimateMaxBleed() const;
180 
181  // new stuff
182 
183  bool rotateMarker() const { return mRotateMarker; }
184  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
185 
186  double interval() const { return mInterval; }
187  void setInterval( double interval ) { mInterval = interval; }
188 
189  double offset() const { return mOffset; }
190  void setOffset( double offset ) { mOffset = offset; }
191 
192  Placement placement() const { return mPlacement; }
193  void setPlacement( Placement p ) { mPlacement = p; }
194 
195  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
196  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
197 
198  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
199  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
200 
203 
204  protected:
205 
206  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
207  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
208  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
209  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
210 
212  double mInterval;
215  double mOffset;
218 };
219 
220 #endif