QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 QgsExpression;
42 class QgsRenderContext;
43 
44 class CORE_EXPORT QgsSymbolLayerV2
45 {
46  public:
47 
48  // not necessarily supported by all symbol layers...
49  virtual void setColor( const QColor& color ) { mColor = color; }
50  virtual QColor color() const { return mColor; }
51 
52  virtual ~QgsSymbolLayerV2() { removeDataDefinedProperties(); }
53 
54  virtual QString layerType() const = 0;
55 
56  virtual void startRender( QgsSymbolV2RenderContext& context ) = 0;
57  virtual void stopRender( QgsSymbolV2RenderContext& context ) = 0;
58 
59  virtual QgsSymbolLayerV2* clone() const = 0;
60 
61  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
62  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "SymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
63 
64  virtual QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const { Q_UNUSED( mmScaleFactor ); Q_UNUSED( mapUnitScaleFactor ); return QString(); }
65 
66  virtual QgsStringMap properties() const = 0;
67 
68  virtual void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) = 0;
69 
70  virtual QgsSymbolV2* subSymbol() { return NULL; }
71  // set layer's subsymbol. takes ownership of the passed symbol
72  virtual bool setSubSymbol( QgsSymbolV2* symbol ) { delete symbol; return false; }
73 
74  QgsSymbolV2::SymbolType type() const { return mType; }
75 
76  void setLocked( bool locked ) { mLocked = locked; }
77  bool isLocked() const { return mLocked; }
78 
79  virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); } //= 0;
80  virtual QgsSymbolV2::OutputUnit outputUnit() const { return QgsSymbolV2::Mixed; } //= 0;
81 
82  // used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
83  void setRenderingPass( int renderingPass ) { mRenderingPass = renderingPass; }
84  int renderingPass() const { return mRenderingPass; }
85 
86  // symbol layers normally only use additional attributes to provide data defined settings
87  virtual QSet<QString> usedAttributes() const;
88 
89  virtual const QgsExpression* dataDefinedProperty( const QString& property ) const;
90  virtual QString dataDefinedPropertyString( const QString& property ) const;
91  virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
92  virtual void removeDataDefinedProperty( const QString& property );
93  virtual void removeDataDefinedProperties();
94 
95  protected:
96  QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
97  : mType( type ), mLocked( locked ), mRenderingPass( 0 ) {}
98 
100  bool mLocked;
101  QColor mColor;
103 
104  QMap< QString, QgsExpression* > mDataDefinedProperties;
105 
106  // Configuration of selected symbology implementation
107  static const bool selectionIsOpaque = true; // Selection ignores symbol alpha
108  static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology
109  static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
110 
111  virtual void prepareExpressions( const QgsVectorLayer* vl );
112  virtual QgsExpression* expression( const QString& property );
114  void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
116  void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const;
117 };
118 
120 
121 class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
122 {
123  public:
124  virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0;
125 
126  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
127 
128  void setAngle( double angle ) { mAngle = angle; }
129  double angle() const { return mAngle; }
130 
131  void setSize( double size ) { mSize = size; }
132  double size() const { return mSize; }
133 
134  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod ) { mScaleMethod = scaleMethod; }
135  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
136 
137  void setOffset( QPointF offset ) { mOffset = offset; }
138  QPointF offset() { return mOffset; }
139 
140  virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
141 
142  virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
143  { Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
144 
145  void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
146  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
147 
148  void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; }
149  QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; }
150 
151  virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit );
152  virtual QgsSymbolV2::OutputUnit outputUnit() const;
153 
154  protected:
155  QgsMarkerSymbolLayerV2( bool locked = false );
156  void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY );
157  static QPointF _rotatedOffset( const QPointF& offset, double angle );
158 
159  double mAngle;
160  double mSize;
162  QPointF mOffset;
165 };
166 
167 class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
168 {
169  public:
170  virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
171 
173  virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
174 
175  virtual void setWidth( double width ) { mWidth = width; }
176  virtual double width() const { return mWidth; }
177 
178  void setWidthUnit( QgsSymbolV2::OutputUnit unit ) { mWidthUnit = unit; }
179  QgsSymbolV2::OutputUnit widthUnit() const { return mWidthUnit; }
180 
181  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
182 
183  protected:
184  QgsLineSymbolLayerV2( bool locked = false );
185 
186  double mWidth;
188 };
189 
190 class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
191 {
192  public:
193  virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
194 
195  void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
196 
197  void setAngle( double angle ) { mAngle = angle; }
198  double angle() const { return mAngle; }
199 
200  protected:
201  QgsFillSymbolLayerV2( bool locked = false );
203  void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings );
204 
205  double mAngle;
206 };
207 
208 class QgsSymbolLayerV2Widget; // why does SIP fail, when this isn't here
209 
210 #endif