QGIS API Documentation  2.5.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 
35 #include "qgssymbollayerv2utils.h" // QgsStringMap
36 
37 class QPainter;
38 class QSize;
39 class QPolygonF;
40 
41 class QgsDxfExport;
42 class QgsExpression;
43 class QgsRenderContext;
44 
45 class CORE_EXPORT QgsSymbolLayerV2
46 {
47  public:
48 
49  // not necessarily supported by all symbol layers...
50  virtual QColor color() const { return mColor; }
51  virtual void setColor( const QColor& color ) { mColor = color; }
54  virtual void setOutlineColor( const QColor& color ) { Q_UNUSED( color ); }
57  virtual QColor outlineColor() const { return QColor(); }
60  virtual void setFillColor( const QColor& color ) { Q_UNUSED( color ); }
63  virtual QColor fillColor() const { return QColor(); }
64 
65  virtual ~QgsSymbolLayerV2() { removeDataDefinedProperties(); }
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 
127  virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
128 
129  virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
130  virtual Qt::PenStyle dxfPenStyle() const;
131  virtual QColor dxfBrushColor( const QgsSymbolV2RenderContext& context ) const;
132  virtual Qt::BrushStyle dxfBrushStyle() const;
133 
134  protected:
135  QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
136  : mType( type ), mLocked( locked ), mRenderingPass( 0 ) {}
137 
139  bool mLocked;
140  QColor mColor;
142 
143  QMap< QString, QgsExpression* > mDataDefinedProperties;
144 
145  // Configuration of selected symbology implementation
146  static const bool selectionIsOpaque = true; // Selection ignores symbol alpha
147  static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology
148  static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
149 
150  virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 );
151  virtual QgsExpression* expression( const QString& property ) const;
153  void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
155  void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const;
156 };
157 
159 
160 class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
161 {
162  public:
163 
165  {
168  Right
169  };
170 
172  {
175  Bottom
176  };
177 
178  void startRender( QgsSymbolV2RenderContext& context );
179 
180  virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0;
181 
182  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
183 
184  void setAngle( double angle ) { mAngle = angle; }
185  double angle() const { return mAngle; }
186 
187  void setSize( double size ) { mSize = size; }
188  double size() const { return mSize; }
189 
190  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod ) { mScaleMethod = scaleMethod; }
191  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
192 
193  void setOffset( QPointF offset ) { mOffset = offset; }
194  QPointF offset() { return mOffset; }
195 
196  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
197 
198  virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
199  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
200 
201  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
202  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
203 
204  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
205  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
206 
207  void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; }
208  QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; }
209 
210  void setSizeMapUnitScale( const QgsMapUnitScale& scale ) { mSizeMapUnitScale = scale; }
211  const QgsMapUnitScale& sizeMapUnitScale() const { return mSizeMapUnitScale; }
212 
215 
216  void setMapUnitScale( const QgsMapUnitScale& scale );
218 
219  void setHorizontalAnchorPoint( HorizontalAnchorPoint h ) { mHorizontalAnchorPoint = h; }
220  HorizontalAnchorPoint horizontalAnchorPoint() const { return mHorizontalAnchorPoint; }
221 
222  void setVerticalAnchorPoint( VerticalAnchorPoint v ) { mVerticalAnchorPoint = v; }
223  VerticalAnchorPoint verticalAnchorPoint() const { return mVerticalAnchorPoint; }
224 
225  protected:
226  QgsMarkerSymbolLayerV2( bool locked = false );
227 
228  //handles marker offset and anchor point shift together
229  void markerOffset( const QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ) const;
230 
231  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height, double& offsetX, double& offsetY ) const;
232 
234  void markerOffset( const QgsSymbolV2RenderContext& context, double width, double height,
235  QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
236  double& offsetX, double& offsetY,
237  const QgsMapUnitScale &widthMapUnitScale, const QgsMapUnitScale &heightMapUnitScale ) const;
238 
239  static QPointF _rotatedOffset( const QPointF& offset, double angle );
240 
241  double mAngle;
242  double mSize;
245  QPointF mOffset;
251 
252  private:
253  static QgsMarkerSymbolLayerV2::HorizontalAnchorPoint decodeHorizontalAnchorPoint( const QString& str );
254  static QgsMarkerSymbolLayerV2::VerticalAnchorPoint decodeVerticalAnchorPoint( const QString& str );
255 
256  QgsExpression* mOffsetExpression;
257  QgsExpression* mHorizontalAnchorExpression;
258  QgsExpression* mVerticalAnchorExpression;
259 };
260 
261 class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
262 {
263  public:
264  virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
265 
266  virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
267 
268  virtual void setWidth( double width ) { mWidth = width; }
269  virtual double width() const { return mWidth; }
270 
271  void setWidthUnit( QgsSymbolV2::OutputUnit unit ) { mWidthUnit = unit; }
272  QgsSymbolV2::OutputUnit widthUnit() const { return mWidthUnit; }
273 
274  void setWidthMapUnitScale( const QgsMapUnitScale& scale ) { mWidthMapUnitScale = scale; }
275  const QgsMapUnitScale& widthMapUnitScale() const { return mWidthMapUnitScale; }
276 
279 
280  void setMapUnitScale( const QgsMapUnitScale& scale );
282 
283  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
284 
285  virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
286 
287  protected:
288  QgsLineSymbolLayerV2( bool locked = false );
289 
290  double mWidth;
293 };
294 
295 class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
296 {
297  public:
298  virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
299 
300  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
301 
302  void setAngle( double angle ) { mAngle = angle; }
303  double angle() const { return mAngle; }
304 
305  protected:
306  QgsFillSymbolLayerV2( bool locked = false );
308  void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
309 
310  double mAngle;
311 };
312 
313 class QgsSymbolLayerV2Widget; // why does SIP fail, when this isn't here
314 
315 #endif
316 
317 
double angle() const
Definition: qgssymbollayerv2.h:185
QgsSymbolV2::SymbolType mType
Definition: qgssymbollayerv2.h:138
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:87
VerticalAnchorPoint verticalAnchorPoint() const
Definition: qgssymbollayerv2.h:223
virtual void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbollayerv2.h:101
virtual ~QgsSymbolLayerV2()
Definition: qgssymbollayerv2.h:65
void setLocked(bool locked)
Definition: qgssymbollayerv2.h:89
Definition: qgssymbollayerv2.h:166
virtual QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbollayerv2.h:99
QMap< QString, QgsExpression * > mDataDefinedProperties
Definition: qgssymbollayerv2.h:143
OutputUnit
Definition: qgssymbolv2.h:47
virtual void setOutputUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgssymbollayerv2.h:98
QgsMapUnitScale mSizeMapUnitScale
Definition: qgssymbollayerv2.h:244
bool mLocked
Definition: qgssymbollayerv2.h:139
virtual double dxfWidth(const QgsDxfExport &e, const QgsSymbolV2RenderContext &context) const
Definition: qgssymbollayerv2.cpp:97
QPointF offset()
Definition: qgssymbollayerv2.h:194
virtual double width() const
Definition: qgssymbollayerv2.h:269
HorizontalAnchorPoint horizontalAnchorPoint() const
Definition: qgssymbollayerv2.h:220
virtual void setOutlineColor(const QColor &color)
Set outline color.
Definition: qgssymbollayerv2.h:54
Definition: qgssymbollayerv2.h:173
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
Definition: qgssymbollayerv2.h:190
void setOffset(QPointF offset)
Definition: qgssymbollayerv2.h:193
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
Definition: qgssymbollayerv2.h:219
Container of fields for a vector layer.
Definition: qgsfield.h:172
void setVerticalAnchorPoint(VerticalAnchorPoint v)
Definition: qgssymbollayerv2.h:222
Definition: qgssymbollayerv2.h:295
QgsSymbolV2::OutputUnit sizeUnit() const
Definition: qgssymbollayerv2.h:208
Definition: qgssymbollayerv2.h:167
QgsSymbolLayerV2(QgsSymbolV2::SymbolType type, bool locked=false)
Definition: qgssymbollayerv2.h:135
Definition: qgssymbollayerv2.h:45
QgsMapUnitScale mWidthMapUnitScale
Definition: qgssymbollayerv2.h:292
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)
Definition: qgssymbollayerv2.h:204
virtual QColor fillColor() const
Get fill color.
Definition: qgssymbollayerv2.h:63
QMap< QString, QString > QgsStringMap
Definition: qgis.h:412
void setWidthUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgssymbollayerv2.h:271
Definition: qgssymbollayerv2.h:174
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgssymbollayerv2.h:201
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
Definition: qgssymbollayerv2.h:96
double mAngle
Definition: qgssymbollayerv2.h:310
virtual void startRender(QgsSymbolV2RenderContext &context)=0
QgsSymbolV2::OutputUnit offsetUnit() const
Definition: qgssymbollayerv2.h:202
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
Definition: qgssymbollayerv2.h:198
Definition: qgssymbolv2.h:51
virtual void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
Definition: qgssymbollayerv2.h:74
QgsSymbolV2::OutputUnit mWidthUnit
Definition: qgssymbollayerv2.h:291
void setRenderingPass(int renderingPass)
Definition: qgssymbollayerv2.h:105
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbollayerv2.h:274
virtual void setWidth(double width)
Definition: qgssymbollayerv2.h:268
void setAngle(double angle)
Definition: qgssymbollayerv2.h:302
QgsSymbolV2::ScaleMethod mScaleMethod
Definition: qgssymbollayerv2.h:248
void setSizeUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgssymbollayerv2.h:207
const QgsMapUnitScale & sizeMapUnitScale() const
Definition: qgssymbollayerv2.h:211
virtual QColor color() const
Definition: qgssymbollayerv2.h:50
HorizontalAnchorPoint mHorizontalAnchorPoint
Definition: qgssymbollayerv2.h:249
Definition: qgssymbollayerv2widget.h:26
bool hasDataDefinedProperties() const
Definition: qgssymbollayerv2.h:116
Definition: qgssymbolv2.h:43
double mAngle
Definition: qgssymbollayerv2.h:241
QgsSymbolV2::ScaleMethod scaleMethod() const
Definition: qgssymbollayerv2.h:191
double size() const
Definition: qgssymbollayerv2.h:188
QgsSymbolV2::SymbolType type() const
Definition: qgssymbollayerv2.h:87
virtual void setFillColor(const QColor &color)
Set fill color.
Definition: qgssymbollayerv2.h:60
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)
int mRenderingPass
Definition: qgssymbollayerv2.h:141
int renderingPass() const
Definition: qgssymbollayerv2.h:106
virtual QString layerType() const =0
virtual QgsSymbolV2 * subSymbol()
Definition: qgssymbollayerv2.h:83
SymbolType
Definition: qgssymbolv2.h:54
virtual QColor outlineColor() const
Get outline color.
Definition: qgssymbollayerv2.h:57
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
VerticalAnchorPoint
Definition: qgssymbollayerv2.h:171
const QgsMapUnitScale & offsetMapUnitScale() const
Definition: qgssymbollayerv2.h:205
ScaleMethod
Definition: qgssymbolv2.h:61
Definition: qgsmapunitscale.h:24
bool isLocked() const
Definition: qgssymbollayerv2.h:90
const QgsMapUnitScale & widthMapUnitScale() const
Definition: qgssymbollayerv2.h:275
virtual QgsMapUnitScale mapUnitScale() const
Definition: qgssymbollayerv2.h:102
QgsSymbolV2::OutputUnit mOffsetUnit
Definition: qgssymbollayerv2.h:246
virtual void setColor(const QColor &color)
Definition: qgssymbollayerv2.h:51
Definition: qgssymbollayerv2.h:160
VerticalAnchorPoint mVerticalAnchorPoint
Definition: qgssymbollayerv2.h:250
QgsSymbolV2::OutputUnit mSizeUnit
Definition: qgssymbollayerv2.h:243
QgsMapUnitScale mOffsetMapUnitScale
Definition: qgssymbollayerv2.h:247
QColor mColor
Definition: qgssymbollayerv2.h:140
Definition: qgssymbolv2.h:163
HorizontalAnchorPoint
Definition: qgssymbollayerv2.h:164
double mSize
Definition: qgssymbollayerv2.h:242
virtual void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size)=0
void setSize(double size)
Definition: qgssymbollayerv2.h:187
void setAngle(double angle)
Definition: qgssymbollayerv2.h:184
double size
Definition: qgssvgcache.cpp:77
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
Definition: qgssymbollayerv2.h:85
QPointF mOffset
Definition: qgssymbollayerv2.h:245
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbollayerv2.h:210
double angle() const
Definition: qgssymbollayerv2.h:303
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
Definition: qgssymbollayerv2.h:77
double mWidth
Definition: qgssymbollayerv2.h:290
QgsSymbolV2::OutputUnit widthUnit() const
Definition: qgssymbollayerv2.h:272
Definition: qgssymbollayerv2.h:261
Definition: qgsdxfexport.h:32