QGIS API Documentation  2.15.0-Master (972fc9f)
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 
175  virtual bool filterNeedsGeometry() const;
176 
177  virtual ~QgsFeatureRendererV2();
178 
179  virtual QgsFeatureRendererV2* clone() const = 0;
180 
191  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
192 
194  virtual QString dump() const;
195 
197  {
198  SymbolLevels = 1,
199  RotationField = 1 << 1,
200  MoreSymbolsPerFeature = 1 << 2,
201  Filter = 1 << 3,
202  ScaleDependent = 1 << 4
203  };
204 
206  virtual int capabilities() { return 0; }
207 
211  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbols();
212 
218  //TODO - QGIS 3.0 change PyName to symbols when deprecated method is removed
219  virtual QgsSymbolV2List symbols( QgsRenderContext& context );
220 
221  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
222  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
223 
225  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
226 
228  virtual QDomElement save( QDomDocument& doc );
229 
232  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
235  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
236 
247  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
248 
250  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
251  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
252 
254  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
255 
258  virtual bool legendSymbolItemsCheckable() const;
259 
262  virtual bool legendSymbolItemChecked( const QString& key );
263 
266  virtual void checkLegendSymbolItem( const QString& key, bool state = true );
267 
273  virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol );
274 
277  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" );
278 
282  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
283 
286  virtual QString legendClassificationAttribute() const { return QString(); }
287 
289  void setVertexMarkerAppearance( int type, int size );
290 
293  Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
294 
297  Q_DECL_DEPRECATED virtual void setRotationField( const QString& fieldName ) { Q_UNUSED( fieldName ); }
298 
304  Q_DECL_DEPRECATED virtual bool willRenderFeature( QgsFeature& feat );
305 
312  //TODO - QGIS 3.0 change PyName to willRenderFeature when deprecated method is removed
313  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
314 
320  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
321 
328  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
329  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
330 
336  Q_DECL_DEPRECATED virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
337 
343  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
344  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
345 
352  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
353 
359  QgsPaintEffect* paintEffect() const;
360 
366  void setPaintEffect( QgsPaintEffect* effect );
367 
372  bool forceRasterRender() const { return mForceRaster; }
373 
381  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
382 
389  QgsFeatureRequest::OrderBy orderBy() const;
390 
397  void setOrderBy( const QgsFeatureRequest::OrderBy& orderBy );
398 
405  bool orderByEnabled() const;
406 
414  void setOrderByEnabled( bool enabled );
415 
422  virtual void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer ) { delete subRenderer; }
423 
429  virtual const QgsFeatureRendererV2* embeddedRenderer() const { return nullptr; }
430 
431  protected:
432  QgsFeatureRendererV2( const QString& type );
433 
434  void renderFeatureWithSymbol( QgsFeature& feature,
435  QgsSymbolV2* symbol,
436  QgsRenderContext& context,
437  int layer,
438  bool selected,
439  bool drawVertexMarker );
440 
442  void renderVertexMarker( QPointF pt, QgsRenderContext& context );
444  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
446  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
447 
452  static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr& wkb );
453 
458  static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
459 
464  static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
465 
466  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
467 
476  void copyRendererData( QgsFeatureRendererV2 *destRenderer ) const;
477 
482  Q_DECL_DEPRECATED void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
483 
485 
487 
492 
494 
496 
500  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
504  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
505 
507 
509 
510  private:
511  Q_DISABLE_COPY( QgsFeatureRendererV2 )
512 };
513 
514 // for some reason SIP compilation fails if these lines are not included:
515 class QgsRendererV2Widget;
517 
518 #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:115
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:193
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
virtual void setEmbeddedRenderer(QgsFeatureRendererV2 *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
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 const QgsFeatureRendererV2 * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
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