QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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"
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;
41 
42 typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
43 
44 typedef QList<QgsSymbol *> QgsSymbolList;
45 typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
46 
47 #include "qgslegendsymbolitem.h"
48 
49 
50 #define RENDERER_TAG_NAME "renderer-v2"
51 
53 // symbol levels
54 
59 class CORE_EXPORT QgsSymbolLevelItem
60 {
61  public:
62  QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
63  : mSymbol( symbol )
64  , mLayer( layer )
65  {}
66  QgsSymbol *symbol() { return mSymbol; }
67  int layer() { return mLayer; }
68  protected:
69  QgsSymbol *mSymbol = nullptr;
70  int mLayer;
71 };
72 
73 // every level has list of items: symbol + symbol layer num
74 typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
75 
76 // this is a list of levels
77 #ifndef SIP_RUN
78 typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
79 #else
80 typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
81 #endif
82 
83 
85 // renderers
86 
91 class CORE_EXPORT QgsFeatureRenderer
92 {
93 
94 #ifdef SIP_RUN
96 
97  const QString type = sipCpp->type();
98 
99  if ( type == QStringLiteral( "singleSymbol" ) )
100  sipType = sipType_QgsSingleSymbolRenderer;
101  else if ( type == QStringLiteral( "categorizedSymbol" ) )
102  sipType = sipType_QgsCategorizedSymbolRenderer;
103  else if ( type == QStringLiteral( "graduatedSymbol" ) )
104  sipType = sipType_QgsGraduatedSymbolRenderer;
105  else if ( type == QStringLiteral( "RuleRenderer" ) )
106  sipType = sipType_QgsRuleBasedRenderer;
107  else if ( type == QStringLiteral( "heatmapRenderer" ) )
108  sipType = sipType_QgsHeatmapRenderer;
109  else if ( type == QStringLiteral( "invertedPolygonRenderer" ) )
110  sipType = sipType_QgsInvertedPolygonRenderer;
111  else if ( type == QStringLiteral( "pointCluster" ) )
112  sipType = sipType_QgsPointClusterRenderer;
113  else if ( type == QStringLiteral( "pointDisplacement" ) )
114  sipType = sipType_QgsPointDisplacementRenderer;
115  else if ( type == QStringLiteral( "25dRenderer" ) )
116  sipType = sipType_Qgs25DRenderer;
117  else if ( type == QStringLiteral( "nullSymbol" ) )
118  sipType = sipType_QgsNullSymbolRenderer;
119  else
120  sipType = 0;
121  SIP_END
122 #endif
123 
124  public:
125  // renderer takes ownership of its symbols!
126 
128  static QgsFeatureRenderer *defaultRenderer( QgsWkbTypes::GeometryType geomType ) SIP_FACTORY;
129 
130  QString type() const { return mType; }
131 
141  virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
142 
149  virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
150 
155  virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
156 
169  virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
170 
181  virtual void stopRender( QgsRenderContext &context );
182 
194  virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
195 
202  virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
203 
207  virtual bool filterNeedsGeometry() const;
208 
209  virtual ~QgsFeatureRenderer();
210 
217  virtual QgsFeatureRenderer *clone() const = 0 SIP_FACTORY;
218 
232  virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
233 
235  virtual QString dump() const;
236 
242  {
243  SymbolLevels = 1,
244  MoreSymbolsPerFeature = 1 << 2,
245  Filter = 1 << 3,
246  ScaleDependent = 1 << 4
247  };
248 
249  Q_DECLARE_FLAGS( Capabilities, Capability )
250 
251 
263  virtual QgsFeatureRenderer::Capabilities capabilities() { return nullptr; }
264 
270  virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
271 
272  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
273  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
274 
276  static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
277 
279  virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
280 
285  virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QgsStringMap &props = QgsStringMap() ) const;
286 
298  static QgsFeatureRenderer *loadSld( const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
299 
301  virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const
302  {
303  element.appendChild( doc.createComment( QStringLiteral( "FeatureRenderer %1 not implemented yet" ).arg( type() ) ) );
304  ( void ) props; // warning avoidance
305  }
306 
311  virtual bool legendSymbolItemsCheckable() const;
312 
317  virtual bool legendSymbolItemChecked( const QString &key );
318 
323  virtual void checkLegendSymbolItem( const QString &key, bool state = true );
324 
331  virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
332 
337  virtual QgsLegendSymbolList legendSymbolItems() const;
338 
343  virtual QString legendClassificationAttribute() const { return QString(); }
344 
346  void setVertexMarkerAppearance( int type, double size );
347 
354  virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
355 
362  virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
363 
369  virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
370 
378  virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
379 
386  QgsPaintEffect *paintEffect() const;
387 
394  void setPaintEffect( QgsPaintEffect *effect );
395 
401  bool forceRasterRender() const { return mForceRaster; }
402 
411  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
412 
419  QgsFeatureRequest::OrderBy orderBy() const;
420 
427  void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
428 
435  bool orderByEnabled() const;
436 
444  void setOrderByEnabled( bool enabled );
445 
453  virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
454 
461  virtual const QgsFeatureRenderer *embeddedRenderer() const;
462 
472  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
473 
474  protected:
475  QgsFeatureRenderer( const QString &type );
476 
483  void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
484 
486  void renderVertexMarker( QPointF pt, QgsRenderContext &context );
488  void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
490  void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
491 
496  static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
497 
506  void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
507 
508  QString mType;
509 
511 
516 
517  QgsPaintEffect *mPaintEffect = nullptr;
518 
520 
525  static void convertSymbolSizeScale( QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field );
526 
531  static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
532 
534 
536 
537  private:
538 #ifdef SIP_RUN
540  QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
541 #endif
542 
543 #ifdef QGISDEBUG
544  QThread *mThread = nullptr;
546 #endif
547 
548  Q_DISABLE_COPY( QgsFeatureRenderer )
549 };
550 
551 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRenderer::Capabilities )
552 
553 // for some reason SIP compilation fails if these lines are not included:
554 class QgsRendererWidget;
556 
557 #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:40
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
Definition: qgsrenderer.h:533
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrenderer.h:343
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
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:301
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:194
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
Definition: qgsrenderer.h:401
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:273
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:612
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:78
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44
QString type() const
Definition: qgsrenderer.h:130
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
Definition: qgsrenderer.h:411
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:189
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSymbolLevelItem(QgsSymbol *symbol, int layer)
Definition: qgsrenderer.h:62
ScaleMethod
Scale method.
Definition: qgssymbol.h:94
Capability
Used to specify details about a renderer.
Definition: qgsrenderer.h:241
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:139
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:272
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:74
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
QMap< QString, QgsSymbol *> QgsSymbolMap
Definition: qgsrenderer.h:45
#define SIP_THROW(name)
Definition: qgis_sip.h:184
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:513
Represents a vector layer which manages a vector based data sets.
double mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:515
QgsSymbol * symbol()
Definition: qgsrenderer.h:66
Represents a list of OrderByClauses, with the most important first and the least important last...