QGIS API Documentation  2.7.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  void applySizeScale( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen );
141 };
142 
144 
145 #define DEFAULT_MARKERLINE_ROTATE true
146 #define DEFAULT_MARKERLINE_INTERVAL 3
147 
149 {
150  public:
152  double interval = DEFAULT_MARKERLINE_INTERVAL );
153 
155 
157  {
162  CentralPoint
163  };
164 
165  // static stuff
166 
167  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
168  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
169 
170  // implemented from base classes
171 
172  QString layerType() const;
173 
174  void startRender( QgsSymbolV2RenderContext& context );
175 
176  void stopRender( QgsSymbolV2RenderContext& context );
177 
178  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
179 
180  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
181 
182  QgsStringMap properties() const;
183 
184  QgsSymbolLayerV2* clone() const;
185 
186  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
187 
188  void setColor( const QColor& color );
189 
191  bool setSubSymbol( QgsSymbolV2* symbol );
192 
193  virtual void setWidth( double width );
194  virtual double width() const;
195 
196  double estimateMaxBleed() const;
197 
198  // new stuff
199 
200  bool rotateMarker() const { return mRotateMarker; }
201  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
202 
203  double interval() const { return mInterval; }
204  void setInterval( double interval ) { mInterval = interval; }
205 
206  double offset() const { return mOffset; }
207  void setOffset( double offset ) { mOffset = offset; }
208 
209  Placement placement() const { return mPlacement; }
210  void setPlacement( Placement p ) { mPlacement = p; }
211 
222  double offsetAlongLine() const { return mOffsetAlongLine; }
223 
235  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
236 
242  QgsSymbolV2::OutputUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
243 
249  void setOffsetAlongLineUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetAlongLineUnit = unit; }
250 
254  const QgsMapUnitScale& offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
255 
259  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetAlongLineMapUnitScale = scale; }
260 
261  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
262  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
263 
264  void setIntervalMapUnitScale( const QgsMapUnitScale& scale ) { mIntervalMapUnitScale = scale; }
265  const QgsMapUnitScale& intervalMapUnitScale() const { return mIntervalMapUnitScale; }
266 
267  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
268  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
269 
270  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
271  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
272 
275 
276  void setMapUnitScale( const QgsMapUnitScale& scale );
278 
279  protected:
280 
281  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
282  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
283  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
284  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
285 
287  double mInterval;
291  double mOffset;
295  double mOffsetAlongLine; //distance to offset along line before marker is drawn
296  QgsSymbolV2::OutputUnit mOffsetAlongLineUnit; //unit for offset along line
298 
299  private:
300 
311  void renderOffsetVertexAlongLine( const QPolygonF& points, int vertex, double distance, QgsSymbolV2RenderContext &context );
312 };
313 
314 #endif
315 
316 
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
QgsSymbolV2::OutputUnit customDashPatternUnit() const
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:87
QgsSymbolV2::OutputUnit intervalUnit() const
#define DEFAULT_SIMPLELINE_PENSTYLE
#define DEFAULT_MARKERLINE_ROTATE
void setOutputUnit(QgsSymbolV2::OutputUnit unit)
QgsSymbolV2::OutputUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
virtual Qt::PenStyle dxfPenStyle() const
virtual QgsSymbolLayerV2 * clone() const =0
const QgsMapUnitScale & offsetMapUnitScale() const
virtual double width() const
QgsSymbolV2::OutputUnit outputUnit() const
#define DEFAULT_MARKERLINE_INTERVAL
const QgsMapUnitScale & customDashPatternMapUnitScale() const
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
QgsMapUnitScale mCustomDashPatternMapUnitScale
QVector< qreal > customDashVector() const
const QgsMapUnitScale & intervalMapUnitScale() const
void setPenJoinStyle(Qt::PenJoinStyle style)
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
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)
QgsSymbolV2::OutputUnit mOffsetUnit
void setDrawInsidePolygon(bool drawInsidePolygon)
QgsSymbolV2::OutputUnit mIntervalUnit
virtual void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
virtual QVector< qreal > dxfCustomDashPattern(QgsSymbolV2::OutputUnit &unit) const
const QgsMapUnitScale & offsetMapUnitScale() const
QVector< qreal > mCustomDashVector
Vector with an even number of entries for the.
#define DEFAULT_SIMPLELINE_WIDTH
virtual void setWidth(double width)
virtual QgsStringMap properties() const =0
QgsMapUnitScale mapUnitScale() const
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)
QgsSymbolV2::OutputUnit offsetUnit() const
virtual QColor dxfColor(const QgsSymbolV2RenderContext &context) const
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
virtual void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context)=0
QgsSymbolV2::OutputUnit mCustomDashPatternUnit
virtual QString layerType() const =0
virtual QgsSymbolV2 * subSymbol()
#define DEFAULT_SIMPLELINE_COLOR
QgsSymbolV2::OutputUnit mOffsetAlongLineUnit
void setPenStyle(Qt::PenStyle style)
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
virtual void setColor(const QColor &color)
QgsSymbolV2::OutputUnit mOffsetUnit
virtual double dxfWidth(const QgsDxfExport &e, const QgsSymbolV2RenderContext &context) const
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)
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
QgsSymbolV2::OutputUnit offsetUnit() const
Qt::PenJoinStyle penJoinStyle() const
void setMapUnitScale(const QgsMapUnitScale &scale)
Qt::PenCapStyle penCapStyle() const