QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsfillsymbollayerv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfillsymbollayerv2.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 QGSFILLSYMBOLLAYERV2_H
17 #define QGSFILLSYMBOLLAYERV2_H
18 
19 #include "qgssymbollayerv2.h"
20 
21 #define DEFAULT_SIMPLEFILL_COLOR QColor(0,0,255)
22 #define DEFAULT_SIMPLEFILL_STYLE Qt::SolidPattern
23 #define DEFAULT_SIMPLEFILL_BORDERCOLOR QColor(0,0,0)
24 #define DEFAULT_SIMPLEFILL_BORDERSTYLE Qt::SolidLine
25 #define DEFAULT_SIMPLEFILL_BORDERWIDTH DEFAULT_LINE_WIDTH
26 
27 #include <QPen>
28 #include <QBrush>
29 
31 {
32  public:
34  Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE,
35  QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR,
36  Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE,
37  double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH );
38 
39  // static stuff
40 
41  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
42  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
43 
44  // implemented from base classes
45 
46  QString layerType() const;
47 
48  void startRender( QgsSymbolV2RenderContext& context );
49 
50  void stopRender( QgsSymbolV2RenderContext& context );
51 
52  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
53 
54  QgsStringMap properties() const;
55 
56  QgsSymbolLayerV2* clone() const;
57 
58  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
59 
60  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
61 
62  Qt::BrushStyle brushStyle() const { return mBrushStyle; }
63  void setBrushStyle( Qt::BrushStyle style ) { mBrushStyle = style; }
64 
65  QColor borderColor() const { return mBorderColor; }
66  void setBorderColor( QColor borderColor ) { mBorderColor = borderColor; }
67 
68  Qt::PenStyle borderStyle() const { return mBorderStyle; }
69  void setBorderStyle( Qt::PenStyle borderStyle ) { mBorderStyle = borderStyle; }
70 
71  double borderWidth() const { return mBorderWidth; }
72  void setBorderWidth( double borderWidth ) { mBorderWidth = borderWidth; }
73 
74  void setOffset( QPointF offset ) { mOffset = offset; }
75  QPointF offset() { return mOffset; }
76 
77  void setBorderWidthUnit( QgsSymbolV2::OutputUnit unit ) { mBorderWidthUnit = unit; }
78  QgsSymbolV2::OutputUnit borderWidthUnit() const { return mBorderWidthUnit; }
79 
80  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
81  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
82 
85 
86  protected:
87  QBrush mBrush;
88  QBrush mSelBrush;
89  Qt::BrushStyle mBrushStyle;
90  QColor mBorderColor;
91  Qt::PenStyle mBorderStyle;
92  double mBorderWidth;
94  QPen mPen;
95  QPen mSelPen;
96 
97  QPointF mOffset;
99 
100  private:
101  //helper functions for data defined symbology
102  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QBrush& brush, QPen& pen, QPen& selPen );
103 };
104 
107 {
108  public:
110  virtual ~QgsImageFillSymbolLayer();
111  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
112 
113  virtual QgsSymbolV2* subSymbol() { return mOutline; }
114  virtual bool setSubSymbol( QgsSymbolV2* symbol );
115 
116  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
117  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
118 
119  protected:
120  QBrush mBrush;
121  double mNextAngle; // mAngle / data defined angle
122 
126 
129 
130  virtual void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context ) { Q_UNUSED( context ); }
131 };
132 
136 {
137  public:
138  QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20, double rotation = 0.0 );
139  QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20, double rotation = 0.0 );
141 
142  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
143  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
144 
145  // implemented from base classes
146 
147  QString layerType() const;
148 
149  void startRender( QgsSymbolV2RenderContext& context );
150  void stopRender( QgsSymbolV2RenderContext& context );
151 
152  QgsStringMap properties() const;
153 
154  QgsSymbolLayerV2* clone() const;
155 
156  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
157 
158  //getters and setters
159  void setSvgFilePath( const QString& svgPath );
160  QString svgFilePath() const { return mSvgFilePath; }
161  void setPatternWidth( double width ) { mPatternWidth = width;}
162  double patternWidth() const { return mPatternWidth; }
163 
164  void setSvgFillColor( const QColor& c ) { mSvgFillColor = c; }
165  QColor svgFillColor() const { return mSvgFillColor; }
166  void setSvgOutlineColor( const QColor& c ) { mSvgOutlineColor = c; }
167  QColor svgOutlineColor() const { return mSvgOutlineColor; }
168  void setSvgOutlineWidth( double w ) { mSvgOutlineWidth = w; }
169  double svgOutlineWidth() const { return mSvgOutlineWidth; }
170 
171  void setPatternWidthUnit( QgsSymbolV2::OutputUnit unit ) { mPatternWidthUnit = unit; }
172  QgsSymbolV2::OutputUnit patternWidthUnit() const { return mPatternWidthUnit; }
173 
174  void setSvgOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mSvgOutlineWidthUnit = unit; }
175  QgsSymbolV2::OutputUnit svgOutlineWidthUnit() const { return mSvgOutlineWidthUnit; }
176 
179 
180  protected:
184 
186  QByteArray mSvgData;
188  QString mSvgFilePath;
190  QRectF mSvgViewBox;
193  QImage* mSvgPattern;
194 
195  //param(fill), param(outline), param(outline-width) are going
196  //to be replaced in memory
201 
202  void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context );
203 
204  private:
206  void storeViewBox();
207  void setDefaultSvgParams(); //fills mSvgFillColor, mSvgOutlineColor, mSvgOutlineWidth with default values for mSvgFilePath
208 
210  void applyPattern( QBrush& brush, const QString& svgFilePath, double patternWidth, QgsSymbolV2::OutputUnit patternWidthUnit, const QColor& svgFillColor, const QColor& svgOutlineColor,
211  double svgOutlineWidth, QgsSymbolV2::OutputUnit svgOutlineWidthUnit, const QgsSymbolV2RenderContext& context );
212 };
213 
215 {
216  public:
219 
220  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
221  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
222 
223  QString layerType() const;
224 
225  void startRender( QgsSymbolV2RenderContext& context );
226 
227  void stopRender( QgsSymbolV2RenderContext& context );
228 
229  QgsStringMap properties() const;
230 
231  QgsSymbolLayerV2* clone() const;
232 
233  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
234 
235  QString ogrFeatureStyleWidth( double widthScaleFactor ) const;
236 
237  //getters and setters
238  void setLineAngle( double a ) { mLineAngle = a; }
239  double lineAngle() const { return mLineAngle; }
240  void setDistance( double d ) { mDistance = d; }
241  double distance() const { return mDistance; }
242  void setLineWidth( double w ) { mLineWidth = w; }
243  double lineWidth() const { return mLineWidth; }
244  void setColor( const QColor& c ) { mColor = c; }
245  QColor color() const { return mColor; }
246  void setOffset( double offset ) { mOffset = offset; }
247  double offset() const { return mOffset; }
248 
249  void setDistanceUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceUnit = unit; }
250  QgsSymbolV2::OutputUnit distanceUnit() const { return mDistanceUnit; }
251 
252  void setLineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mLineWidthUnit = unit; }
253  QgsSymbolV2::OutputUnit lineWidthUnit() const { return mLineWidthUnit; }
254 
255  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
256  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
257 
260 
261  protected:
263  double mDistance;
266  double mLineWidth;
268  QColor mColor;
270  double mLineAngle;
272  double mOffset;
274 
275  void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context );
276 
277  private:
279  void applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double lineAngle, double distance, double lineWidth, const QColor& color );
280 };
281 
283 {
284  public:
287 
288  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
289  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
290 
291  QString layerType() const;
292 
293  void startRender( QgsSymbolV2RenderContext& context );
294 
295  void stopRender( QgsSymbolV2RenderContext& context );
296 
297  QgsStringMap properties() const;
298 
299  QgsSymbolLayerV2* clone() const;
300 
301  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
302 
303  //getters and setters
304  double distanceX() const { return mDistanceX; }
305  void setDistanceX( double d ) { mDistanceX = d; }
306 
307  double distanceY() const { return mDistanceY; }
308  void setDistanceY( double d ) { mDistanceY = d; }
309 
310  double displacementX() const { return mDisplacementX; }
311  void setDisplacementX( double d ) { mDisplacementX = d; }
312 
313  double displacementY() const { return mDisplacementY; }
314  void setDisplacementY( double d ) { mDisplacementY = d; }
315 
316  bool setSubSymbol( QgsSymbolV2* symbol );
317  virtual QgsSymbolV2* subSymbol() { return mMarkerSymbol; }
318 
319  void setDistanceXUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceXUnit = unit; }
320  QgsSymbolV2::OutputUnit distanceXUnit() const { return mDistanceXUnit; }
321 
322  void setDistanceYUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceYUnit = unit; }
323  QgsSymbolV2::OutputUnit distanceYUnit() const { return mDistanceYUnit; }
324 
325  void setDisplacementXUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementXUnit = unit; }
326  QgsSymbolV2::OutputUnit displacementXUnit() const { return mDisplacementXUnit; }
327 
328  void setDisplacementYUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementYUnit = unit; }
329  QgsSymbolV2::OutputUnit displacementYUnit() const { return mDisplacementYUnit; }
330 
333 
334  protected:
336  double mDistanceX;
338  double mDistanceY;
344 
345  void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context );
346 
347  private:
348  void applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double distanceX, double distanceY,
349  double displacementX, double displacementY );
350 };
351 
353 {
354  public:
357 
358  // static stuff
359 
360  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
361  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
362 
363  // implemented from base classes
364 
365  QString layerType() const;
366 
367  void startRender( QgsSymbolV2RenderContext& context );
368 
369  void stopRender( QgsSymbolV2RenderContext& context );
370 
371  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
372 
373  QgsStringMap properties() const;
374 
375  QgsSymbolLayerV2* clone() const;
376 
377  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
378 
379  void setColor( const QColor& color );
380 
382  bool setSubSymbol( QgsSymbolV2* symbol );
383 
384  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); }
386 
387  virtual QSet<QString> usedAttributes() const;
388 
389  protected:
391 };
392 
393 #endif