QGIS API Documentation  2.9.0-Master
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 
46 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
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 
60  typedef QList<OutputUnit> OutputUnitList;
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 
116  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
117 
119  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
120 
122  bool deleteSymbolLayer( int index );
123 
125  QgsSymbolLayerV2* takeSymbolLayer( int index );
126 
128  bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
129 
130  void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
131  void stopRender( QgsRenderContext& context );
132 
133  void setColor( const QColor& color );
134  QColor color() const;
135 
139  void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );
140 
141  QImage asImage( QSize size, QgsRenderContext* customContext = 0 );
142 
143  QImage bigSymbolPreviewImage();
144 
145  QString dump() const;
146 
147  virtual QgsSymbolV2* clone() const = 0;
148 
149  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
150 
151  QgsSymbolV2::OutputUnit outputUnit() const;
152  void setOutputUnit( QgsSymbolV2::OutputUnit u );
153 
154  QgsMapUnitScale mapUnitScale() const;
155  void setMapUnitScale( const QgsMapUnitScale& scale );
156 
158  qreal alpha() const { return mAlpha; }
160  void setAlpha( qreal alpha ) { mAlpha = alpha; }
161 
162  void setRenderHints( int hints ) { mRenderHints = hints; }
163  int renderHints() const { return mRenderHints; }
164 
173  void setClipFeaturesToExtent( bool clipFeaturesToExtent ) { mClipFeaturesToExtent = clipFeaturesToExtent; }
174 
183  double clipFeaturesToExtent() const { return mClipFeaturesToExtent; }
184 
185  QSet<QString> usedAttributes() const;
186 
188  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
189  const QgsVectorLayer* layer() const { return mLayer; }
190 
191  protected:
192  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
193 
194  QgsSymbolLayerV2List cloneLayers() const;
195 
198  bool isSymbolLayerCompatible( SymbolType t );
199 
202 
204  qreal mAlpha;
205 
208 
209  const QgsVectorLayer* mLayer; //current vectorlayer
210 
211 };
212 
214 
215 class CORE_EXPORT QgsSymbolV2RenderContext
216 {
217  public:
218  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() );
220 
221  QgsRenderContext& renderContext() { return mRenderContext; }
222  const QgsRenderContext& renderContext() const { return mRenderContext; }
223 
224  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
225  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
226 
227  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
228  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
229 
231  qreal alpha() const { return mAlpha; }
233  void setAlpha( qreal alpha ) { mAlpha = alpha; }
234 
235  bool selected() const { return mSelected; }
236  void setSelected( bool selected ) { mSelected = selected; }
237 
238  int renderHints() const { return mRenderHints; }
239  void setRenderHints( int hints ) { mRenderHints = hints; }
240 
241  void setFeature( const QgsFeature* f ) { mFeature = f; }
243  const QgsFeature* feature() const { return mFeature; }
244 
249  const QgsFields* fields() const { return mFields; }
250 
251  double outputLineWidth( double width ) const;
252  double outputPixelSize( double size ) const;
253 
254  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
256 
257  private:
258  QgsRenderContext& mRenderContext;
259  QgsSymbolV2::OutputUnit mOutputUnit;
260  QgsMapUnitScale mMapUnitScale;
261  qreal mAlpha;
262  bool mSelected;
263  int mRenderHints;
264  const QgsFeature* mFeature; //current feature
265  const QgsFields* mFields;
266 };
267 
268 
269 
271 
272 
273 
274 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
275 {
276  public:
280  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
281 
283 
284  void setAngle( double angle );
285  double angle() const;
286 
292  void setDataDefinedAngle( const QgsDataDefined& dd );
293 
300  QgsDataDefined dataDefinedAngle() const;
301 
308  void setLineAngle( double lineAngle );
309 
310  void setSize( double size );
311  double size() const;
312 
318  void setDataDefinedSize( const QgsDataDefined& dd );
319 
326  QgsDataDefined dataDefinedSize() const;
327 
328  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
329  ScaleMethod scaleMethod();
330 
331  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
332 
333  virtual QgsSymbolV2* clone() const override;
334 
335  private:
336 
337  void renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, const QPointF& point, QgsSymbolV2RenderContext& context );
338 
339 };
340 
341 
342 
343 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
344 {
345  public:
349  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
350 
352 
353  void setWidth( double width );
354  double width() const;
355 
361  void setDataDefinedWidth( const QgsDataDefined& dd );
362 
369  QgsDataDefined dataDefinedWidth() const;
370 
371  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
372 
373  virtual QgsSymbolV2* clone() const override;
374 
375  private:
376 
377  void renderPolylineUsingLayer( QgsLineSymbolLayerV2* layer, const QPolygonF& points, QgsSymbolV2RenderContext& context );
378 
379 };
380 
381 
382 
383 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
384 {
385  public:
389  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
390 
392  void setAngle( double angle );
393  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
394 
395  virtual QgsSymbolV2* clone() const override;
396 
397  private:
398 
399  void renderPolygonUsingLayer( QgsSymbolLayerV2* layer, const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolV2RenderContext &context );
401  QRectF polygonBounds( const QPolygonF &points, const QList<QPolygonF> *rings ) const;
403  QList<QPolygonF>* translateRings( const QList<QPolygonF> *rings, double dx, double dy ) const;
404 };
405 
406 #endif
407 
408 
409 /*
410 
411 QgsSymbolV2* ps = new QgsPointSymbol();
412 
413 // ----
414 
415 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
416 
417 // (or)
418 
419 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
420 
421 // (or)
422 
423 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
424 QgsLineSymbol* s = new LineSymbol( [ sl ] );
425 
426 // ----
427 
428 rend = QgsSingleSymbolRenderer( new LineSymbol() );
429 */
430 
431 
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:173
int renderHints() const
Definition: qgssymbolv2.h:238
bool mClipFeaturesToExtent
Definition: qgssymbolv2.h:207
A container class for data source field mapping or expression.
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:209
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:233
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:183
Base class for visual effects which can be applied to QPicture drawings.
Container of fields for a vector layer.
Definition: qgsfield.h:173
GeometryType
Definition: qgis.h:155
void setRenderHints(int hints)
Definition: qgssymbolv2.h:239
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:119
SymbolType mType
Definition: qgssymbolv2.h:200
QMap< QString, QString > QgsStringMap
Definition: qgis.h:438
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbolv2.h:228
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:189
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:231
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:201
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.h:227
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:243
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:158
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:188
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:204
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:241
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:225
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:224
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:236
Contains information about the context of a rendering operation.
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:44
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:221
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:249
void setRenderHints(int hints)
Definition: qgssymbolv2.h:162
bool selected() const
Definition: qgssymbolv2.h:235
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:222
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:160
int mRenderHints
Definition: qgssymbolv2.h:206
int renderHints() const
Definition: qgssymbolv2.h:163