QGIS API Documentation  2.12.0-Lyon
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 
97  //TODO - QGIS 3.0 make pure virtual when above method is removed
98  //TODO - QGIS 3.0 change PyName to symbolForFeature when deprecated method is removed
99  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
100 
107  Q_DECL_DEPRECATED virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
108 
116  //TODO - QGIS 3.0 change PyName to originalSymbolForFeature when deprecated method is removed
117  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
118 
126  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
127 
129  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
130 
131  virtual void stopRender( QgsRenderContext& context ) = 0;
132 
144  virtual QString filter() { return QString::null; }
145 
146  virtual QList<QString> usedAttributes() = 0;
147 
148  virtual ~QgsFeatureRendererV2();
149 
150  virtual QgsFeatureRendererV2* clone() const = 0;
151 
152  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
153 
155  virtual QString dump() const;
156 
158  {
159  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
160  RotationField = 1 << 1, // rotate symbols by attribute value
161  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
162  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
163  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
164  };
165 
167  virtual int capabilities() { return 0; }
168 
170  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbols();
171 
177  //TODO - QGIS 3.0 change PyName to symbols when deprecated method is removed
178  virtual QgsSymbolV2List symbols( QgsRenderContext& context );
179 
180  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
181  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
182 
184  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
185 
187  virtual QDomElement save( QDomDocument& doc );
188 
191  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
194  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
195 
206  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
207 
209  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
210  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
211 
213  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
214 
217  virtual bool legendSymbolItemsCheckable() const;
218 
221  virtual bool legendSymbolItemChecked( const QString& key );
222 
225  virtual void checkLegendSymbolItem( const QString& key, bool state = true );
226 
229  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" );
230 
234  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
235 
238  virtual QString legendClassificationAttribute() const { return QString(); }
239 
241  void setVertexMarkerAppearance( int type, int size );
242 
245  Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
246 
249  Q_DECL_DEPRECATED virtual void setRotationField( const QString& fieldName ) { Q_UNUSED( fieldName ); }
250 
254  Q_DECL_DEPRECATED virtual bool willRenderFeature( QgsFeature& feat );
255 
262  //TODO - QGIS 3.0 change PyName to willRenderFeature when deprecated method is removed
263  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
264 
268  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
269 
276  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
277  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
278 
282  Q_DECL_DEPRECATED virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
283 
289  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
290  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
291 
298  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
299 
305  QgsPaintEffect* paintEffect() const;
306 
312  void setPaintEffect( QgsPaintEffect* effect );
313 
318  bool forceRasterRender() const { return mForceRaster; }
319 
327  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
328 
329  protected:
330  QgsFeatureRendererV2( const QString& type );
331 
332  void renderFeatureWithSymbol( QgsFeature& feature,
333  QgsSymbolV2* symbol,
334  QgsRenderContext& context,
335  int layer,
336  bool selected,
337  bool drawVertexMarker );
338 
340  void renderVertexMarker( const QPointF& pt, QgsRenderContext& context );
342  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
344  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
345 
346  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
347  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
348  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
349 
350  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
351 
355  void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
356 
358 
360 
365 
367 
369 
373  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
377  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
378 
379  private:
380  Q_DISABLE_COPY( QgsFeatureRendererV2 )
381 };
382 
383 // for some reason SIP compilation fails if these lines are not included:
384 class QgsRendererV2Widget;
386 
387 #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:104
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:176
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.
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:78
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
virtual Q_DECL_DEPRECATED void setRotationField(const QString &fieldName)
sets rotation field of renderer (if supported by 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