QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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;
39 class QgsVectorLayer;
40 class QgsPaintEffect;
45 
47 
48 class CORE_EXPORT QgsSymbolV2
49 {
50  public:
51 
53  {
54  MM = 0,
56  Mixed, //mixed units in symbol layers
57  Pixel
58  };
59 
61 
63  {
66  Fill
67  };
68 
70  {
72  ScaleDiameter
73  };
74 
76  {
77  DataDefinedSizeScale = 1,
78  DataDefinedRotation = 2
79  };
80 
81  virtual ~QgsSymbolV2();
82 
84  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
85 
86  SymbolType type() const { return mType; }
87 
88  // symbol layers handling
89 
96  QgsSymbolLayerV2List symbolLayers() { return mLayers; }
97 
105  QgsSymbolLayerV2* symbolLayer( int layer );
106 
113  int symbolLayerCount() { return mLayers.count(); }
114 
122  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
123 
130  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
131 
133  bool deleteSymbolLayer( int index );
134 
141  QgsSymbolLayerV2* takeSymbolLayer( int index );
142 
144  bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
145 
146  void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
147  void stopRender( QgsRenderContext& context );
148 
149  void setColor( const QColor& color );
150  QColor color() const;
151 
155  void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );
156 
158  void exportImage( QString path, QString format, QSize size );
159 
161  QImage asImage( QSize size, QgsRenderContext* customContext = 0 );
162 
163  QImage bigSymbolPreviewImage();
164 
165  QString dump() const;
166 
167  virtual QgsSymbolV2* clone() const = 0;
168 
169  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
170 
171  QgsSymbolV2::OutputUnit outputUnit() const;
172  void setOutputUnit( QgsSymbolV2::OutputUnit u );
173 
174  QgsMapUnitScale mapUnitScale() const;
175  void setMapUnitScale( const QgsMapUnitScale& scale );
176 
178  qreal alpha() const { return mAlpha; }
180  void setAlpha( qreal alpha ) { mAlpha = alpha; }
181 
182  void setRenderHints( int hints ) { mRenderHints = hints; }
183  int renderHints() const { return mRenderHints; }
184 
193  void setClipFeaturesToExtent( bool clipFeaturesToExtent ) { mClipFeaturesToExtent = clipFeaturesToExtent; }
194 
203  double clipFeaturesToExtent() const { return mClipFeaturesToExtent; }
204 
205  QSet<QString> usedAttributes() const;
206 
208  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
209  const QgsVectorLayer* layer() const { return mLayer; }
210 
211  protected:
212  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
213 
214  QgsSymbolLayerV2List cloneLayers() const;
215 
218  bool isSymbolLayerCompatible( SymbolType t );
219 
222 
224  qreal mAlpha;
225 
228 
229  const QgsVectorLayer* mLayer; //current vectorlayer
230 
231 };
232 
234 
235 class CORE_EXPORT QgsSymbolV2RenderContext
236 {
237  public:
238  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields* fields = 0, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
240 
241  QgsRenderContext& renderContext() { return mRenderContext; }
242  const QgsRenderContext& renderContext() const { return mRenderContext; }
243 
244  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
245  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
246 
247  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
248  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
249 
251  qreal alpha() const { return mAlpha; }
253  void setAlpha( qreal alpha ) { mAlpha = alpha; }
254 
255  bool selected() const { return mSelected; }
256  void setSelected( bool selected ) { mSelected = selected; }
257 
258  int renderHints() const { return mRenderHints; }
259  void setRenderHints( int hints ) { mRenderHints = hints; }
260 
261  void setFeature( const QgsFeature* f ) { mFeature = f; }
263  const QgsFeature* feature() const { return mFeature; }
264 
269  const QgsFields* fields() const { return mFields; }
270 
271  double outputLineWidth( double width ) const;
272  double outputPixelSize( double size ) const;
273 
274  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
276 
277  private:
278  QgsRenderContext& mRenderContext;
279  QgsSymbolV2::OutputUnit mOutputUnit;
280  QgsMapUnitScale mMapUnitScale;
281  qreal mAlpha;
282  bool mSelected;
283  int mRenderHints;
284  const QgsFeature* mFeature; //current feature
285  const QgsFields* mFields;
286 };
287 
288 
289 
291 
292 
293 
294 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
295 {
296  public:
300  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
301 
303 
304  void setAngle( double angle );
305  double angle() const;
306 
312  void setDataDefinedAngle( const QgsDataDefined& dd );
313 
320  QgsDataDefined dataDefinedAngle() const;
321 
328  void setLineAngle( double lineAngle );
329 
330  void setSize( double size );
331  double size() const;
332 
338  void setDataDefinedSize( const QgsDataDefined& dd );
339 
346  QgsDataDefined dataDefinedSize() const;
347 
348  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
349  ScaleMethod scaleMethod();
350 
351  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
352 
353  virtual QgsSymbolV2* clone() const override;
354 
355  private:
356 
357  void renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, const QPointF& point, QgsSymbolV2RenderContext& context );
358 
359 };
360 
361 
362 
363 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
364 {
365  public:
369  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
370 
372 
373  void setWidth( double width );
374  double width() const;
375 
381  void setDataDefinedWidth( const QgsDataDefined& dd );
382 
389  QgsDataDefined dataDefinedWidth() const;
390 
391  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
392 
393  virtual QgsSymbolV2* clone() const override;
394 
395  private:
396 
397  void renderPolylineUsingLayer( QgsLineSymbolLayerV2* layer, const QPolygonF& points, QgsSymbolV2RenderContext& context );
398 
399 };
400 
401 
402 
403 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
404 {
405  public:
409  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
410 
412  void setAngle( double angle );
413  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
414 
415  virtual QgsSymbolV2* clone() const override;
416 
417  private:
418 
419  void renderPolygonUsingLayer( QgsSymbolLayerV2* layer, const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolV2RenderContext &context );
421  QRectF polygonBounds( const QPolygonF &points, const QList<QPolygonF> *rings ) const;
423  QList<QPolygonF>* translateRings( const QList<QPolygonF> *rings, double dx, double dy ) const;
424 };
425 
426 #endif
427 
428 
429 /*
430 
431 QgsSymbolV2* ps = new QgsPointSymbol();
432 
433 // ----
434 
435 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
436 
437 // (or)
438 
439 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
440 
441 // (or)
442 
443 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
444 QgsLineSymbol* s = new LineSymbol( [ sl ] );
445 
446 // ----
447 
448 rend = QgsSingleSymbolRenderer( new LineSymbol() );
449 */
450 
451 
static unsigned index
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent...
Definition: qgssymbolv2.h:193
int renderHints() const
Definition: qgssymbolv2.h:258
bool mClipFeaturesToExtent
Definition: qgssymbolv2.h:227
A container class for data source field mapping or expression.
GeometryType
Definition: qgis.h:155
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:229
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:253
SymbolType type() const
Definition: qgssymbolv2.h:86
virtual QgsSymbolV2 * clone() const =0
QList< OutputUnit > OutputUnitList
Definition: qgssymbolv2.h:60
double clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
Definition: qgssymbolv2.h:203
Base class for visual effects which can be applied to QPicture drawings.
Container of fields for a vector layer.
Definition: qgsfield.h:173
void setRenderHints(int hints)
Definition: qgssymbolv2.h:259
QgsSymbolLayerV2List symbolLayers()
Returns list of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:96
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
SymbolType mType
Definition: qgssymbolv2.h:220
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbolv2.h:248
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:209
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:251
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:221
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.h:247
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:263
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:178
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:208
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:113
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:224
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:261
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:245
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:244
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:256
Contains information about the context of a rendering operation.
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:44
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:241
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:269
void setRenderHints(int hints)
Definition: qgssymbolv2.h:182
bool selected() const
Definition: qgssymbolv2.h:255
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:242
Represents a vector layer which manages a vector based data sets.
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:180
int mRenderHints
Definition: qgssymbolv2.h:226
int renderHints() const
Definition: qgssymbolv2.h:183