QGIS API Documentation  2.11.0-Master
qgsrendererv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererv2.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 QGSRENDERERV2_H
17 #define QGSRENDERERV2_H
18 
19 #include "qgis.h"
20 #include "qgsrectangle.h"
21 #include "qgsrendercontext.h"
22 #include "qgssymbolv2.h"
23 
24 #include <QList>
25 #include <QString>
26 #include <QVariant>
27 #include <QPair>
28 #include <QPixmap>
29 #include <QDomDocument>
30 #include <QDomElement>
31 
32 class QgsFeature;
33 class QgsFields;
34 class QgsVectorLayer;
36 
38 
41 
44 
45 #include "qgslegendsymbolitemv2.h"
46 
47 
48 #define RENDERER_TAG_NAME "renderer-v2"
49 
51 // symbol levels
52 
53 class CORE_EXPORT QgsSymbolV2LevelItem
54 {
55  public:
56  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {}
57  QgsSymbolV2* symbol() { return mSymbol; }
58  int layer() { return mLayer; }
59  protected:
61  int mLayer;
62 };
63 
64 // every level has list of items: symbol + symbol layer num
66 
67 // this is a list of levels
69 
70 
72 // renderers
73 
74 class CORE_EXPORT QgsFeatureRendererV2
75 {
76  public:
77  // renderer takes ownership of its symbols!
78 
80  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
81 
82  QString type() const { return mType; }
83 
88  Q_DECL_DEPRECATED virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
89 
96  //TODO - make pure virtual when above method is removed
97  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
98 
105  Q_DECL_DEPRECATED virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
106 
113  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
114 
122  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
123 
125  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
126 
127  virtual void stopRender( QgsRenderContext& context ) = 0;
128 
140  virtual QString filter() { return QString::null; }
141 
142  virtual QList<QString> usedAttributes() = 0;
143 
144  virtual ~QgsFeatureRendererV2();
145 
146  virtual QgsFeatureRendererV2* clone() const = 0;
147 
148  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
149 
151  virtual QString dump() const;
152 
154  {
155  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
156  RotationField = 1 << 1, // rotate symbols by attribute value
157  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
158  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
159  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
160  };
161 
163  virtual int capabilities() { return 0; }
164 
166  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbols();
167 
172  virtual QgsSymbolV2List symbols( QgsRenderContext& context );
173 
174  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
175  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
176 
178  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
179 
181  virtual QDomElement save( QDomDocument& doc );
182 
185  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
188  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
189 
200  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
201 
203  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
204  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
205 
207  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
208 
211  virtual bool legendSymbolItemsCheckable() const;
212 
215  virtual bool legendSymbolItemChecked( QString key );
216 
219  virtual void checkLegendSymbolItem( QString key, bool state = true );
220 
223  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
224 
228  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
229 
232  virtual QString legendClassificationAttribute() const { return QString(); }
233 
235  void setVertexMarkerAppearance( int type, int size );
236 
239  Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
242  Q_DECL_DEPRECATED virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
243 
247  Q_DECL_DEPRECATED virtual bool willRenderFeature( QgsFeature& feat );
248 
254  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
255 
259  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
260 
264  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
265 
269  Q_DECL_DEPRECATED virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
270 
274  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
275 
282  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
283 
289  QgsPaintEffect* paintEffect() const;
290 
296  void setPaintEffect( QgsPaintEffect* effect );
297 
302  bool forceRasterRender() const { return mForceRaster; }
303 
311  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
312 
313  protected:
315 
316  void renderFeatureWithSymbol( QgsFeature& feature,
317  QgsSymbolV2* symbol,
318  QgsRenderContext& context,
319  int layer,
320  bool selected,
321  bool drawVertexMarker );
322 
324  void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
326  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
328  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
329 
330  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
331  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
332  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
333 
334  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
335 
339  void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
340 
342 
344 
349 
351 
353 
357  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
361  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
362 
363  private:
364  Q_DISABLE_COPY( QgsFeatureRendererV2 )
365 };
366 
367 // for some reason SIP compilation fails if these lines are not included:
368 class QgsRendererV2Widget;
370 
371 #endif // QGSRENDERERV2_H
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:40
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:39
QDomNode appendChild(const QDomNode &newChild)
Base class for effect properties widgets.
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgsrendererv2.h:42
virtual QString filter()
If a renderer does not require all the features this method may be overridden and return an expressio...
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
Base class for visual effects which can be applied to QPicture drawings.
Container of fields for a vector layer.
Definition: qgsfield.h:177
GeometryType
Definition: qgis.h:155
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
virtual Q_DECL_DEPRECATED void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
QgsPaintEffect * mPaintEffect
QString type() const
Definition: qgsrendererv2.h:82
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
int mCurrentVertexMarkerSize
The current size of editing marker.
virtual Q_DECL_DEPRECATED QString rotationField() const
return rotation field name (or empty string if not set or not supported by renderer) ...
int mCurrentVertexMarkerType
The current type of editing marker.
QList< QgsSymbolV2LevelItem > QgsSymbolV2Level
Definition: qgsrendererv2.h:65
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
QgsSymbolV2LevelItem(QgsSymbolV2 *symbol, int layer)
Definition: qgsrendererv2.h:56
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:57
bool usingSymbolLevels() const
QDomComment createComment(const QString &value)
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:68
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:43
QgsSymbolV2 * mSymbol
Definition: qgsrendererv2.h:60
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:35