QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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::ScaleArea
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 
36 class QPainter;
37 class QSize;
38 class QPolygonF;
39 
40 class QgsDxfExport;
41 class QgsExpression;
42 class QgsRenderContext;
43 class QgsPaintEffect;
44 
45 class CORE_EXPORT QgsSymbolLayerV2
46 {
47  public:
48 
49  virtual ~QgsSymbolLayerV2();
50 
51  // not necessarily supported by all symbol layers...
52  virtual QColor color() const { return mColor; }
53  virtual void setColor( const QColor& color ) { mColor = color; }
56  virtual void setOutlineColor( const QColor& color ) { Q_UNUSED( color ); }
59  virtual QColor outlineColor() const { return QColor(); }
62  virtual void setFillColor( const QColor& color ) { Q_UNUSED( color ); }
65  virtual QColor fillColor() const { return QColor(); }
66 
67  virtual QString layerType() const = 0;
68 
69  virtual void startRender( QgsSymbolV2RenderContext& context ) = 0;
70  virtual void stopRender( QgsSymbolV2RenderContext& context ) = 0;
71 
72  virtual QgsSymbolLayerV2* clone() const = 0;
73 
74  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
75  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "SymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
76 
77  virtual QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const { Q_UNUSED( mmScaleFactor ); Q_UNUSED( mapUnitScaleFactor ); return QString(); }
78 
79  virtual QgsStringMap properties() const = 0;
80 
81  virtual void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) = 0;
82 
83  virtual QgsSymbolV2* subSymbol() { return NULL; }
84  // set layer's subsymbol. takes ownership of the passed symbol
85  virtual bool setSubSymbol( QgsSymbolV2* symbol ) { delete symbol; return false; }
86 
87  QgsSymbolV2::SymbolType type() const { return mType; }
88 
89  void setLocked( bool locked ) { mLocked = locked; }
90  bool isLocked() const { return mLocked; }
91 
96  virtual double estimateMaxBleed() const { return 0; }
97 
98  virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); } //= 0;
99  virtual QgsSymbolV2::OutputUnit outputUnit() const { return QgsSymbolV2::Mixed; } //= 0;
100 
101  virtual void setMapUnitScale( const QgsMapUnitScale& scale ) { Q_UNUSED( scale ); } //= 0;
102  virtual QgsMapUnitScale mapUnitScale() const { return QgsMapUnitScale(); } //= 0;
103 
104  // used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
105  void setRenderingPass( int renderingPass ) { mRenderingPass = renderingPass; }
106  int renderingPass() const { return mRenderingPass; }
107 
108  // symbol layers normally only use additional attributes to provide data defined settings
109  virtual QSet<QString> usedAttributes() const;
110 
111  virtual const QgsExpression* dataDefinedProperty( const QString& property ) const;
112  virtual QString dataDefinedPropertyString( const QString& property ) const;
113  virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
114  virtual void removeDataDefinedProperty( const QString& property );
115  virtual void removeDataDefinedProperties();
116  bool hasDataDefinedProperties() const { return mDataDefinedProperties.size() > 0; }
117 
118  virtual bool writeDxf( QgsDxfExport& e,
119  double mmMapUnitScaleFactor,
120  const QString& layerName,
121  const QgsSymbolV2RenderContext* context,
122  const QgsFeature* f,
123  const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
124 
125  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
126  virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
127 
128  virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
129 
130  virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
131  virtual Qt::PenStyle dxfPenStyle() const;
132  virtual QColor dxfBrushColor( const QgsSymbolV2RenderContext& context ) const;
133  virtual Qt::BrushStyle dxfBrushStyle() const;
134 
140  QgsPaintEffect* paintEffect() const;
141 
147  void setPaintEffect( QgsPaintEffect* effect );
148 
149  protected:
150  QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );
151 
153  bool mLocked;
154  QColor mColor;
156 
157  QMap< QString, QgsExpression* > mDataDefinedProperties;
159 
160  // Configuration of selected symbology implementation
161  static const bool selectionIsOpaque = true; // Selection ignores symbol alpha
162  static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology
163  static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
164 
165  virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 );
166  virtual QgsExpression* expression( const QString& property ) const;
168  void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
170  void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const;
175  void copyPaintEffect( QgsSymbolLayerV2* destLayer ) const;
176 };
177 
179 
180 class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
181 {
182  public:
183 
185  {
188  Right
189  };
190 
192  {
195  Bottom
196  };
197 
198  void startRender( QgsSymbolV2RenderContext& context ) override;
199 
200  virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0;
201 
202  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
203 
204  void setAngle( double angle ) { mAngle = angle; }
205  double angle() const { return mAngle; }
206 
207  void setSize( double size ) { mSize = size; }
208  double size() const { return mSize; }
209 
210  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod ) { mScaleMethod = scaleMethod; }
211  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
212 
213  void setOffset( QPointF offset ) { mOffset = offset; }
214  QPointF offset() { return mOffset; }
215 
216  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const override;
217 
218  virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
219  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
220 
221  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
222  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
223 
224  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
225  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
226 
227  void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; }
228  QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; }
229 
230  void setSizeMapUnitScale( const QgsMapUnitScale& scale ) { mSizeMapUnitScale = scale; }
231  const QgsMapUnitScale& sizeMapUnitScale() const { return mSizeMapUnitScale; }
232 
233  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
234  QgsSymbolV2::OutputUnit outputUnit() const override;
235 
236  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
237  QgsMapUnitScale mapUnitScale() const override;
238 
239  void setHorizontalAnchorPoint( HorizontalAnchorPoint h ) { mHorizontalAnchorPoint = h; }
240  HorizontalAnchorPoint horizontalAnchorPoint() const { return mHorizontalAnchorPoint; }
241 
242  void setVerticalAnchorPoint( VerticalAnchorPoint v ) { mVerticalAnchorPoint = v; }
243  VerticalAnchorPoint verticalAnchorPoint() const { return mVerticalAnchorPoint; }
244 
245  protected:
246  QgsMarkerSymbolLayerV2( bool locked = false );
247 
248  //handles marker offset and anchor point shift together
249  void markerOffset( const QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ) const;
250 
251  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height, double& offsetX, double& offsetY ) const;
252 
254  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height,
255  QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
256  double& offsetX, double& offsetY,
257  const QgsMapUnitScale &widthMapUnitScale, const QgsMapUnitScale &heightMapUnitScale ) const;
258 
259  static QPointF _rotatedOffset( const QPointF& offset, double angle );
260 
261  double mAngle;
262  double mSize;
265  QPointF mOffset;
271 
272  private:
273  static QgsMarkerSymbolLayerV2::HorizontalAnchorPoint decodeHorizontalAnchorPoint( const QString& str );
274  static QgsMarkerSymbolLayerV2::VerticalAnchorPoint decodeVerticalAnchorPoint( const QString& str );
275 
276  QgsExpression* mOffsetExpression;
277  QgsExpression* mHorizontalAnchorExpression;
278  QgsExpression* mVerticalAnchorExpression;
279 };
280 
281 class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
282 {
283  public:
284  virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
285 
286  virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
287 
288  virtual void setWidth( double width ) { mWidth = width; }
289  virtual double width() const { return mWidth; }
290 
291  double offset() const { return mOffset; }
292  void setOffset( double offset ) { mOffset = offset; }
293 
294  void setWidthUnit( QgsSymbolV2::OutputUnit unit ) { mWidthUnit = unit; }
295  QgsSymbolV2::OutputUnit widthUnit() const { return mWidthUnit; }
296 
297  void setWidthMapUnitScale( const QgsMapUnitScale& scale ) { mWidthMapUnitScale = scale; }
298  const QgsMapUnitScale& widthMapUnitScale() const { return mWidthMapUnitScale; }
299 
300  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
301  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
302 
303  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
304  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
305 
306  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
307  QgsSymbolV2::OutputUnit outputUnit() const override;
308 
309  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
310  QgsMapUnitScale mapUnitScale() const override;
311 
312  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
313 
314  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const override;
315 
316  protected:
317  QgsLineSymbolLayerV2( bool locked = false );
318 
319  double mWidth;
322  double mOffset;
325 };
326 
327 class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
328 {
329  public:
330  virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
331 
332  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) override;
333 
334  void setAngle( double angle ) { mAngle = angle; }
335  double angle() const { return mAngle; }
336 
337  protected:
338  QgsFillSymbolLayerV2( bool locked = false );
340  void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
341 
342  double mAngle;
343 };
344 
345 class QgsSymbolLayerV2Widget; // why does SIP fail, when this isn't here
346 
347 #endif
348 
349 
QgsSymbolV2::SymbolType mType
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
VerticalAnchorPoint verticalAnchorPoint() const
virtual void setMapUnitScale(const QgsMapUnitScale &scale)
void setLocked(bool locked)
virtual QgsSymbolV2::OutputUnit outputUnit() const
QMap< QString, QgsExpression * > mDataDefinedProperties
virtual void setOutputUnit(QgsSymbolV2::OutputUnit unit)
QgsMapUnitScale mSizeMapUnitScale
virtual double dxfWidth(const QgsDxfExport &e, const QgsSymbolV2RenderContext &context) const
virtual double width() const
HorizontalAnchorPoint horizontalAnchorPoint() const
virtual void setOutlineColor(const QColor &color)
Set outline color.
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
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:172
void setVerticalAnchorPoint(VerticalAnchorPoint v)
QgsSymbolV2::OutputUnit sizeUnit() const
QgsMapUnitScale mWidthMapUnitScale
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
QgsMapUnitScale mOffsetMapUnitScale
virtual QColor fillColor() const
Get fill color.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:438
QgsSymbolV2::OutputUnit mOffsetUnit
void setWidthUnit(QgsSymbolV2::OutputUnit unit)
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
QgsSymbolV2::OutputUnit offsetUnit() const
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
virtual void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
void setOffset(double offset)
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
virtual QColor color() const
HorizontalAnchorPoint mHorizontalAnchorPoint
bool hasDataDefinedProperties() const
QgsSymbolV2::ScaleMethod scaleMethod() const
QgsSymbolV2::SymbolType type() const
virtual void setFillColor(const QColor &color)
Set fill color.
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)
int renderingPass() const
virtual QString layerType() const =0
virtual QgsSymbolV2 * subSymbol()
virtual QColor outlineColor() const
Get outline color.
Contains information about the context of a rendering operation.
const QgsMapUnitScale & offsetMapUnitScale() const
QgsSymbolV2::OutputUnit offsetUnit() const
bool isLocked() const
const QgsMapUnitScale & offsetMapUnitScale() const
const QgsMapUnitScale & widthMapUnitScale() const
double offset() const
virtual QgsMapUnitScale mapUnitScale() const
QgsSymbolV2::OutputUnit mOffsetUnit
virtual void setColor(const QColor &color)
VerticalAnchorPoint mVerticalAnchorPoint
QgsSymbolV2::OutputUnit mSizeUnit
QgsMapUnitScale mOffsetMapUnitScale
virtual void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size)=0
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setSize(double size)
void setAngle(double angle)
double size
Definition: qgssvgcache.cpp:77
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
double angle() const
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
QgsSymbolV2::OutputUnit widthUnit() const