QGIS API Documentation  2.0.1-Dufour
 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  // new stuff
67 
68  Qt::PenStyle penStyle() const { return mPenStyle; }
69  void setPenStyle( Qt::PenStyle style ) { mPenStyle = style; }
70 
71  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
72  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
73 
74  Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
75  void setPenCapStyle( Qt::PenCapStyle style ) { mPenCapStyle = style; }
76 
77  double offset() const { return mOffset; }
78  void setOffset( double offset ) { mOffset = offset; }
79 
80  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
81  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
82 
83  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
84  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
85 
86  QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
87  void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
88 
89  QVector<qreal> customDashVector() const { return mCustomDashVector; }
90  void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
91 
92  protected:
93  Qt::PenStyle mPenStyle;
94  Qt::PenJoinStyle mPenJoinStyle;
95  Qt::PenCapStyle mPenCapStyle;
96  QPen mPen;
97  QPen mSelPen;
98  double mOffset;
100 
101  //use a custom dash dot pattern instead of the predefined ones
104 
106  QVector<qreal> mCustomDashVector;
107 
108  private:
109  //helper functions for data defined symbology
110  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset );
111 };
112 
114 
115 #define DEFAULT_MARKERLINE_ROTATE true
116 #define DEFAULT_MARKERLINE_INTERVAL 3
117 
119 {
120  public:
122  double interval = DEFAULT_MARKERLINE_INTERVAL );
123 
125 
127  {
132  CentralPoint
133  };
134 
135  // static stuff
136 
137  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
138  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
139 
140  // implemented from base classes
141 
142  QString layerType() const;
143 
144  void startRender( QgsSymbolV2RenderContext& context );
145 
146  void stopRender( QgsSymbolV2RenderContext& context );
147 
148  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
149 
150  QgsStringMap properties() const;
151 
152  QgsSymbolLayerV2* clone() const;
153 
154  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
155 
156  void setColor( const QColor& color );
157 
159  bool setSubSymbol( QgsSymbolV2* symbol );
160 
161  virtual void setWidth( double width );
162  virtual double width() const;
163 
164  // new stuff
165 
166  bool rotateMarker() const { return mRotateMarker; }
167  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
168 
169  double interval() const { return mInterval; }
170  void setInterval( double interval ) { mInterval = interval; }
171 
172  double offset() const { return mOffset; }
173  void setOffset( double offset ) { mOffset = offset; }
174 
175  Placement placement() const { return mPlacement; }
176  void setPlacement( Placement p ) { mPlacement = p; }
177 
178  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
179  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
180 
181  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
182  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
183 
186 
187  protected:
188 
189  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
190  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
191  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
192  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
193 
195  double mInterval;
198  double mOffset;
201 };
202 
203 #endif