QGIS API Documentation  2.99.0-Master (9caa722)
qgsrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrenderer.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_core.h"
20 #include "qgis_sip.h"
21 #include "qgis.h"
22 #include "qgsrectangle.h"
23 #include "qgsrendercontext.h"
24 #include "qgssymbol.h"
25 #include "qgsfields.h"
26 #include "qgsfeaturerequest.h"
27 
28 #include <QList>
29 #include <QString>
30 #include <QVariant>
31 #include <QPair>
32 #include <QPixmap>
33 #include <QDomDocument>
34 #include <QDomElement>
35 
36 class QgsFeature;
37 class QgsVectorLayer;
38 class QgsPaintEffect;
40 
41 typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
42 
43 typedef QList<QgsSymbol *> QgsSymbolList;
44 typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
45 
46 #include "qgslegendsymbolitem.h"
47 
48 
49 #define RENDERER_TAG_NAME "renderer-v2"
50 
52 // symbol levels
53 
57 class CORE_EXPORT QgsSymbolLevelItem
58 {
59  public:
60  QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
61  : mSymbol( symbol )
62  , mLayer( layer )
63  {}
64  QgsSymbol *symbol() { return mSymbol; }
65  int layer() { return mLayer; }
66  protected:
67  QgsSymbol *mSymbol = nullptr;
68  int mLayer;
69 };
70 
71 // every level has list of items: symbol + symbol layer num
72 typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
73 
74 // this is a list of levels
75 #ifndef SIP_RUN
76 typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
77 #else
78 typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
79 #endif
80 
81 
83 // renderers
84 
88 class CORE_EXPORT QgsFeatureRenderer
89 {
90 
91 #ifdef SIP_RUN
93  if ( sipCpp->type() == "singleSymbol" )
94  sipType = sipType_QgsSingleSymbolRenderer;
95  else if ( sipCpp->type() == "categorizedSymbol" )
96  sipType = sipType_QgsCategorizedSymbolRenderer;
97  else if ( sipCpp->type() == "graduatedSymbol" )
98  sipType = sipType_QgsGraduatedSymbolRenderer;
99  else if ( sipCpp->type() == "RuleRenderer" )
100  sipType = sipType_QgsRuleBasedRenderer;
101  else if ( sipCpp->type() == "heatmapRenderer" )
102  sipType = sipType_QgsHeatmapRenderer;
103  else if ( sipCpp->type() == "invertedPolygonRenderer" )
104  sipType = sipType_QgsInvertedPolygonRenderer;
105  else if ( sipCpp->type() == "pointCluster" )
106  sipType = sipType_QgsPointClusterRenderer;
107  else if ( sipCpp->type() == "pointDisplacement" )
108  sipType = sipType_QgsPointDisplacementRenderer;
109  else if ( sipCpp->type() == "25dRenderer" )
110  sipType = sipType_Qgs25DRenderer;
111  else if ( sipCpp->type() == "nullSymbol" )
112  sipType = sipType_QgsNullSymbolRenderer;
113  else
114  sipType = 0;
115  SIP_END
116 #endif
117 
118  public:
119  // renderer takes ownership of its symbols!
120 
122  static QgsFeatureRenderer *defaultRenderer( QgsWkbTypes::GeometryType geomType ) SIP_FACTORY;
123 
124  QString type() const { return mType; }
125 
134  virtual QgsSymbol *symbolForFeature( QgsFeature &feature, QgsRenderContext &context ) = 0;
135 
142  virtual QgsSymbol *originalSymbolForFeature( QgsFeature &feature, QgsRenderContext &context );
143 
148  virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );
149 
157  virtual void startRender( QgsRenderContext &context, const QgsFields &fields ) = 0;
158 
162  virtual void stopRender( QgsRenderContext &context ) = 0;
163 
175  virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ); return QString(); }
176 
183  virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
184 
188  virtual bool filterNeedsGeometry() const;
189 
190  virtual ~QgsFeatureRenderer();
191 
198  virtual QgsFeatureRenderer *clone() const = 0 SIP_FACTORY;
199 
210  virtual bool renderFeature( QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
211 
213  virtual QString dump() const;
214 
220  {
221  SymbolLevels = 1,
222  MoreSymbolsPerFeature = 1 << 2,
223  Filter = 1 << 3,
224  ScaleDependent = 1 << 4
225  };
226 
227  Q_DECLARE_FLAGS( Capabilities, Capability )
228 
229 
241  virtual QgsFeatureRenderer::Capabilities capabilities() { return 0; }
242 
247  virtual QgsSymbolList symbols( QgsRenderContext &context ) { Q_UNUSED( context ); return QgsSymbolList(); }
248 
249  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
250  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
251 
253  static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
254 
256  virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
257 
260  virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QgsStringMap &props = QgsStringMap() ) const;
261 
272  static QgsFeatureRenderer *loadSld( const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
273 
275  virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const
276  {
277  element.appendChild( doc.createComment( QStringLiteral( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) );
278  ( void ) props; // warning avoidance
279  }
280 
283  virtual bool legendSymbolItemsCheckable() const;
284 
287  virtual bool legendSymbolItemChecked( const QString &key );
288 
291  virtual void checkLegendSymbolItem( const QString &key, bool state = true );
292 
298  virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
299 
302  virtual QgsLegendSymbolList legendSymbolItems() const;
303 
306  virtual QString legendClassificationAttribute() const { return QString(); }
307 
309  void setVertexMarkerAppearance( int type, int size );
310 
316  virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
317 
323  virtual QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
324 
329  virtual QgsSymbolList originalSymbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
330 
337  virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
338 
344  QgsPaintEffect *paintEffect() const;
345 
351  void setPaintEffect( QgsPaintEffect *effect );
352 
357  bool forceRasterRender() const { return mForceRaster; }
358 
366  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
367 
374  QgsFeatureRequest::OrderBy orderBy() const;
375 
382  void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
383 
390  bool orderByEnabled() const;
391 
399  void setOrderByEnabled( bool enabled );
400 
407  virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) { delete subRenderer; }
408 
414  virtual const QgsFeatureRenderer *embeddedRenderer() const { return nullptr; }
415 
416  protected:
417  QgsFeatureRenderer( const QString &type );
418 
419  void renderFeatureWithSymbol( QgsFeature &feature,
420  QgsSymbol *symbol,
421  QgsRenderContext &context,
422  int layer,
423  bool selected,
424  bool drawVertexMarker );
425 
427  void renderVertexMarker( QPointF pt, QgsRenderContext &context );
429  void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
431  void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
432 
437  static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
438 
447  void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
448 
449  QString mType;
450 
452 
457 
458  QgsPaintEffect *mPaintEffect = nullptr;
459 
461 
465  static void convertSymbolSizeScale( QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field );
466 
470  static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
471 
473 
475 
476  private:
477 #ifdef SIP_RUN
479  QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
480 #endif
481 
482  Q_DISABLE_COPY( QgsFeatureRenderer )
483 };
484 
485 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRenderer::Capabilities )
486 
487 // for some reason SIP compilation fails if these lines are not included:
488 class QgsRendererWidget;
490 
491 #endif // QGSRENDERERV2_H
The class is used as a container of context for various read/write operations on other objects...
QMap< QString, QString > QgsStringMap
Definition: qgsrenderer.h:39
A rectangle specified with double values.
Definition: qgsrectangle.h:38
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
Definition: qgsrenderer.h:472
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrenderer.h:306
Base class for effect properties widgets.
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Definition: qgsrenderer.h:275
Base class for renderer settings widgets.
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...
Definition: qgsrenderer.h:175
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
Definition: qgsrenderer.h:357
Base class for visual effects which can be applied to QPicture drawings.
Container of fields for a vector layer.
Definition: qgsfields.h:41
void setUsingSymbolLevels(bool usingSymbolLevels)
Definition: qgsrenderer.h:250
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
QMap< QString, QString > QgsStringMap
Definition: qgis.h:366
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:76
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:43
QString type() const
Definition: qgsrenderer.h:124
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
Definition: qgsrenderer.h:366
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:175
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsSymbolLevelItem(QgsSymbol *symbol, int layer)
Definition: qgsrenderer.h:60
ScaleMethod
Scale method.
Definition: qgssymbol.h:93
Capability
Used to specify details about a renderer.
Definition: qgsrenderer.h:219
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:36
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.h:407
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:136
virtual QgsSymbolList symbols(QgsRenderContext &context)
Returns list of symbols used by the renderer.
Definition: qgsrenderer.h:247
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.h:414
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:249
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:72
int mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:456
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
QMap< QString, QgsSymbol *> QgsSymbolMap
Definition: qgsrenderer.h:44
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
Definition: qgsrenderer.h:337
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:454
Represents a vector layer which manages a vector based data sets.
QgsSymbol * symbol()
Definition: qgsrenderer.h:64
Represents a list of OrderByClauses, with the most important first and the least important last...