QGIS API Documentation  2.12.0-Lyon
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 override;
48 
49  void startRender( QgsSymbolV2RenderContext& context ) override;
50 
51  void stopRender( QgsSymbolV2RenderContext& context ) override;
52 
53  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;
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 ) override;
57 
58  QgsStringMap properties() const override;
59 
60  QgsSymbolLayerV2* clone() const override;
61 
62  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
63 
64  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
65 
66  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
67  QgsSymbolV2::OutputUnit outputUnit() const override;
68 
69  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
70  QgsMapUnitScale mapUnitScale() const override;
71 
72  double estimateMaxBleed() const override;
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  bool useCustomDashPattern() const { return mUseCustomDashPattern; }
86  void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
87 
88  void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
89  QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
90 
91  const QgsMapUnitScale& customDashPatternMapUnitScale() const { return mCustomDashPatternMapUnitScale; }
92  void setCustomDashPatternMapUnitScale( const QgsMapUnitScale& scale ) { mCustomDashPatternMapUnitScale = scale; }
93 
94  QVector<qreal> customDashVector() const { return mCustomDashVector; }
95  void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
96 
97  //Returns true if the line should only be drawn inside the polygon
98  bool drawInsidePolygon() const { return mDrawInsidePolygon; }
99  //Set to true if the line should only be drawn inside the polygon
100  void setDrawInsidePolygon( bool drawInsidePolygon ) { mDrawInsidePolygon = drawInsidePolygon; }
101 
103  Qt::PenStyle dxfPenStyle() const override;
104 
105  double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext &context ) const override;
106  double dxfOffset( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const override;
107  QColor dxfColor( QgsSymbolV2RenderContext &context ) const override;
108 
109  protected:
110  Qt::PenStyle mPenStyle;
111  Qt::PenJoinStyle mPenJoinStyle;
112  Qt::PenCapStyle mPenCapStyle;
115 
116  //use a custom dash dot pattern instead of the predefined ones
120 
123 
125 
126  private:
127  //helper functions for data defined symbology
128  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset );
129  void applySizeScale( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen );
130 };
131 
133 
134 #define DEFAULT_MARKERLINE_ROTATE true
135 #define DEFAULT_MARKERLINE_INTERVAL 3
136 
138 {
139  public:
141  double interval = DEFAULT_MARKERLINE_INTERVAL );
142 
144 
146  {
152  CurvePoint
153  };
154 
155  // static stuff
156 
157  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
158  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
159 
160  // implemented from base classes
161 
162  QString layerType() const override;
163 
164  void startRender( QgsSymbolV2RenderContext& context ) override;
165 
166  void stopRender( QgsSymbolV2RenderContext& context ) override;
167 
168  void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;
169 
170  void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) override;
171 
172  QgsStringMap properties() const override;
173 
174  QgsSymbolLayerV2* clone() const override;
175 
176  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
177 
178  void setColor( const QColor& color ) override;
179 
180  QgsSymbolV2* subSymbol() override;
181  bool setSubSymbol( QgsSymbolV2* symbol ) override;
182 
183  virtual void setWidth( double width ) override;
184  virtual double width() const override;
185 
186  double estimateMaxBleed() const override;
187 
188  // new stuff
189 
190  bool rotateMarker() const { return mRotateMarker; }
191  void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }
192 
193  double interval() const { return mInterval; }
194  void setInterval( double interval ) { mInterval = interval; }
195 
196  Placement placement() const { return mPlacement; }
197  void setPlacement( Placement p ) { mPlacement = p; }
198 
209  double offsetAlongLine() const { return mOffsetAlongLine; }
210 
222  void setOffsetAlongLine( double offsetAlongLine ) { mOffsetAlongLine = offsetAlongLine; }
223 
229  QgsSymbolV2::OutputUnit offsetAlongLineUnit() const { return mOffsetAlongLineUnit; }
230 
236  void setOffsetAlongLineUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetAlongLineUnit = unit; }
237 
241  const QgsMapUnitScale& offsetAlongLineMapUnitScale() const { return mOffsetAlongLineMapUnitScale; }
242 
246  void setOffsetAlongLineMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetAlongLineMapUnitScale = scale; }
247 
248  void setIntervalUnit( QgsSymbolV2::OutputUnit unit ) { mIntervalUnit = unit; }
249  QgsSymbolV2::OutputUnit intervalUnit() const { return mIntervalUnit; }
250 
251  void setIntervalMapUnitScale( const QgsMapUnitScale& scale ) { mIntervalMapUnitScale = scale; }
252  const QgsMapUnitScale& intervalMapUnitScale() const { return mIntervalMapUnitScale; }
253 
254  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
255  QgsSymbolV2::OutputUnit outputUnit() const override;
256 
257  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
258  QgsMapUnitScale mapUnitScale() const override;
259 
260  QSet<QString> usedAttributes() const override;
261 
262  protected:
263 
264  void renderPolylineInterval( const QPolygonF& points, QgsSymbolV2RenderContext& context );
265  void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement = Vertex );
266  void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
267  double markerAngle( const QPolygonF& points, bool isRing, int vertex );
268 
270  double mInterval;
275  double mOffsetAlongLine; //distance to offset along line before marker is drawn
276  QgsSymbolV2::OutputUnit mOffsetAlongLineUnit; //unit for offset along line
278 
279  private:
280 
291  void renderOffsetVertexAlongLine( const QPolygonF& points, int vertex, double distance, QgsSymbolV2RenderContext &context );
292 };
293 
294 #endif
295 
296 
virtual QSet< QString > usedAttributes() const
Returns the set of attributes referenced by the layer.
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
QgsSymbolV2::OutputUnit customDashPatternUnit() const
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:92
QgsSymbolV2::OutputUnit intervalUnit() const
#define DEFAULT_SIMPLELINE_PENSTYLE
#define DEFAULT_MARKERLINE_ROTATE
QgsSymbolV2::OutputUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:55
virtual Qt::PenStyle dxfPenStyle() const
virtual QgsSymbolLayerV2 * clone() const =0
virtual double width() const
#define DEFAULT_MARKERLINE_INTERVAL
const QgsMapUnitScale & customDashPatternMapUnitScale() const
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
QgsMapUnitScale mCustomDashPatternMapUnitScale
QgsSymbolV2::OutputUnit outputUnit() const override
QVector< qreal > customDashVector() const
const QgsMapUnitScale & intervalMapUnitScale() const
void setPenJoinStyle(Qt::PenJoinStyle style)
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
QMap< QString, QString > QgsStringMap
Definition: qgis.h:367
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)
void setDrawInsidePolygon(bool drawInsidePolygon)
QgsSymbolV2::OutputUnit mIntervalUnit
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
virtual QVector< qreal > dxfCustomDashPattern(QgsSymbolV2::OutputUnit &unit) 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
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)
virtual void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context)=0
QgsSymbolV2::OutputUnit mCustomDashPatternUnit
virtual QString layerType() const =0
virtual QgsSymbolV2 * subSymbol()
#define DEFAULT_SIMPLELINE_COLOR
QgsMapUnitScale mapUnitScale() const override
QgsSymbolV2::OutputUnit mOffsetAlongLineUnit
void setPenStyle(Qt::PenStyle style)
void setMapUnitScale(const QgsMapUnitScale &scale) override
Struct for storing maximum and minimum scales for measurements in map units.
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
virtual QColor dxfColor(QgsSymbolV2RenderContext &context) const
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
virtual void setColor(const QColor &color)
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const override
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
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
Qt::PenJoinStyle penJoinStyle() const
Qt::PenCapStyle penCapStyle() const