QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgssymbolv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolv2.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 
16 #ifndef QGSSYMBOLV2_H
17 #define QGSSYMBOLV2_H
18 
19 #include "qgis.h"
20 #include <QList>
21 #include <QMap>
22 #include "qgsmapunitscale.h"
23 
24 class QColor;
25 class QImage;
26 class QPainter;
27 class QSize;
28 class QPointF;
29 class QPolygonF;
30 
31 class QDomDocument;
32 class QDomElement;
33 //class
34 
35 class QgsFeature;
36 class QgsFields;
37 class QgsSymbolLayerV2;
38 class QgsRenderContext;
40 
41 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
42 
43 class CORE_EXPORT QgsSymbolV2
44 {
45  public:
46 
48  {
49  MM = 0,
51  Mixed //mixed units in symbol layers
52  };
53 
55  {
58  Fill
59  };
60 
62  {
64  ScaleDiameter
65  };
66 
68  {
69  DataDefinedSizeScale = 1,
70  DataDefinedRotation = 2
71  };
72 
73  virtual ~QgsSymbolV2();
74 
76  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
77 
78  SymbolType type() const { return mType; }
79 
80  // symbol layers handling
81 
82  QgsSymbolLayerV2* symbolLayer( int layer );
83 
84  int symbolLayerCount() { return mLayers.count(); }
85 
87  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
88 
90  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
91 
93  bool deleteSymbolLayer( int index );
94 
96  QgsSymbolLayerV2* takeSymbolLayer( int index );
97 
99  bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
100 
101  void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
102  void stopRender( QgsRenderContext& context );
103 
104  void setColor( const QColor& color );
105  QColor color() const;
106 
110  void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );
111 
112  QImage asImage( QSize size, QgsRenderContext* customContext = 0 );
113 
114  QImage bigSymbolPreviewImage();
115 
116  QString dump() const;
117 
118  virtual QgsSymbolV2* clone() const = 0;
119 
120  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
121 
122  QgsSymbolV2::OutputUnit outputUnit() const;
123  void setOutputUnit( QgsSymbolV2::OutputUnit u );
124 
125  QgsMapUnitScale mapUnitScale() const;
126  void setMapUnitScale( const QgsMapUnitScale& scale );
127 
129  qreal alpha() const { return mAlpha; }
131  void setAlpha( qreal alpha ) { mAlpha = alpha; }
132 
133  void setRenderHints( int hints ) { mRenderHints = hints; }
134  int renderHints() const { return mRenderHints; }
135 
136  QSet<QString> usedAttributes() const;
137 
138  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
139  const QgsVectorLayer* layer() const { return mLayer; }
140 
141  protected:
142  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
143 
144  QgsSymbolLayerV2List cloneLayers() const;
145 
148  bool isSymbolLayerCompatible( SymbolType t );
149 
152 
154  qreal mAlpha;
155 
157 
158  const QgsVectorLayer* mLayer; //current vectorlayer
159 };
160 
162 
163 class CORE_EXPORT QgsSymbolV2RenderContext
164 {
165  public:
166  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields* = 0, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
168 
169  QgsRenderContext& renderContext() { return mRenderContext; }
170  const QgsRenderContext& renderContext() const { return mRenderContext; }
171  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
172 
173  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
174  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
175 
176  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
177  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
178 
180  qreal alpha() const { return mAlpha; }
182  void setAlpha( qreal alpha ) { mAlpha = alpha; }
183 
184  bool selected() const { return mSelected; }
185  void setSelected( bool selected ) { mSelected = selected; }
186 
187  int renderHints() const { return mRenderHints; }
188  void setRenderHints( int hints ) { mRenderHints = hints; }
189 
190  void setFeature( const QgsFeature* f ) { mFeature = f; }
192  const QgsFeature* feature() const { return mFeature; }
193 
198  const QgsFields* fields() const { return mFields; }
199 
200  double outputLineWidth( double width ) const;
201  double outputPixelSize( double size ) const;
202 
203  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
205 
206  private:
207  QgsRenderContext& mRenderContext;
208  QgsSymbolV2::OutputUnit mOutputUnit;
209  QgsMapUnitScale mMapUnitScale;
210  qreal mAlpha;
211  bool mSelected;
212  int mRenderHints;
213  const QgsFeature* mFeature; //current feature
214  const QgsFields* mFields;
215 };
216 
217 
218 
220 
221 
222 
223 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
224 {
225  public:
229  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
230 
232 
233  void setAngle( double angle );
234  double angle();
235 
236  void setSize( double size );
237  double size();
238 
239  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
240  ScaleMethod scaleMethod();
241 
242  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
243 
244  virtual QgsSymbolV2* clone() const;
245 };
246 
247 
248 
249 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
250 {
251  public:
255  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
256 
258 
259  void setWidth( double width );
260  double width();
261 
262  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
263 
264  virtual QgsSymbolV2* clone() const;
265 };
266 
267 
268 
269 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
270 {
271  public:
275  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
276 
278  void setAngle( double angle );
279  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
280 
281  virtual QgsSymbolV2* clone() const;
282 };
283 
284 #endif
285 
286 
287 /*
288 
289 QgsSymbolV2* ps = new QgsPointSymbol();
290 
291 // ----
292 
293 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
294 
295 // (or)
296 
297 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
298 
299 // (or)
300 
301 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
302 QgsLineSymbol* s = new LineSymbol( [ sl ] );
303 
304 // ----
305 
306 rend = QgsSingleSymbolRenderer( new LineSymbol() );
307 */
308 
309 
static unsigned index
int renderHints() const
Definition: qgssymbolv2.h:187
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:158
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:182
SymbolType type() const
Definition: qgssymbolv2.h:78
virtual QgsSymbolV2 * clone() const =0
Container of fields for a vector layer.
Definition: qgsfield.h:172
GeometryType
Definition: qgis.h:155
void setRenderHints(int hints)
Definition: qgssymbolv2.h:188
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
SymbolType mType
Definition: qgssymbolv2.h:150
QMap< QString, QString > QgsStringMap
Definition: qgis.h:412
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbolv2.h:177
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:139
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:180
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:151
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.h:176
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:192
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:129
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:138
int symbolLayerCount()
Definition: qgssymbolv2.h:84
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:154
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:190
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:174
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:173
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 setSelected(bool selected)
Definition: qgssymbolv2.h:185
Contains information about the context of a rendering operation.
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:39
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:169
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:198
void setRenderHints(int hints)
Definition: qgssymbolv2.h:133
bool selected() const
Definition: qgssymbolv2.h:184
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:170
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:131
int mRenderHints
Definition: qgssymbolv2.h:156
int renderHints() const
Definition: qgssymbolv2.h:134