QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  {
243  return writeSld( doc, styleName, QgsStringMap() );
244  }
247  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName, const QgsStringMap& props ) const;
248 
259  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
260 
262  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
263  {
264  toSld( doc, element, QgsStringMap() );
265  }
267  virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const
268  {
269  Q_UNUSED( props );
270  element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) );
271  }
272 
274  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
275 
278  virtual bool legendSymbolItemsCheckable() const;
279 
282  virtual bool legendSymbolItemChecked( const QString& key );
283 
286  virtual void checkLegendSymbolItem( const QString& key, bool state = true );
287 
293  virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol );
294 
297  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" );
298 
302  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
303 
306  virtual QString legendClassificationAttribute() const { return QString(); }
307 
309  void setVertexMarkerAppearance( int type, int size );
310 
313  Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
314 
317  Q_DECL_DEPRECATED virtual void setRotationField( const QString& fieldName ) { Q_UNUSED( fieldName ); }
318 
324  Q_DECL_DEPRECATED virtual bool willRenderFeature( QgsFeature& feat );
325 
332  //TODO - QGIS 3.0 change PyName to willRenderFeature when deprecated method is removed
333  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
334 
340  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
341 
348  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
349  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
350 
356  Q_DECL_DEPRECATED virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
357 
363  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
364  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
365 
372  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
373 
379  QgsPaintEffect* paintEffect() const;
380 
386  void setPaintEffect( QgsPaintEffect* effect );
387 
392  bool forceRasterRender() const { return mForceRaster; }
393 
401  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
402 
409  QgsFeatureRequest::OrderBy orderBy() const;
410 
417  void setOrderBy( const QgsFeatureRequest::OrderBy& orderBy );
418 
425  bool orderByEnabled() const;
426 
434  void setOrderByEnabled( bool enabled );
435 
442  virtual void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer ) { delete subRenderer; }
443 
449  virtual const QgsFeatureRendererV2* embeddedRenderer() const { return nullptr; }
450 
451  protected:
452  QgsFeatureRendererV2( const QString& type );
453 
454  void renderFeatureWithSymbol( QgsFeature& feature,
455  QgsSymbolV2* symbol,
456  QgsRenderContext& context,
457  int layer,
458  bool selected,
459  bool drawVertexMarker );
460 
462  void renderVertexMarker( QPointF pt, QgsRenderContext& context );
464  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
466  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
467 
472  static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr& wkb );
473 
478  static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
479 
484  static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
485 
486  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
487 
496  void copyRendererData( QgsFeatureRendererV2 *destRenderer ) const;
497 
502  Q_DECL_DEPRECATED void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
503 
505 
507 
512 
514 
516 
520  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
524  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
525 
527 
529 
530  private:
531  Q_DISABLE_COPY( QgsFeatureRendererV2 )
532 };
533 
534 // for some reason SIP compilation fails if these lines are not included:
535 class QgsRendererV2Widget;
537 
538 #endif // QGSRENDERERV2_H
QMap< QString, QgsSymbolV2 *> QgsSymbolV2Map
Definition: qgsrendererv2.h:41
virtual Q_DECL_DEPRECATED QString rotationField() const
return rotation field name (or empty string if not set or not supported by renderer) ...
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 toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
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:252
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...
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
QgsPaintEffect * mPaintEffect
virtual const QgsFeatureRendererV2 * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual void setEmbeddedRenderer(QgsFeatureRendererV2 *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
int mCurrentVertexMarkerSize
The current size of editing marker.
QString type() const
Definition: qgsrendererv2.h:92
int mCurrentVertexMarkerType
The current type of editing marker.
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
bool usingSymbolLevels() const
QList< QgsSymbolV2LevelItem > QgsSymbolV2Level
Definition: qgsrendererv2.h:72
QgsSymbolV2LevelItem(QgsSymbolV2 *symbol, int layer)
Definition: qgsrendererv2.h:60
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
virtual QDomElement writeSld(QDomDocument &doc, const QString &styleName) const
create the SLD UserStyle element following the SLD v1.1 specs with the given name ...
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:90
QgsFeatureRequest::OrderBy mOrderBy
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:64
QDomComment createComment(const QString &value)
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:75
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
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