QGIS API Documentation  3.17.0-Master (a035f434f4)
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 QGSRENDERER_H
17 #define QGSRENDERER_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"
28 
29 #include <QList>
30 #include <QString>
31 #include <QVariant>
32 #include <QPair>
33 #include <QPixmap>
34 #include <QDomDocument>
35 #include <QDomElement>
36 
37 class QgsFeature;
38 class QgsVectorLayer;
39 class QgsPaintEffect;
42 
43 typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
44 
45 typedef QList<QgsSymbol *> QgsSymbolList;
46 typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
47 
48 #include "qgslegendsymbolitem.h"
49 
50 
51 #define RENDERER_TAG_NAME "renderer-v2"
52 
54 // symbol levels
55 
60 class CORE_EXPORT QgsSymbolLevelItem
61 {
62  public:
63  QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
64  : mSymbol( symbol )
65  , mLayer( layer )
66  {}
67 
71  QgsSymbol *symbol() const;
72 
76  int layer() const;
77 
78  // TODO QGIS 4.0 -> make private
79  protected:
80  QgsSymbol *mSymbol = nullptr;
81  int mLayer;
82 };
83 
84 // every level has list of items: symbol + symbol layer num
85 typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
86 
87 // this is a list of levels
88 #ifndef SIP_RUN
89 typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
90 #else
91 typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
92 #endif
93 
94 
96 // renderers
97 
102 class CORE_EXPORT QgsFeatureRenderer
103 {
104 
105 #ifdef SIP_RUN
107 
108  const QString type = sipCpp->type();
109 
110  if ( type == QLatin1String( "singleSymbol" ) )
111  sipType = sipType_QgsSingleSymbolRenderer;
112  else if ( type == QLatin1String( "categorizedSymbol" ) )
113  sipType = sipType_QgsCategorizedSymbolRenderer;
114  else if ( type == QLatin1String( "graduatedSymbol" ) )
115  sipType = sipType_QgsGraduatedSymbolRenderer;
116  else if ( type == QLatin1String( "RuleRenderer" ) )
117  sipType = sipType_QgsRuleBasedRenderer;
118  else if ( type == QLatin1String( "heatmapRenderer" ) )
119  sipType = sipType_QgsHeatmapRenderer;
120  else if ( type == QLatin1String( "invertedPolygonRenderer" ) )
121  sipType = sipType_QgsInvertedPolygonRenderer;
122  else if ( type == QLatin1String( "pointCluster" ) )
123  sipType = sipType_QgsPointClusterRenderer;
124  else if ( type == QLatin1String( "pointDisplacement" ) )
125  sipType = sipType_QgsPointDisplacementRenderer;
126  else if ( type == QLatin1String( "25dRenderer" ) )
127  sipType = sipType_Qgs25DRenderer;
128  else if ( type == QLatin1String( "nullSymbol" ) )
129  sipType = sipType_QgsNullSymbolRenderer;
130  else
131  sipType = 0;
132  SIP_END
133 #endif
134 
135  public:
136  // renderer takes ownership of its symbols!
137 
139  static QgsFeatureRenderer *defaultRenderer( QgsWkbTypes::GeometryType geomType ) SIP_FACTORY;
140 
141  QString type() const { return mType; }
142 
152  virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
153 
160  virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
161 
166  virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
167 
180  virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
181 
192  virtual void stopRender( QgsRenderContext &context );
193 
205  virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
206 
213  virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
214 
218  virtual bool filterNeedsGeometry() const;
219 
220  virtual ~QgsFeatureRenderer();
221 
228  virtual QgsFeatureRenderer *clone() const = 0 SIP_FACTORY;
229 
243  virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
244 
246  virtual QString dump() const;
247 
253  {
254  SymbolLevels = 1,
255  MoreSymbolsPerFeature = 1 << 2,
256  Filter = 1 << 3,
257  ScaleDependent = 1 << 4
258  };
259 
260  Q_DECLARE_FLAGS( Capabilities, Capability )
261 
262 
274  virtual QgsFeatureRenderer::Capabilities capabilities() { return QgsFeatureRenderer::Capabilities(); }
275 
281  virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
282 
283  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
284  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
285 
287  static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
288 
290  virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
291 
296  virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QgsStringMap &props = QgsStringMap() ) const;
297 
309  static QgsFeatureRenderer *loadSld( const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
310 
312  virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const
313  {
314  element.appendChild( doc.createComment( QStringLiteral( "FeatureRenderer %1 not implemented yet" ).arg( type() ) ) );
315  ( void ) props; // warning avoidance
316  }
317 
322  virtual bool legendSymbolItemsCheckable() const;
323 
328  virtual bool legendSymbolItemChecked( const QString &key );
329 
334  virtual void checkLegendSymbolItem( const QString &key, bool state = true );
335 
342  virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
343 
348  virtual QgsLegendSymbolList legendSymbolItems() const;
349 
354  virtual QString legendClassificationAttribute() const { return QString(); }
355 
357  void setVertexMarkerAppearance( int type, double size );
358 
365  virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
366 
373  virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
374 
380  virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
381 
389  virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
390 
397  QgsPaintEffect *paintEffect() const;
398 
405  void setPaintEffect( QgsPaintEffect *effect );
406 
412  bool forceRasterRender() const { return mForceRaster; }
413 
422  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
423 
430  QgsFeatureRequest::OrderBy orderBy() const;
431 
438  void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
439 
446  bool orderByEnabled() const;
447 
455  void setOrderByEnabled( bool enabled );
456 
464  virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
465 
472  virtual const QgsFeatureRenderer *embeddedRenderer() const;
473 
483  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
484 
485  protected:
486  QgsFeatureRenderer( const QString &type );
487 
494  void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
495 
497  void renderVertexMarker( QPointF pt, QgsRenderContext &context );
499  void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
501  void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
502 
507  static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
508 
518  void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
519 
520  QString mType;
521 
523 
528 
529  QgsPaintEffect *mPaintEffect = nullptr;
530 
532 
537  static void convertSymbolSizeScale( QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field );
538 
543  static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
544 
546 
548 
549  private:
550 #ifdef SIP_RUN
552  QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
553 #endif
554 
555 #ifdef QGISDEBUG
556  QThread *mThread = nullptr;
558 #endif
559 
560  Q_DISABLE_COPY( QgsFeatureRenderer )
561 };
562 
563 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRenderer::Capabilities )
564 
565 // for some reason SIP compilation fails if these lines are not included:
566 class QgsRendererWidget;
568 
569 #endif // QGSRENDERER_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:41
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
Definition: qgsrenderer.h:545
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrenderer.h:354
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
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:312
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:205
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
Definition: qgsrenderer.h:412
Base class for visual effects which can be applied to QPicture drawings.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
Container of fields for a vector layer.
Definition: qgsfields.h:44
void setUsingSymbolLevels(bool usingSymbolLevels)
Definition: qgsrenderer.h:284
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
An interface for classes which can visit style entity (e.g.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:759
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:89
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:45
QString type() const
Definition: qgsrenderer.h:141
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
Definition: qgsrenderer.h:422
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:194
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSymbolLevelItem(QgsSymbol *symbol, int layer)
Definition: qgsrenderer.h:63
ScaleMethod
Scale method.
Definition: qgssymbol.h:97
Capability
Used to specify details about a renderer.
Definition: qgsrenderer.h:252
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:283
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:85
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
QMap< QString, QgsSymbol *> QgsSymbolMap
Definition: qgsrenderer.h:46
#define SIP_THROW(name)
Definition: qgis_sip.h:189
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:525
Represents a vector layer which manages a vector based data sets.
double mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:527
const QgsField & field
Definition: qgsfield.h:471
Represents a list of OrderByClauses, with the most important first and the least important last...