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  Q_DECL_DEPRECATED virtual QVariant evaluateDataDefinedProperty( const QString& property, const QgsFeature* feature, const QVariant& defaultVal = QVariant(), bool *ok = 0 ) const;
203 
217  virtual QVariant evaluateDataDefinedProperty( const QString& property, const QgsSymbolV2RenderContext& context, const QVariant& defaultVal = QVariant(), bool *ok = 0 ) const;
218 
219  virtual bool writeDxf( QgsDxfExport& e,
220  double mmMapUnitScaleFactor,
221  const QString& layerName,
222  const QgsSymbolV2RenderContext* context,
223  const QgsFeature* f,
224  const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
225 
226  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
227  virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
228 
229  virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
230 
231  virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
232  virtual Qt::PenStyle dxfPenStyle() const;
233  virtual QColor dxfBrushColor( const QgsSymbolV2RenderContext& context ) const;
234  virtual Qt::BrushStyle dxfBrushStyle() const;
235 
241  QgsPaintEffect* paintEffect() const;
242 
248  void setPaintEffect( QgsPaintEffect* effect );
249 
250  protected:
251  QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );
252 
254  bool mLocked;
257 
261 
262  // Configuration of selected symbology implementation
263  static const bool selectionIsOpaque = true; // Selection ignores symbol alpha
264  static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology
265  static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
266 
272  Q_DECL_DEPRECATED virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 );
273 
279  virtual void prepareExpressions( const QgsSymbolV2RenderContext& context );
280 
284  Q_DECL_DEPRECATED virtual QgsExpression* expression( const QString& property ) const;
285 
290  void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
291 
297  void restoreDataDefinedProperties( const QgsStringMap& stringMap );
298 
302  void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const;
303 
308  void copyPaintEffect( QgsSymbolLayerV2* destLayer ) const;
309 
310  static const QString EXPR_SIZE;
311  static const QString EXPR_ANGLE;
312  static const QString EXPR_NAME;
313  static const QString EXPR_COLOR;
317  static const QString EXPR_FILL;
318  static const QString EXPR_OUTLINE;
319  static const QString EXPR_OFFSET;
320  static const QString EXPR_CHAR;
321  static const QString EXPR_FILL_COLOR;
323  static const QString EXPR_WIDTH;
324  static const QString EXPR_HEIGHT;
325  static const QString EXPR_SYMBOL_NAME;
326  static const QString EXPR_ROTATION;
327  static const QString EXPR_FILL_STYLE;
330  static const QString EXPR_JOIN_STYLE;
332  static const QString EXPR_COLOR2;
333  static const QString EXPR_LINEANGLE;
336  static const QString EXPR_SPREAD;
343  static const QString EXPR_BLUR_RADIUS;
344  static const QString EXPR_DISTANCE;
348  static const QString EXPR_SVG_FILE;
352  static const QString EXPR_LINEWIDTH;
353  static const QString EXPR_DISTANCE_X;
354  static const QString EXPR_DISTANCE_Y;
357  static const QString EXPR_FILE;
358  static const QString EXPR_ALPHA;
359  static const QString EXPR_CUSTOMDASH;
360  static const QString EXPR_LINE_STYLE;
361  static const QString EXPR_JOINSTYLE; //near duplicate is required to maintain project compatibility
362  static const QString EXPR_CAPSTYLE;
363  static const QString EXPR_PLACEMENT;
364  static const QString EXPR_INTERVAL;
368 };
369 
371 
372 class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
373 {
374  public:
375 
377  {
380  Right
381  };
382 
384  {
387  Bottom
388  };
389 
390  void startRender( QgsSymbolV2RenderContext& context ) override;
391 
392  virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0;
393 
394  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
395 
396  void setAngle( double angle ) { mAngle = angle; }
397  double angle() const { return mAngle; }
398 
405  void setLineAngle( double lineAngle ) { mLineAngle = lineAngle; }
406 
407  void setSize( double size ) { mSize = size; }
408  double size() const { return mSize; }
409 
410  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod ) { mScaleMethod = scaleMethod; }
411  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
412 
413  void setOffset( QPointF offset ) { mOffset = offset; }
414  QPointF offset() const { return mOffset; }
415 
416  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const override;
417 
418  virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
419  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
420 
421  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
422  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
423 
424  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
425  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
426 
427  void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; }
428  QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; }
429 
430  void setSizeMapUnitScale( const QgsMapUnitScale& scale ) { mSizeMapUnitScale = scale; }
431  const QgsMapUnitScale& sizeMapUnitScale() const { return mSizeMapUnitScale; }
432 
433  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
434  QgsSymbolV2::OutputUnit outputUnit() const override;
435 
436  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
437  QgsMapUnitScale mapUnitScale() const override;
438 
439  void setHorizontalAnchorPoint( HorizontalAnchorPoint h ) { mHorizontalAnchorPoint = h; }
440  HorizontalAnchorPoint horizontalAnchorPoint() const { return mHorizontalAnchorPoint; }
441 
442  void setVerticalAnchorPoint( VerticalAnchorPoint v ) { mVerticalAnchorPoint = v; }
443  VerticalAnchorPoint verticalAnchorPoint() const { return mVerticalAnchorPoint; }
444 
445  protected:
446  QgsMarkerSymbolLayerV2( bool locked = false );
447 
448  //handles marker offset and anchor point shift together
449  void markerOffset( const QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ) const;
450 
451  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height, double& offsetX, double& offsetY ) const;
452 
454  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height,
455  QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
456  double& offsetX, double& offsetY,
457  const QgsMapUnitScale &widthMapUnitScale, const QgsMapUnitScale &heightMapUnitScale ) const;
458 
459  static QPointF _rotatedOffset( const QPointF& offset, double angle );
460 
461  double mAngle;
462  double mLineAngle;
463  double mSize;
472 
473  private:
474  static QgsMarkerSymbolLayerV2::HorizontalAnchorPoint decodeHorizontalAnchorPoint( const QString& str );
475  static QgsMarkerSymbolLayerV2::VerticalAnchorPoint decodeVerticalAnchorPoint( const QString& str );
476 };
477 
478 class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
479 {
480  public:
481  virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
482 
483  virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
484 
485  virtual void setWidth( double width ) { mWidth = width; }
486  virtual double width() const { return mWidth; }
487 
488  double offset() const { return mOffset; }
489  void setOffset( double offset ) { mOffset = offset; }
490 
491  void setWidthUnit( QgsSymbolV2::OutputUnit unit ) { mWidthUnit = unit; }
492  QgsSymbolV2::OutputUnit widthUnit() const { return mWidthUnit; }
493 
494  void setWidthMapUnitScale( const QgsMapUnitScale& scale ) { mWidthMapUnitScale = scale; }
495  const QgsMapUnitScale& widthMapUnitScale() const { return mWidthMapUnitScale; }
496 
497  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
498  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
499 
500  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
501  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
502 
503  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
504  QgsSymbolV2::OutputUnit outputUnit() const override;
505 
506  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
507  QgsMapUnitScale mapUnitScale() const override;
508 
509  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
510 
511  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const override;
512 
513  protected:
514  QgsLineSymbolLayerV2( bool locked = false );
515 
516  double mWidth;
519  double mOffset;
522 };
523 
524 class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
525 {
526  public:
527  virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
528 
529  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
530 
531  void setAngle( double angle ) { mAngle = angle; }
532  double angle() const { return mAngle; }
533 
534  protected:
535  QgsFillSymbolLayerV2( bool locked = false );
537  void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
538 
539  double mAngle;
540 };
541 
542 class QgsSymbolLayerV2Widget; // why does SIP fail, when this isn't here
543 
544 #endif
545 
546 
QgsSymbolV2::SymbolType mType
static const QString EXPR_DISTANCE_Y
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:88
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:177
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