QGIS API Documentation  2.9.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;
39 class QgsVectorLayer;
40 class QgsPaintEffect;
44 
45 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
46 
47 class CORE_EXPORT QgsSymbolV2
48 {
49  public:
50 
52  {
53  MM = 0,
55  Mixed, //mixed units in symbol layers
56  Pixel
57  };
58 
59  typedef QList<OutputUnit> OutputUnitList;
60 
62  {
65  Fill
66  };
67 
69  {
71  ScaleDiameter
72  };
73 
75  {
76  DataDefinedSizeScale = 1,
77  DataDefinedRotation = 2
78  };
79 
80  virtual ~QgsSymbolV2();
81 
83  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
84 
85  SymbolType type() const { return mType; }
86 
87  // symbol layers handling
88 
95  QgsSymbolLayerV2List symbolLayers() { return mLayers; }
96 
104  QgsSymbolLayerV2* symbolLayer( int layer );
105 
112  int symbolLayerCount() { return mLayers.count(); }
113 
115  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
116 
118  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
119 
121  bool deleteSymbolLayer( int index );
122 
124  QgsSymbolLayerV2* takeSymbolLayer( int index );
125 
127  bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
128 
129  void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
130  void stopRender( QgsRenderContext& context );
131 
132  void setColor( const QColor& color );
133  QColor color() const;
134 
138  void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );
139 
140  QImage asImage( QSize size, QgsRenderContext* customContext = 0 );
141 
142  QImage bigSymbolPreviewImage();
143 
144  QString dump() const;
145 
146  virtual QgsSymbolV2* clone() const = 0;
147 
148  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
149 
150  QgsSymbolV2::OutputUnit outputUnit() const;
151  void setOutputUnit( QgsSymbolV2::OutputUnit u );
152 
153  QgsMapUnitScale mapUnitScale() const;
154  void setMapUnitScale( const QgsMapUnitScale& scale );
155 
157  qreal alpha() const { return mAlpha; }
159  void setAlpha( qreal alpha ) { mAlpha = alpha; }
160 
161  void setRenderHints( int hints ) { mRenderHints = hints; }
162  int renderHints() const { return mRenderHints; }
163 
172  void setClipFeaturesToExtent( bool clipFeaturesToExtent ) { mClipFeaturesToExtent = clipFeaturesToExtent; }
173 
182  double clipFeaturesToExtent() const { return mClipFeaturesToExtent; }
183 
184  QSet<QString> usedAttributes() const;
185 
186  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
187  const QgsVectorLayer* layer() const { return mLayer; }
188 
189  protected:
190  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
191 
192  QgsSymbolLayerV2List cloneLayers() const;
193 
196  bool isSymbolLayerCompatible( SymbolType t );
197 
200 
202  qreal mAlpha;
203 
206 
207  const QgsVectorLayer* mLayer; //current vectorlayer
208 
209 };
210 
212 
213 class CORE_EXPORT QgsSymbolV2RenderContext
214 {
215  public:
216  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() );
218 
219  QgsRenderContext& renderContext() { return mRenderContext; }
220  const QgsRenderContext& renderContext() const { return mRenderContext; }
221 
222  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
223  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
224 
225  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
226  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
227 
229  qreal alpha() const { return mAlpha; }
231  void setAlpha( qreal alpha ) { mAlpha = alpha; }
232 
233  bool selected() const { return mSelected; }
234  void setSelected( bool selected ) { mSelected = selected; }
235 
236  int renderHints() const { return mRenderHints; }
237  void setRenderHints( int hints ) { mRenderHints = hints; }
238 
239  void setFeature( const QgsFeature* f ) { mFeature = f; }
241  const QgsFeature* feature() const { return mFeature; }
242 
247  const QgsFields* fields() const { return mFields; }
248 
249  double outputLineWidth( double width ) const;
250  double outputPixelSize( double size ) const;
251 
252  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
254 
255  private:
256  QgsRenderContext& mRenderContext;
257  QgsSymbolV2::OutputUnit mOutputUnit;
258  QgsMapUnitScale mMapUnitScale;
259  qreal mAlpha;
260  bool mSelected;
261  int mRenderHints;
262  const QgsFeature* mFeature; //current feature
263  const QgsFields* mFields;
264 };
265 
266 
267 
269 
270 
271 
272 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
273 {
274  public:
278  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
279 
281 
282  void setAngle( double angle );
283  double angle();
284 
285  void setSize( double size );
286  double size();
287 
288  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
289  ScaleMethod scaleMethod();
290 
291  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
292 
293  virtual QgsSymbolV2* clone() const override;
294 
295  private:
296 
297  void renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, const QPointF& point, QgsSymbolV2RenderContext& context );
298 
299 };
300 
301 
302 
303 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
304 {
305  public:
309  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
310 
312 
313  void setWidth( double width );
314  double width();
315 
316  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
317 
318  virtual QgsSymbolV2* clone() const override;
319 
320  private:
321 
322  void renderPolylineUsingLayer( QgsLineSymbolLayerV2* layer, const QPolygonF& points, QgsSymbolV2RenderContext& context );
323 
324 };
325 
326 
327 
328 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
329 {
330  public:
334  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
335 
337  void setAngle( double angle );
338  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
339 
340  virtual QgsSymbolV2* clone() const override;
341 
342  private:
343 
344  void renderPolygonUsingLayer( QgsSymbolLayerV2* layer, const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolV2RenderContext &context );
346  QRectF polygonBounds( const QPolygonF &points, const QList<QPolygonF> *rings ) const;
348  QList<QPolygonF>* translateRings( const QList<QPolygonF> *rings, double dx, double dy ) const;
349 };
350 
351 #endif
352 
353 
354 /*
355 
356 QgsSymbolV2* ps = new QgsPointSymbol();
357 
358 // ----
359 
360 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
361 
362 // (or)
363 
364 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
365 
366 // (or)
367 
368 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
369 QgsLineSymbol* s = new LineSymbol( [ sl ] );
370 
371 // ----
372 
373 rend = QgsSingleSymbolRenderer( new LineSymbol() );
374 */
375 
376 
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:172
int renderHints() const
Definition: qgssymbolv2.h:236
bool mClipFeaturesToExtent
Definition: qgssymbolv2.h:205
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:207
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:231
SymbolType type() const
Definition: qgssymbolv2.h:85
virtual QgsSymbolV2 * clone() const =0
QList< OutputUnit > OutputUnitList
Definition: qgssymbolv2.h:59
double clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
Definition: qgssymbolv2.h:182
Container of fields for a vector layer.
Definition: qgsfield.h:172
GeometryType
Definition: qgis.h:155
void setRenderHints(int hints)
Definition: qgssymbolv2.h:237
QgsSymbolLayerV2List symbolLayers()
Returns list of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:95
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:198
QMap< QString, QString > QgsStringMap
Definition: qgis.h:438
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbolv2.h:226
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:187
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:229
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:199
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.h:225
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:241
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:157
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:186
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:112
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:202
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:239
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:223
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:222
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:234
Contains information about the context of a rendering operation.
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:43
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:219
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:247
void setRenderHints(int hints)
Definition: qgssymbolv2.h:161
bool selected() const
Definition: qgssymbolv2.h:233
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:220
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:159
int mRenderHints
Definition: qgssymbolv2.h:204
int renderHints() const
Definition: qgssymbolv2.h:162