QGIS API Documentation  2.99.0-Master (f1c3692)
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 
58 class CORE_EXPORT QgsSymbolLevelItem
59 {
60  public:
61  QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
62  : mSymbol( symbol )
63  , mLayer( layer )
64  {}
65  QgsSymbol *symbol() { return mSymbol; }
66  int layer() { return mLayer; }
67  protected:
68  QgsSymbol *mSymbol = nullptr;
69  int mLayer;
70 };
71 
72 // every level has list of items: symbol + symbol layer num
73 typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
74 
75 // this is a list of levels
76 #ifndef SIP_RUN
77 typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
78 #else
79 typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
80 #endif
81 
82 
84 // renderers
85 
90 class CORE_EXPORT QgsFeatureRenderer
91 {
92 
93 #ifdef SIP_RUN
95  if ( sipCpp->type() == "singleSymbol" )
96  sipType = sipType_QgsSingleSymbolRenderer;
97  else if ( sipCpp->type() == "categorizedSymbol" )
98  sipType = sipType_QgsCategorizedSymbolRenderer;
99  else if ( sipCpp->type() == "graduatedSymbol" )
100  sipType = sipType_QgsGraduatedSymbolRenderer;
101  else if ( sipCpp->type() == "RuleRenderer" )
102  sipType = sipType_QgsRuleBasedRenderer;
103  else if ( sipCpp->type() == "heatmapRenderer" )
104  sipType = sipType_QgsHeatmapRenderer;
105  else if ( sipCpp->type() == "invertedPolygonRenderer" )
106  sipType = sipType_QgsInvertedPolygonRenderer;
107  else if ( sipCpp->type() == "pointCluster" )
108  sipType = sipType_QgsPointClusterRenderer;
109  else if ( sipCpp->type() == "pointDisplacement" )
110  sipType = sipType_QgsPointDisplacementRenderer;
111  else if ( sipCpp->type() == "25dRenderer" )
112  sipType = sipType_Qgs25DRenderer;
113  else if ( sipCpp->type() == "nullSymbol" )
114  sipType = sipType_QgsNullSymbolRenderer;
115  else
116  sipType = 0;
117  SIP_END
118 #endif
119 
120  public:
121  // renderer takes ownership of its symbols!
122 
124  static QgsFeatureRenderer *defaultRenderer( QgsWkbTypes::GeometryType geomType ) SIP_FACTORY;
125 
126  QString type() const { return mType; }
127 
137  virtual QgsSymbol *symbolForFeature( QgsFeature &feature, QgsRenderContext &context ) = 0;
138 
145  virtual QgsSymbol *originalSymbolForFeature( QgsFeature &feature, QgsRenderContext &context );
146 
151  virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );
152 
160  virtual void startRender( QgsRenderContext &context, const QgsFields &fields ) = 0;
161 
165  virtual void stopRender( QgsRenderContext &context ) = 0;
166 
178  virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ); return QString(); }
179 
186  virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
187 
191  virtual bool filterNeedsGeometry() const;
192 
193  virtual ~QgsFeatureRenderer();
194 
201  virtual QgsFeatureRenderer *clone() const = 0 SIP_FACTORY;
202 
213  virtual bool renderFeature( QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
214 
216  virtual QString dump() const;
217 
223  {
224  SymbolLevels = 1,
225  MoreSymbolsPerFeature = 1 << 2,
226  Filter = 1 << 3,
227  ScaleDependent = 1 << 4
228  };
229 
230  Q_DECLARE_FLAGS( Capabilities, Capability )
231 
232 
244  virtual QgsFeatureRenderer::Capabilities capabilities() { return 0; }
245 
251  virtual QgsSymbolList symbols( QgsRenderContext &context ) { Q_UNUSED( context ); return QgsSymbolList(); }
252 
253  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
254  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
255 
257  static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
258 
260  virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
261 
266  virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QgsStringMap &props = QgsStringMap() ) const;
267 
279  static QgsFeatureRenderer *loadSld( const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
280 
282  virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const
283  {
284  element.appendChild( doc.createComment( QStringLiteral( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) );
285  ( void ) props; // warning avoidance
286  }
287 
292  virtual bool legendSymbolItemsCheckable() const;
293 
298  virtual bool legendSymbolItemChecked( const QString &key );
299 
304  virtual void checkLegendSymbolItem( const QString &key, bool state = true );
305 
312  virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
313 
318  virtual QgsLegendSymbolList legendSymbolItems() const;
319 
324  virtual QString legendClassificationAttribute() const { return QString(); }
325 
327  void setVertexMarkerAppearance( int type, int size );
328 
335  virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
336 
343  virtual QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
344 
350  virtual QgsSymbolList originalSymbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
351 
359  virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
360 
367  QgsPaintEffect *paintEffect() const;
368 
375  void setPaintEffect( QgsPaintEffect *effect );
376 
382  bool forceRasterRender() const { return mForceRaster; }
383 
392  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
393 
400  QgsFeatureRequest::OrderBy orderBy() const;
401 
408  void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
409 
416  bool orderByEnabled() const;
417 
425  void setOrderByEnabled( bool enabled );
426 
434  virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) { delete subRenderer; }
435 
442  virtual const QgsFeatureRenderer *embeddedRenderer() const { return nullptr; }
443 
444  protected:
445  QgsFeatureRenderer( const QString &type );
446 
447  void renderFeatureWithSymbol( QgsFeature &feature,
448  QgsSymbol *symbol,
449  QgsRenderContext &context,
450  int layer,
451  bool selected,
452  bool drawVertexMarker );
453 
455  void renderVertexMarker( QPointF pt, QgsRenderContext &context );
457  void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
459  void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
460 
465  static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
466 
475  void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
476 
477  QString mType;
478 
480 
485 
486  QgsPaintEffect *mPaintEffect = nullptr;
487 
489 
494  static void convertSymbolSizeScale( QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field );
495 
500  static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
501 
503 
505 
506  private:
507 #ifdef SIP_RUN
509  QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
510 #endif
511 
512  Q_DISABLE_COPY( QgsFeatureRenderer )
513 };
514 
515 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRenderer::Capabilities )
516 
517 // for some reason SIP compilation fails if these lines are not included:
518 class QgsRendererWidget;
520 
521 #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:39
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
Definition: qgsrenderer.h:502
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrenderer.h:324
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:282
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:178
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
Definition: qgsrenderer.h:382
Base class for visual effects which can be applied to QPicture drawings.
Container of fields for a vector layer.
Definition: qgsfields.h:42
void setUsingSymbolLevels(bool usingSymbolLevels)
Definition: qgsrenderer.h:254
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
QMap< QString, QString > QgsStringMap
Definition: qgis.h:443
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:77
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:43
QString type() const
Definition: qgsrenderer.h:126
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
Definition: qgsrenderer.h:392
#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:61
ScaleMethod
Scale method.
Definition: qgssymbol.h:94
Capability
Used to specify details about a renderer.
Definition: qgsrenderer.h:222
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.h:434
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:137
virtual QgsSymbolList symbols(QgsRenderContext &context)
Returns list of symbols used by the renderer.
Definition: qgsrenderer.h:251
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.h:442
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:253
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:73
int mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:484
#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:359
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:482
Represents a vector layer which manages a vector based data sets.
QgsSymbol * symbol()
Definition: qgsrenderer.h:65
Represents a list of OrderByClauses, with the most important first and the least important last...