QGIS API Documentation  2.2.0-Valmiera
 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 
70  QColor outlineColor() const { return borderColor(); }
73  void setOutlineColor( const QColor& color ) { setBorderColor( color ); }
74 
77  QColor fillColor() const { return color(); }
80  void setFillColor( const QColor& color ) { setColor( color ); }
81 
82  Qt::PenStyle borderStyle() const { return mBorderStyle; }
83  void setBorderStyle( Qt::PenStyle borderStyle ) { mBorderStyle = borderStyle; }
84 
85  double borderWidth() const { return mBorderWidth; }
86  void setBorderWidth( double borderWidth ) { mBorderWidth = borderWidth; }
87 
88  void setOffset( QPointF offset ) { mOffset = offset; }
89  QPointF offset() { return mOffset; }
90 
91  void setBorderWidthUnit( QgsSymbolV2::OutputUnit unit ) { mBorderWidthUnit = unit; }
92  QgsSymbolV2::OutputUnit borderWidthUnit() const { return mBorderWidthUnit; }
93 
94  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
95  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
96 
99 
100  double estimateMaxBleed() const;
101 
102  double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
103  QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
104  Qt::PenStyle dxfPenStyle() const;
105 
106  protected:
107  QBrush mBrush;
108  QBrush mSelBrush;
109  Qt::BrushStyle mBrushStyle;
110  QColor mBorderColor;
111  Qt::PenStyle mBorderStyle;
112  double mBorderWidth;
114  QPen mPen;
115  QPen mSelPen;
116 
117  QPointF mOffset;
119 
120  private:
121  //helper functions for data defined symbology
122  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QBrush& brush, QPen& pen, QPen& selPen );
123 };
124 
126 
128 {
129  public:
130 
132  {
134  ColorRamp
135  };
136 
138  {
141  Conical
142  };
143 
145  {
147  Viewport
148  };
149 
151  {
154  Repeat
155  };
156 
158  QColor color2 = Qt::white,
159  GradientColorType gradientColorType = SimpleTwoColor,
160  GradientType gradientType = Linear,
161  GradientCoordinateMode coordinateMode = Feature,
162  GradientSpread gradientSpread = Pad
163  );
164 
165  virtual ~QgsGradientFillSymbolLayerV2();
166 
167  // static stuff
168 
169  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
170 
171  // implemented from base classes
172 
173  QString layerType() const;
174 
175  void startRender( QgsSymbolV2RenderContext& context );
176 
177  void stopRender( QgsSymbolV2RenderContext& context );
178 
179  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
180 
181  QgsStringMap properties() const;
182 
183  QgsSymbolLayerV2* clone() const;
184 
185  double estimateMaxBleed() const;
186 
188  GradientType gradientType() const { return mGradientType; };
189  void setGradientType( GradientType gradientType ) { mGradientType = gradientType; };
190 
192  GradientColorType gradientColorType() const { return mGradientColorType; };
193  void setGradientColorType( GradientColorType gradientColorType ) { mGradientColorType = gradientColorType; };
194 
196  QgsVectorColorRampV2* colorRamp() { return mGradientRamp; };
197  void setColorRamp( QgsVectorColorRampV2* ramp );
198 
200  QColor color2() const { return mColor2; };
201  void setColor2( QColor color2 ) { mColor2 = color2; };
202 
204  GradientCoordinateMode coordinateMode() const { return mCoordinateMode; };
205  void setCoordinateMode( GradientCoordinateMode coordinateMode ) { mCoordinateMode = coordinateMode; };
206 
208  GradientSpread gradientSpread() const { return mGradientSpread; };
209  void setGradientSpread( GradientSpread gradientSpread ) { mGradientSpread = gradientSpread; };
210 
212  void setReferencePoint1( QPointF referencePoint ) { mReferencePoint1 = referencePoint; };
213  QPointF referencePoint1() const { return mReferencePoint1; };
214 
216  void setReferencePoint1IsCentroid( bool isCentroid ) { mReferencePoint1IsCentroid = isCentroid; };
217  bool referencePoint1IsCentroid() const { return mReferencePoint1IsCentroid; };
218 
220  void setReferencePoint2( QPointF referencePoint ) { mReferencePoint2 = referencePoint; };
221  QPointF referencePoint2() const { return mReferencePoint2; };
222 
224  void setReferencePoint2IsCentroid( bool isCentroid ) { mReferencePoint2IsCentroid = isCentroid; };
225  bool referencePoint2IsCentroid() const { return mReferencePoint2IsCentroid; };
226 
228  void setAngle( double angle ) { mAngle = angle; };
229  double angle() const { return mAngle; };
230 
232  void setOffset( QPointF offset ) { mOffset = offset; };
233  QPointF offset() const { return mOffset; };
234 
236  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; };
237  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; };
238 
239  protected:
240  QBrush mBrush;
241  QBrush mSelBrush;
242 
244  QColor mColor2;
249 
254  double mAngle;
255 
256  QPointF mOffset;
258 
259  private:
260 
261  //helper functions for data defined symbology
262  void applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, const QPolygonF& points );
263 
265  void applyGradient( const QgsSymbolV2RenderContext& context, QBrush& brush, const QColor& color, const QColor& color2,
266  const GradientColorType &gradientColorType, QgsVectorColorRampV2 *gradientRamp, const GradientType &gradientType,
267  const GradientCoordinateMode &coordinateMode, const GradientSpread &gradientSpread,
268  const QPointF &referencePoint1, const QPointF &referencePoint2, const double angle );
269 
271  QPointF rotateReferencePoint( const QPointF & refPoint, double angle );
272 };
273 
276 {
277  public:
279  virtual ~QgsImageFillSymbolLayer();
280  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
281 
282  virtual QgsSymbolV2* subSymbol() { return mOutline; }
283  virtual bool setSubSymbol( QgsSymbolV2* symbol );
284 
285  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
286  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
287 
288  virtual double estimateMaxBleed() const;
289 
290  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
291  virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
292  virtual Qt::PenStyle dxfPenStyle() const;
293 
294  protected:
295  QBrush mBrush;
296  double mNextAngle; // mAngle / data defined angle
297 
301 
304 
305  virtual void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context ) { Q_UNUSED( context ); }
306 };
307 
311 {
312  public:
313  QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20, double rotation = 0.0 );
314  QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20, double rotation = 0.0 );
316 
317  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
318  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
319 
320  // implemented from base classes
321 
322  QString layerType() const;
323 
324  void startRender( QgsSymbolV2RenderContext& context );
325  void stopRender( QgsSymbolV2RenderContext& context );
326 
327  QgsStringMap properties() const;
328 
329  QgsSymbolLayerV2* clone() const;
330 
331  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
332 
333  //getters and setters
334  void setSvgFilePath( const QString& svgPath );
335  QString svgFilePath() const { return mSvgFilePath; }
336  void setPatternWidth( double width ) { mPatternWidth = width;}
337  double patternWidth() const { return mPatternWidth; }
338 
339  void setSvgFillColor( const QColor& c ) { mSvgFillColor = c; }
340  QColor svgFillColor() const { return mSvgFillColor; }
341  void setSvgOutlineColor( const QColor& c ) { mSvgOutlineColor = c; }
342  QColor svgOutlineColor() const { return mSvgOutlineColor; }
343  void setSvgOutlineWidth( double w ) { mSvgOutlineWidth = w; }
344  double svgOutlineWidth() const { return mSvgOutlineWidth; }
345 
346  void setPatternWidthUnit( QgsSymbolV2::OutputUnit unit ) { mPatternWidthUnit = unit; }
347  QgsSymbolV2::OutputUnit patternWidthUnit() const { return mPatternWidthUnit; }
348 
349  void setSvgOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mSvgOutlineWidthUnit = unit; }
350  QgsSymbolV2::OutputUnit svgOutlineWidthUnit() const { return mSvgOutlineWidthUnit; }
351 
354 
355  protected:
359 
361  QByteArray mSvgData;
363  QString mSvgFilePath;
365  QRectF mSvgViewBox;
368  QImage* mSvgPattern;
369 
370  //param(fill), param(outline), param(outline-width) are going
371  //to be replaced in memory
376 
377  void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context );
378 
379  private:
381  void storeViewBox();
382  void setDefaultSvgParams(); //fills mSvgFillColor, mSvgOutlineColor, mSvgOutlineWidth with default values for mSvgFilePath
383 
385  void applyPattern( QBrush& brush, const QString& svgFilePath, double patternWidth, QgsSymbolV2::OutputUnit patternWidthUnit, const QColor& svgFillColor, const QColor& svgOutlineColor,
386  double svgOutlineWidth, QgsSymbolV2::OutputUnit svgOutlineWidthUnit, const QgsSymbolV2RenderContext& context );
387 };
388 
390 {
391  public:
394 
395  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
396  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
397 
398  QString layerType() const;
399 
400  void startRender( QgsSymbolV2RenderContext& context );
401 
402  void stopRender( QgsSymbolV2RenderContext& context );
403 
404  QgsStringMap properties() const;
405 
406  QgsSymbolLayerV2* clone() const;
407 
408  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
409 
410  double estimateMaxBleed() const;
411 
412  QString ogrFeatureStyleWidth( double widthScaleFactor ) const;
413 
414  //getters and setters
415  void setLineAngle( double a ) { mLineAngle = a; }
416  double lineAngle() const { return mLineAngle; }
417  void setDistance( double d ) { mDistance = d; }
418  double distance() const { return mDistance; }
419  void setLineWidth( double w );
420  double lineWidth() const { return mLineWidth; }
421  void setColor( const QColor& c );
422  QColor color() const { return mColor; }
423  void setOffset( double offset ) { mOffset = offset; }
424  double offset() const { return mOffset; }
425 
426  void setDistanceUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceUnit = unit; }
427  QgsSymbolV2::OutputUnit distanceUnit() const { return mDistanceUnit; }
428 
429  void setLineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mLineWidthUnit = unit; }
430  QgsSymbolV2::OutputUnit lineWidthUnit() const { return mLineWidthUnit; }
431 
432  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
433  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
434 
437 
438  bool setSubSymbol( QgsSymbolV2* symbol );
440 
441  protected:
443  double mDistance;
446  double mLineWidth;
448  QColor mColor;
450  double mLineAngle;
452  double mOffset;
454 
455  void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context );
456 
457  private:
459  void applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double lineAngle, double distance, double lineWidth, const QColor& color );
460 
463 };
464 
466 {
467  public:
470 
471  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
472  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
473 
474  QString layerType() const;
475 
476  void startRender( QgsSymbolV2RenderContext& context );
477 
478  void stopRender( QgsSymbolV2RenderContext& context );
479 
480  QgsStringMap properties() const;
481 
482  QgsSymbolLayerV2* clone() const;
483 
484  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
485 
486  double estimateMaxBleed() const;
487 
488  //getters and setters
489  double distanceX() const { return mDistanceX; }
490  void setDistanceX( double d ) { mDistanceX = d; }
491 
492  double distanceY() const { return mDistanceY; }
493  void setDistanceY( double d ) { mDistanceY = d; }
494 
495  double displacementX() const { return mDisplacementX; }
496  void setDisplacementX( double d ) { mDisplacementX = d; }
497 
498  double displacementY() const { return mDisplacementY; }
499  void setDisplacementY( double d ) { mDisplacementY = d; }
500 
501  bool setSubSymbol( QgsSymbolV2* symbol );
502  virtual QgsSymbolV2* subSymbol() { return mMarkerSymbol; }
503 
504  void setDistanceXUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceXUnit = unit; }
505  QgsSymbolV2::OutputUnit distanceXUnit() const { return mDistanceXUnit; }
506 
507  void setDistanceYUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceYUnit = unit; }
508  QgsSymbolV2::OutputUnit distanceYUnit() const { return mDistanceYUnit; }
509 
510  void setDisplacementXUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementXUnit = unit; }
511  QgsSymbolV2::OutputUnit displacementXUnit() const { return mDisplacementXUnit; }
512 
513  void setDisplacementYUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementYUnit = unit; }
514  QgsSymbolV2::OutputUnit displacementYUnit() const { return mDisplacementYUnit; }
515 
518 
519  virtual QSet<QString> usedAttributes() const;
520 
521  protected:
523  double mDistanceX;
525  double mDistanceY;
531 
532  void applyDataDefinedSettings( const QgsSymbolV2RenderContext& context );
533 
534  private:
535  void applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double distanceX, double distanceY,
536  double displacementX, double displacementY );
537 };
538 
540 {
541  public:
544 
545  // static stuff
546 
547  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
548  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
549 
550  // implemented from base classes
551 
552  QString layerType() const;
553 
554  void startRender( QgsSymbolV2RenderContext& context );
555 
556  void stopRender( QgsSymbolV2RenderContext& context );
557 
558  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
559 
560  QgsStringMap properties() const;
561 
562  QgsSymbolLayerV2* clone() const;
563 
564  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
565 
566  void setColor( const QColor& color );
567 
569  bool setSubSymbol( QgsSymbolV2* symbol );
570 
571  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); }
573 
574  virtual QSet<QString> usedAttributes() const;
575 
576  protected:
578 };
579 
580 #endif