QGIS API Documentation  2.17.0-Master (3a3b9ab7)
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 
57 class CORE_EXPORT QgsSymbolV2LevelItem
58 {
59  public:
60  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer )
61  : mSymbol( symbol )
62  , mLayer( layer )
63  {}
64  QgsSymbolV2* symbol() { return mSymbol; }
65  int layer() { return mLayer; }
66  protected:
68  int mLayer;
69 };
70 
71 // every level has list of items: symbol + symbol layer num
73 
74 // this is a list of levels
76 
77 
79 // renderers
80 
84 class CORE_EXPORT QgsFeatureRendererV2
85 {
86  public:
87  // renderer takes ownership of its symbols!
88 
90  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
91 
92  QString type() const { return mType; }
93 
101  Q_DECL_DEPRECATED virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
102 
112  // TODO - QGIS 3.0 make pure virtual when above method is removed
113  // TODO - QGIS 3.0 change PyName to symbolForFeature when deprecated method is removed
114  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
115 
123  Q_DECL_DEPRECATED virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
124 
132  //TODO - QGIS 3.0 change PyName to originalSymbolForFeature when deprecated method is removed
133  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
134 
139  virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );
140 
148  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
149 
151  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
152 
156  virtual void stopRender( QgsRenderContext& context ) = 0;
157 
169  virtual QString filter( const QgsFields& fields = QgsFields() ) { Q_UNUSED( fields ); return QString::null; }
170 
176  virtual QList<QString> usedAttributes() = 0;
177 
181  virtual bool filterNeedsGeometry() const;
182 
183  virtual ~QgsFeatureRendererV2();
184 
185  virtual QgsFeatureRendererV2* clone() const = 0;
186 
197  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
198 
200  virtual QString dump() const;
201 
203  {
204  SymbolLevels = 1,
205  RotationField = 1 << 1,
206  MoreSymbolsPerFeature = 1 << 2,
207  Filter = 1 << 3,
208  ScaleDependent = 1 << 4
209  };
210 
212  virtual int capabilities() { return 0; }
213 
217  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbols();
218 
224  //TODO - QGIS 3.0 change PyName to symbols when deprecated method is removed
225  virtual QgsSymbolV2List symbols( QgsRenderContext& context );
226 
227  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
228  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
229 
231  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
232 
234  virtual QDomElement save( QDomDocument& doc );
235 
238  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
241  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
242 
253  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
254 
256  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
257  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
258 
260  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
261 
264  virtual bool legendSymbolItemsCheckable() const;
265 
268  virtual bool legendSymbolItemChecked( const QString& key );
269 
272  virtual void checkLegendSymbolItem( const QString& key, bool state = true );
273 
279  virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol );
280 
283  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" );
284 
288  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
289 
292  virtual QString legendClassificationAttribute() const { return QString(); }
293 
295  void setVertexMarkerAppearance( int type, int size );
296 
299  Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
300 
303  Q_DECL_DEPRECATED virtual void setRotationField( const QString& fieldName ) { Q_UNUSED( fieldName ); }
304 
310  Q_DECL_DEPRECATED virtual bool willRenderFeature( QgsFeature& feat );
311 
318  //TODO - QGIS 3.0 change PyName to willRenderFeature when deprecated method is removed
319  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
320 
326  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
327 
334  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
335  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
336 
342  Q_DECL_DEPRECATED virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
343 
349  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
350  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
351 
358  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
359 
365  QgsPaintEffect* paintEffect() const;
366 
372  void setPaintEffect( QgsPaintEffect* effect );
373 
378  bool forceRasterRender() const { return mForceRaster; }
379 
387  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
388 
395  QgsFeatureRequest::OrderBy orderBy() const;
396 
403  void setOrderBy( const QgsFeatureRequest::OrderBy& orderBy );
404 
411  bool orderByEnabled() const;
412 
420  void setOrderByEnabled( bool enabled );
421 
428  virtual void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer ) { delete subRenderer; }
429 
435  virtual const QgsFeatureRendererV2* embeddedRenderer() const { return nullptr; }
436 
437  protected:
438  QgsFeatureRendererV2( const QString& type );
439 
440  void renderFeatureWithSymbol( QgsFeature& feature,
441  QgsSymbolV2* symbol,
442  QgsRenderContext& context,
443  int layer,
444  bool selected,
445  bool drawVertexMarker );
446 
448  void renderVertexMarker( QPointF pt, QgsRenderContext& context );
450  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
452  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
453 
458  static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr& wkb );
459 
464  static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
465 
470  static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
471 
472  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
473 
482  void copyRendererData( QgsFeatureRendererV2 *destRenderer ) const;
483 
488  Q_DECL_DEPRECATED void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
489 
491 
493 
498 
500 
502 
506  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
510  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
511 
513 
515 
516  private:
517  Q_DISABLE_COPY( QgsFeatureRendererV2 )
518 };
519 
520 // for some reason SIP compilation fails if these lines are not included:
521 class QgsRendererV2Widget;
523 
524 #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:209
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:92
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:72
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:60
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:90
QgsFeatureRequest::OrderBy mOrderBy
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:64
bool usingSymbolLevels() const
QDomComment createComment(const QString &value)
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:75
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:67
Represents a list of OrderByClauses, with the most important first and the least important last...
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:36