QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgssymbollayerv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerv2.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 #ifndef QGSSYMBOLLAYERV2_H
16 #define QGSSYMBOLLAYERV2_H
17 
18 // MSVC compiler doesn't have defined M_PI in math.h
19 #ifndef M_PI
20 #define M_PI 3.14159265358979323846
21 #endif
22 
23 #define DEG2RAD(x) ((x)*M_PI/180)
24 #define DEFAULT_SCALE_METHOD QgsSymbolV2::ScaleDiameter
25 
26 #include <QColor>
27 #include <QMap>
28 #include <QPointF>
29 #include <QSet>
30 #include <QDomDocument>
31 #include <QDomElement>
32 
33 #include "qgssymbolv2.h"
34 #include "qgssymbollayerv2utils.h" // QgsStringMap
35 #include "qgsfield.h"
36 
37 class QPainter;
38 class QSize;
39 class QPolygonF;
40 
41 class QgsDxfExport;
42 class QgsExpression;
43 class QgsDataDefined;
44 class QgsRenderContext;
45 class QgsPaintEffect;
46 
47 class CORE_EXPORT QgsSymbolLayerV2
48 {
49  public:
50 
51  virtual ~QgsSymbolLayerV2();
52 
53  // not necessarily supported by all symbol layers...
54  virtual QColor color() const { return mColor; }
55  virtual void setColor( const QColor& color ) { mColor = color; }
56 
59  virtual void setOutlineColor( const QColor& color ) { Q_UNUSED( color ); }
60 
63  virtual QColor outlineColor() const { return QColor(); }
64 
67  virtual void setFillColor( const QColor& color ) { Q_UNUSED( color ); }
68 
71  virtual QColor fillColor() const { return QColor(); }
72 
73  virtual QString layerType() const = 0;
74 
75  virtual void startRender( QgsSymbolV2RenderContext& context ) = 0;
76  virtual void stopRender( QgsSymbolV2RenderContext& context ) = 0;
77 
78  virtual QgsSymbolLayerV2* clone() const = 0;
79 
80  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
81  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "SymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
82 
83  virtual QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const { Q_UNUSED( mmScaleFactor ); Q_UNUSED( mapUnitScaleFactor ); return QString(); }
84 
85  virtual QgsStringMap properties() const = 0;
86 
87  virtual void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) = 0;
88 
89  virtual QgsSymbolV2* subSymbol() { return NULL; }
90  // set layer's subsymbol. takes ownership of the passed symbol
91  virtual bool setSubSymbol( QgsSymbolV2* symbol ) { delete symbol; return false; }
92 
93  QgsSymbolV2::SymbolType type() const { return mType; }
94 
95  void setLocked( bool locked ) { mLocked = locked; }
96  bool isLocked() const { return mLocked; }
97 
102  virtual double estimateMaxBleed() const { return 0; }
103 
104  virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); } //= 0;
105  virtual QgsSymbolV2::OutputUnit outputUnit() const { return QgsSymbolV2::Mixed; } //= 0;
106 
107  virtual void setMapUnitScale( const QgsMapUnitScale& scale ) { Q_UNUSED( scale ); } //= 0;
108  virtual QgsMapUnitScale mapUnitScale() const { return QgsMapUnitScale(); } //= 0;
109 
110  // used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
111  void setRenderingPass( int renderingPass ) { mRenderingPass = renderingPass; }
112  int renderingPass() const { return mRenderingPass; }
113 
117  virtual QSet<QString> usedAttributes() const;
118 
122  Q_DECL_DEPRECATED virtual const QgsExpression* dataDefinedProperty( const QString& property ) const;
123 
127  Q_DECL_DEPRECATED virtual QString dataDefinedPropertyString( const QString& property ) const;
128 
132  Q_DECL_DEPRECATED virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
133 
142  virtual QgsDataDefined* getDataDefinedProperty( const QString& property ) const;
143 
153  virtual void setDataDefinedProperty( const QString& property, QgsDataDefined* dataDefined );
154 
162  virtual void removeDataDefinedProperty( const QString& property );
163 
169  virtual void removeDataDefinedProperties();
170 
175  virtual bool hasDataDefinedProperties() const;
176 
186  virtual bool hasDataDefinedProperty( const QString& property ) const;
187 
202  virtual QVariant evaluateDataDefinedProperty( const QString& property, const QgsFeature* feature, const QVariant& defaultVal = QVariant(), bool *ok = 0 ) const;
203 
204  virtual bool writeDxf( QgsDxfExport& e,
205  double mmMapUnitScaleFactor,
206  const QString& layerName,
207  const QgsSymbolV2RenderContext* context,
208  const QgsFeature* f,
209  const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
210 
211  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
212  virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
213 
214  virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
215 
216  virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
217  virtual Qt::PenStyle dxfPenStyle() const;
218  virtual QColor dxfBrushColor( const QgsSymbolV2RenderContext& context ) const;
219  virtual Qt::BrushStyle dxfBrushStyle() const;
220 
226  QgsPaintEffect* paintEffect() const;
227 
233  void setPaintEffect( QgsPaintEffect* effect );
234 
235  protected:
236  QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );
237 
239  bool mLocked;
242 
246 
247  // Configuration of selected symbology implementation
248  static const bool selectionIsOpaque = true; // Selection ignores symbol alpha
249  static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology
250  static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
251 
257  virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 );
258 
262  Q_DECL_DEPRECATED virtual QgsExpression* expression( const QString& property ) const;
263 
268  void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
269 
275  void restoreDataDefinedProperties( const QgsStringMap& stringMap );
276 
280  void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const;
281 
286  void copyPaintEffect( QgsSymbolLayerV2* destLayer ) const;
287 
288  static const QString EXPR_SIZE;
289  static const QString EXPR_ANGLE;
290  static const QString EXPR_NAME;
291  static const QString EXPR_COLOR;
295  static const QString EXPR_FILL;
296  static const QString EXPR_OUTLINE;
297  static const QString EXPR_OFFSET;
298  static const QString EXPR_CHAR;
299  static const QString EXPR_FILL_COLOR;
301  static const QString EXPR_WIDTH;
302  static const QString EXPR_HEIGHT;
303  static const QString EXPR_SYMBOL_NAME;
304  static const QString EXPR_ROTATION;
305  static const QString EXPR_FILL_STYLE;
308  static const QString EXPR_JOIN_STYLE;
310  static const QString EXPR_COLOR2;
311  static const QString EXPR_LINEANGLE;
314  static const QString EXPR_SPREAD;
321  static const QString EXPR_BLUR_RADIUS;
322  static const QString EXPR_DISTANCE;
326  static const QString EXPR_SVG_FILE;
330  static const QString EXPR_LINEWIDTH;
331  static const QString EXPR_DISTANCE_X;
332  static const QString EXPR_DISTANCE_Y;
335  static const QString EXPR_FILE;
336  static const QString EXPR_ALPHA;
337  static const QString EXPR_CUSTOMDASH;
338  static const QString EXPR_LINE_STYLE;
339  static const QString EXPR_JOINSTYLE; //near duplicate is required to maintain project compatibility
340  static const QString EXPR_CAPSTYLE;
341  static const QString EXPR_PLACEMENT;
342  static const QString EXPR_INTERVAL;
346 };
347 
349 
350 class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
351 {
352  public:
353 
355  {
358  Right
359  };
360 
362  {
365  Bottom
366  };
367 
368  void startRender( QgsSymbolV2RenderContext& context ) override;
369 
370  virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0;
371 
372  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
373 
374  void setAngle( double angle ) { mAngle = angle; }
375  double angle() const { return mAngle; }
376 
383  void setLineAngle( double lineAngle ) { mLineAngle = lineAngle; }
384 
385  void setSize( double size ) { mSize = size; }
386  double size() const { return mSize; }
387 
388  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod ) { mScaleMethod = scaleMethod; }
389  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
390 
391  void setOffset( QPointF offset ) { mOffset = offset; }
392  QPointF offset() const { return mOffset; }
393 
394  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const override;
395 
396  virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
397  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
398 
399  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
400  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
401 
402  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
403  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
404 
405  void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; }
406  QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; }
407 
408  void setSizeMapUnitScale( const QgsMapUnitScale& scale ) { mSizeMapUnitScale = scale; }
409  const QgsMapUnitScale& sizeMapUnitScale() const { return mSizeMapUnitScale; }
410 
411  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
412  QgsSymbolV2::OutputUnit outputUnit() const override;
413 
414  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
415  QgsMapUnitScale mapUnitScale() const override;
416 
417  void setHorizontalAnchorPoint( HorizontalAnchorPoint h ) { mHorizontalAnchorPoint = h; }
418  HorizontalAnchorPoint horizontalAnchorPoint() const { return mHorizontalAnchorPoint; }
419 
420  void setVerticalAnchorPoint( VerticalAnchorPoint v ) { mVerticalAnchorPoint = v; }
421  VerticalAnchorPoint verticalAnchorPoint() const { return mVerticalAnchorPoint; }
422 
423  protected:
424  QgsMarkerSymbolLayerV2( bool locked = false );
425 
426  //handles marker offset and anchor point shift together
427  void markerOffset( const QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ) const;
428 
429  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height, double& offsetX, double& offsetY ) const;
430 
432  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height,
433  QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
434  double& offsetX, double& offsetY,
435  const QgsMapUnitScale &widthMapUnitScale, const QgsMapUnitScale &heightMapUnitScale ) const;
436 
437  static QPointF _rotatedOffset( const QPointF& offset, double angle );
438 
439  double mAngle;
440  double mLineAngle;
441  double mSize;
450 
451  private:
452  static QgsMarkerSymbolLayerV2::HorizontalAnchorPoint decodeHorizontalAnchorPoint( const QString& str );
453  static QgsMarkerSymbolLayerV2::VerticalAnchorPoint decodeVerticalAnchorPoint( const QString& str );
454 };
455 
456 class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
457 {
458  public:
459  virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
460 
461  virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
462 
463  virtual void setWidth( double width ) { mWidth = width; }
464  virtual double width() const { return mWidth; }
465 
466  double offset() const { return mOffset; }
467  void setOffset( double offset ) { mOffset = offset; }
468 
469  void setWidthUnit( QgsSymbolV2::OutputUnit unit ) { mWidthUnit = unit; }
470  QgsSymbolV2::OutputUnit widthUnit() const { return mWidthUnit; }
471 
472  void setWidthMapUnitScale( const QgsMapUnitScale& scale ) { mWidthMapUnitScale = scale; }
473  const QgsMapUnitScale& widthMapUnitScale() const { return mWidthMapUnitScale; }
474 
475  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
476  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
477 
478  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
479  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
480 
481  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
482  QgsSymbolV2::OutputUnit outputUnit() const override;
483 
484  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
485  QgsMapUnitScale mapUnitScale() const override;
486 
487  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
488 
489  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const override;
490 
491  protected:
492  QgsLineSymbolLayerV2( bool locked = false );
493 
494  double mWidth;
497  double mOffset;
500 };
501 
502 class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
503 {
504  public:
505  virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
506 
507  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
508 
509  void setAngle( double angle ) { mAngle = angle; }
510  double angle() const { return mAngle; }
511 
512  protected:
513  QgsFillSymbolLayerV2( bool locked = false );
515  void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
516 
517  double mAngle;
518 };
519 
520 class QgsSymbolLayerV2Widget; // why does SIP fail, when this isn't here
521 
522 #endif
523 
524 
QgsSymbolV2::SymbolType mType
static const QString EXPR_DISTANCE_Y
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
VerticalAnchorPoint verticalAnchorPoint() const
static const QString EXPR_CHAR
static const QString EXPR_OUTLINE_COLOR
virtual void setMapUnitScale(const QgsMapUnitScale &scale)
void setLocked(bool locked)
static const QString EXPR_DISPLACEMENT_Y
static const QString EXPR_JOINSTYLE
virtual QgsSymbolV2::OutputUnit outputUnit() const
virtual void setOutputUnit(QgsSymbolV2::OutputUnit unit)
QgsMapUnitScale mSizeMapUnitScale
virtual double dxfWidth(const QgsDxfExport &e, const QgsSymbolV2RenderContext &context) const
A container class for data source field mapping or expression.
static const QString EXPR_BORDER_COLOR
virtual double width() const
HorizontalAnchorPoint horizontalAnchorPoint() const
virtual void setOutlineColor(const QColor &color)
Set outline color.
QDomNode appendChild(const QDomNode &newChild)
static const QString EXPR_USE_WHOLE_SHAPE
static const QString EXPR_REFERENCE2_Y
static const QString EXPR_DISPLACEMENT_X
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
QMap< QString, QgsDataDefined * > mDataDefinedProperties
static const QString EXPR_WIDTH
static const QString EXPR_CUSTOMDASH
void setOffset(QPointF offset)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
Base class for visual effects which can be applied to QPicture drawings.
QgsPaintEffect * mPaintEffect
Container of fields for a vector layer.
Definition: qgsfield.h:173
static const QString EXPR_BLUR_RADIUS
void setVerticalAnchorPoint(VerticalAnchorPoint v)
static const QString EXPR_COORDINATE_MODE
static const QString EXPR_COLOR2
QgsSymbolV2::OutputUnit sizeUnit() const
static const QString EXPR_VERTICAL_ANCHOR_POINT
static const QString EXPR_OFFSET_ALONG_LINE
QgsMapUnitScale mWidthMapUnitScale
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
QgsMapUnitScale mOffsetMapUnitScale
virtual QColor fillColor() const
Get fill color.
static const QString EXPR_OFFSET
QgsSymbolV2::OutputUnit mOffsetUnit
void setWidthUnit(QgsSymbolV2::OutputUnit unit)
static const QString EXPR_SIZE
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
virtual void startRender(QgsSymbolV2RenderContext &context)=0
static const QString EXPR_JOIN_STYLE
static const QString EXPR_FILL_STYLE
static const QString EXPR_REFERENCE1_Y
static const QString EXPR_BORDER_STYLE
static const QString EXPR_REFERENCE2_X
static const QString EXPR_REFERENCE2_ISCENTROID
QgsSymbolV2::OutputUnit offsetUnit() const
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
static const QString EXPR_LINEWIDTH
virtual void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
static const QString EXPR_PLACEMENT
static const QString EXPR_FILL_COLOR
static const QString EXPR_SPREAD
void setOffset(double offset)
static const QString EXPR_LINEANGLE
static const QString EXPR_ALPHA
QgsSymbolV2::OutputUnit mWidthUnit
void setRenderingPass(int renderingPass)
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
virtual void setWidth(double width)
void setAngle(double angle)
QgsSymbolV2::ScaleMethod mScaleMethod
void setSizeUnit(QgsSymbolV2::OutputUnit unit)
const QgsMapUnitScale & sizeMapUnitScale() const
static const QString EXPR_FILL
virtual QColor color() const
HorizontalAnchorPoint mHorizontalAnchorPoint
static const QString EXPR_FILE
static const QString EXPR_CAPSTYLE
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
QgsSymbolV2::ScaleMethod scaleMethod() const
static const QString EXPR_OUTLINE_STYLE
QgsSymbolV2::SymbolType type() const
virtual void setFillColor(const QColor &color)
Set fill color.
static const QString EXPR_DISTANCE
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
static const QString EXPR_COLOR
static const QString EXPR_WIDTH_BORDER
static const QString EXPR_SVG_FILE
static const QString EXPR_ANGLE
int renderingPass() const
virtual QString layerType() const =0
static const QString EXPR_DISTANCE_X
static const QString EXPR_REFERENCE1_X
virtual QgsSymbolV2 * subSymbol()
static const QString EXPR_GRADIENT_TYPE
static const QString EXPR_OUTLINE_WIDTH
virtual QColor outlineColor() const
Get outline color.
Contains information about the context of a rendering operation.
static const QString EXPR_SVG_FILL_COLOR
const QgsMapUnitScale & offsetMapUnitScale() const
QgsSymbolV2::OutputUnit offsetUnit() const
bool isLocked() const
const QgsMapUnitScale & offsetMapUnitScale() const
const QgsMapUnitScale & widthMapUnitScale() const
static const QString EXPR_SVG_OUTLINE_COLOR
static const QString EXPR_NAME
double offset() const
static const QString EXPR_IGNORE_RINGS
static const QString EXPR_COLOR_BORDER
virtual QgsMapUnitScale mapUnitScale() const
QDomComment createComment(const QString &value)
static const QString EXPR_REFERENCE1_ISCENTROID
static const QString EXPR_ROTATION
QgsSymbolV2::OutputUnit mOffsetUnit
virtual void setColor(const QColor &color)
VerticalAnchorPoint mVerticalAnchorPoint
QgsSymbolV2::OutputUnit mSizeUnit
QgsMapUnitScale mOffsetMapUnitScale
static const QString EXPR_OUTLINE
static const QString EXPR_SVG_OUTLINE_WIDTH
virtual void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size)=0
static const QString EXPR_SYMBOL_NAME
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setSize(double size)
void setAngle(double angle)
QPointF offset() const
static const QString EXPR_MAX_DISTANCE
static const QString EXPR_LINE_STYLE
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
double angle() const
static const QString EXPR_INTERVAL
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
QgsSymbolV2::OutputUnit widthUnit() const
static const QString EXPR_HEIGHT
static const QString EXPR_HORIZONTAL_ANCHOR_POINT