QGIS API Documentation  3.6.0-Noosa (5873452)
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;
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 
96  const QString type = sipCpp->type();
97 
98  if ( type == QStringLiteral( "singleSymbol" ) )
99  sipType = sipType_QgsSingleSymbolRenderer;
100  else if ( type == QStringLiteral( "categorizedSymbol" ) )
101  sipType = sipType_QgsCategorizedSymbolRenderer;
102  else if ( type == QStringLiteral( "graduatedSymbol" ) )
103  sipType = sipType_QgsGraduatedSymbolRenderer;
104  else if ( type == QStringLiteral( "RuleRenderer" ) )
105  sipType = sipType_QgsRuleBasedRenderer;
106  else if ( type == QStringLiteral( "heatmapRenderer" ) )
107  sipType = sipType_QgsHeatmapRenderer;
108  else if ( type == QStringLiteral( "invertedPolygonRenderer" ) )
109  sipType = sipType_QgsInvertedPolygonRenderer;
110  else if ( type == QStringLiteral( "pointCluster" ) )
111  sipType = sipType_QgsPointClusterRenderer;
112  else if ( type == QStringLiteral( "pointDisplacement" ) )
113  sipType = sipType_QgsPointDisplacementRenderer;
114  else if ( type == QStringLiteral( "25dRenderer" ) )
115  sipType = sipType_Qgs25DRenderer;
116  else if ( type == QStringLiteral( "nullSymbol" ) )
117  sipType = sipType_QgsNullSymbolRenderer;
118  else
119  sipType = 0;
120  SIP_END
121 #endif
122 
123  public:
124  // renderer takes ownership of its symbols!
125 
127  static QgsFeatureRenderer *defaultRenderer( QgsWkbTypes::GeometryType geomType ) SIP_FACTORY;
128 
129  QString type() const { return mType; }
130 
140  virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
141 
148  virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
149 
154  virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
155 
168  virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
169 
180  virtual void stopRender( QgsRenderContext &context );
181 
193  virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ); return QString(); }
194 
201  virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
202 
206  virtual bool filterNeedsGeometry() const;
207 
208  virtual ~QgsFeatureRenderer();
209 
216  virtual QgsFeatureRenderer *clone() const = 0 SIP_FACTORY;
217 
231  virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
232 
234  virtual QString dump() const;
235 
241  {
242  SymbolLevels = 1,
243  MoreSymbolsPerFeature = 1 << 2,
244  Filter = 1 << 3,
245  ScaleDependent = 1 << 4
246  };
247 
248  Q_DECLARE_FLAGS( Capabilities, Capability )
249 
250 
262  virtual QgsFeatureRenderer::Capabilities capabilities() { return nullptr; }
263 
269  virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
270 
271  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
272  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
273 
275  static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
276 
278  virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
279 
284  virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QgsStringMap &props = QgsStringMap() ) const;
285 
297  static QgsFeatureRenderer *loadSld( const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
298 
300  virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const
301  {
302  element.appendChild( doc.createComment( QStringLiteral( "FeatureRenderer %1 not implemented yet" ).arg( type() ) ) );
303  ( void ) props; // warning avoidance
304  }
305 
310  virtual bool legendSymbolItemsCheckable() const;
311 
316  virtual bool legendSymbolItemChecked( const QString &key );
317 
322  virtual void checkLegendSymbolItem( const QString &key, bool state = true );
323 
330  virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
331 
336  virtual QgsLegendSymbolList legendSymbolItems() const;
337 
342  virtual QString legendClassificationAttribute() const { return QString(); }
343 
345  void setVertexMarkerAppearance( int type, double size );
346 
353  virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
354 
361  virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
362 
368  virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
369 
377  virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
378 
385  QgsPaintEffect *paintEffect() const;
386 
393  void setPaintEffect( QgsPaintEffect *effect );
394 
400  bool forceRasterRender() const { return mForceRaster; }
401 
410  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
411 
418  QgsFeatureRequest::OrderBy orderBy() const;
419 
426  void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
427 
434  bool orderByEnabled() const;
435 
443  void setOrderByEnabled( bool enabled );
444 
452  virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
453 
460  virtual const QgsFeatureRenderer *embeddedRenderer() const;
461 
462  protected:
463  QgsFeatureRenderer( const QString &type );
464 
471  void renderFeatureWithSymbol( const QgsFeature &feature,
472  QgsSymbol *symbol,
473  QgsRenderContext &context,
474  int layer,
475  bool selected,
476  bool drawVertexMarker );
477 
479  void renderVertexMarker( QPointF pt, QgsRenderContext &context );
481  void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
483  void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
484 
489  static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
490 
499  void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
500 
501  QString mType;
502 
504 
509 
510  QgsPaintEffect *mPaintEffect = nullptr;
511 
513 
518  static void convertSymbolSizeScale( QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field );
519 
524  static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
525 
527 
529 
530  private:
531 #ifdef SIP_RUN
533  QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
534 #endif
535 
536 #ifdef QGISDEBUG
537  QThread *mThread = nullptr;
539 #endif
540 
541  Q_DISABLE_COPY( QgsFeatureRenderer )
542 };
543 
544 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRenderer::Capabilities )
545 
546 // for some reason SIP compilation fails if these lines are not included:
547 class QgsRendererWidget;
549 
550 #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:39
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
Definition: qgsrenderer.h:526
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrenderer.h:342
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:300
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:193
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
Definition: qgsrenderer.h:400
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:272
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QMap< QString, QString > QgsStringMap
Definition: qgis.h:587
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:77
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:43
QString type() const
Definition: qgsrenderer.h:129
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
Definition: qgsrenderer.h:410
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:182
#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:240
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:138
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:271
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:73
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
QMap< QString, QgsSymbol *> QgsSymbolMap
Definition: qgsrenderer.h:44
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:506
Represents a vector layer which manages a vector based data sets.
double mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:508
QgsSymbol * symbol()
Definition: qgsrenderer.h:65
Represents a list of OrderByClauses, with the most important first and the least important last...