QGIS API Documentation
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 #include "qgsfield.h"
24 #include "qgsfeaturerequest.h"
25 
26 #include <QList>
27 #include <QString>
28 #include <QVariant>
29 #include <QPair>
30 #include <QPixmap>
31 #include <QDomDocument>
32 #include <QDomElement>
33 
34 class QgsFeature;
35 class QgsVectorLayer;
37 
39 
42 
45 
46 #include "qgslegendsymbolitemv2.h"
47 
48 
49 #define RENDERER_TAG_NAME "renderer-v2"
50 
52 // symbol levels
53 
54 class CORE_EXPORT QgsSymbolV2LevelItem
55 {
56  public:
57  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer )
58  : mSymbol( symbol )
59  , mLayer( layer )
60  {}
61  QgsSymbolV2* symbol() { return mSymbol; }
62  int layer() { return mLayer; }
63  protected:
65  int mLayer;
66 };
67 
68 // every level has list of items: symbol + symbol layer num
70 
71 // this is a list of levels
73 
74 
76 // renderers
77 
78 class CORE_EXPORT QgsFeatureRendererV2
79 {
80  public:
81  // renderer takes ownership of its symbols!
82 
84  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
85 
86  QString type() const { return mType; }
87 
95  Q_DECL_DEPRECATED virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
96 
106  // TODO - QGIS 3.0 make pure virtual when above method is removed
107  // TODO - QGIS 3.0 change PyName to symbolForFeature when deprecated method is removed
108  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
109 
117  Q_DECL_DEPRECATED virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
118 
126  //TODO - QGIS 3.0 change PyName to originalSymbolForFeature when deprecated method is removed
127  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
128 
133  virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );
134 
142  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
143 
145  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
146 
150  virtual void stopRender( QgsRenderContext& context ) = 0;
151 
163  virtual QString filter( const QgsFields& fields = QgsFields() ) { Q_UNUSED( fields ); return QString::null; }
164 
170  virtual QList<QString> usedAttributes() = 0;
171 
172  virtual ~QgsFeatureRendererV2();
173 
174  virtual QgsFeatureRendererV2* clone() const = 0;
175 
186  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
187 
189  virtual QString dump() const;
190 
192  {
193  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
194  RotationField = 1 << 1, // rotate symbols by attribute value
195  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
196  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
197  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
198  };
199 
201  virtual int capabilities() { return 0; }
202 
206  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbols();
207 
213  //TODO - QGIS 3.0 change PyName to symbols when deprecated method is removed
214  virtual QgsSymbolV2List symbols( QgsRenderContext& context );
215 
216  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
217  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
218 
220  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
221 
223  virtual QDomElement save( QDomDocument& doc );
224 
227  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
230  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
231 
242  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
243 
245  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
246  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
247 
249  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
250 
253  virtual bool legendSymbolItemsCheckable() const;
254 
257  virtual bool legendSymbolItemChecked( const QString& key );
258 
261  virtual void checkLegendSymbolItem( const QString& key, bool state = true );
262 
268  virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol );
269 
272  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" );
273 
277  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
278 
281  virtual QString legendClassificationAttribute() const { return QString(); }
282 
284  void setVertexMarkerAppearance( int type, int size );
285 
288  Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
289 
292  Q_DECL_DEPRECATED virtual void setRotationField( const QString& fieldName ) { Q_UNUSED( fieldName ); }
293 
299  Q_DECL_DEPRECATED virtual bool willRenderFeature( QgsFeature& feat );
300 
307  //TODO - QGIS 3.0 change PyName to willRenderFeature when deprecated method is removed
308  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
309 
315  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
316 
323  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
324  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
325 
331  Q_DECL_DEPRECATED virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
332 
338  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
339  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
340 
347  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
348 
354  QgsPaintEffect* paintEffect() const;
355 
361  void setPaintEffect( QgsPaintEffect* effect );
362 
367  bool forceRasterRender() const { return mForceRaster; }
368 
376  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
377 
384  QgsFeatureRequest::OrderBy orderBy() const;
385 
392  void setOrderBy( const QgsFeatureRequest::OrderBy& orderBy );
393 
400  bool orderByEnabled() const;
401 
409  void setOrderByEnabled( bool enabled );
410 
411  protected:
412  QgsFeatureRendererV2( const QString& type );
413 
414  void renderFeatureWithSymbol( QgsFeature& feature,
415  QgsSymbolV2* symbol,
416  QgsRenderContext& context,
417  int layer,
418  bool selected,
419  bool drawVertexMarker );
420 
422  void renderVertexMarker( QPointF pt, QgsRenderContext& context );
424  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
426  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
427 
428  static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr wkb );
429  static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );
430  static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );
431 
432  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
433 
442  void copyRendererData( QgsFeatureRendererV2 *destRenderer ) const;
443 
448  Q_DECL_DEPRECATED void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
449 
451 
453 
458 
460 
462 
466  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
470  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
471 
473 
475 
476  private:
477  Q_DISABLE_COPY( QgsFeatureRendererV2 )
478 };
479 
480 // for some reason SIP compilation fails if these lines are not included:
481 class QgsRendererV2Widget;
483 
484 #endif // QGSRENDERERV2_H
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:41
A rectangle specified with double values.
Definition: qgsrectangle.h:35
GeometryType
Definition: qgis.h:111
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:40
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:43
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:187
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
virtual QString filter(const QgsFields &fields=QgsFields())
If a renderer does not require all the features this method may be overridden and return an expressio...
QgsPaintEffect * mPaintEffect
QString type() const
Definition: qgsrendererv2.h:86
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:69
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:57
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:87
QgsFeatureRequest::OrderBy mOrderBy
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:61
bool usingSymbolLevels() const
QDomComment createComment(const QString &value)
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:72
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:44
QgsSymbolV2 * mSymbol
Definition: qgsrendererv2.h:64
Represents a list of OrderByClauses, with the most important first and the least important last...
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:36