QGIS API Documentation  3.0.2-Girona (307d082)
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 
165  virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
166 
177  virtual void stopRender( QgsRenderContext &context );
178 
190  virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ); return QString(); }
191 
198  virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
199 
203  virtual bool filterNeedsGeometry() const;
204 
205  virtual ~QgsFeatureRenderer();
206 
213  virtual QgsFeatureRenderer *clone() const = 0 SIP_FACTORY;
214 
228  virtual bool renderFeature( QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
229 
231  virtual QString dump() const;
232 
238  {
239  SymbolLevels = 1,
240  MoreSymbolsPerFeature = 1 << 2,
241  Filter = 1 << 3,
242  ScaleDependent = 1 << 4
243  };
244 
245  Q_DECLARE_FLAGS( Capabilities, Capability )
246 
247 
259  virtual QgsFeatureRenderer::Capabilities capabilities() { return nullptr; }
260 
266  virtual QgsSymbolList symbols( QgsRenderContext &context ) { Q_UNUSED( context ); return QgsSymbolList(); }
267 
268  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
269  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
270 
272  static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
273 
275  virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
276 
281  virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QgsStringMap &props = QgsStringMap() ) const;
282 
294  static QgsFeatureRenderer *loadSld( const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
295 
297  virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const
298  {
299  element.appendChild( doc.createComment( QStringLiteral( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) );
300  ( void ) props; // warning avoidance
301  }
302 
307  virtual bool legendSymbolItemsCheckable() const;
308 
313  virtual bool legendSymbolItemChecked( const QString &key );
314 
319  virtual void checkLegendSymbolItem( const QString &key, bool state = true );
320 
327  virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
328 
333  virtual QgsLegendSymbolList legendSymbolItems() const;
334 
339  virtual QString legendClassificationAttribute() const { return QString(); }
340 
342  void setVertexMarkerAppearance( int type, int size );
343 
350  virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
351 
358  virtual QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
359 
365  virtual QgsSymbolList originalSymbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
366 
374  virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
375 
382  QgsPaintEffect *paintEffect() const;
383 
390  void setPaintEffect( QgsPaintEffect *effect );
391 
397  bool forceRasterRender() const { return mForceRaster; }
398 
407  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
408 
415  QgsFeatureRequest::OrderBy orderBy() const;
416 
423  void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
424 
431  bool orderByEnabled() const;
432 
440  void setOrderByEnabled( bool enabled );
441 
449  virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) { delete subRenderer; }
450 
457  virtual const QgsFeatureRenderer *embeddedRenderer() const { return nullptr; }
458 
459  protected:
460  QgsFeatureRenderer( const QString &type );
461 
462  void renderFeatureWithSymbol( QgsFeature &feature,
463  QgsSymbol *symbol,
464  QgsRenderContext &context,
465  int layer,
466  bool selected,
467  bool drawVertexMarker );
468 
470  void renderVertexMarker( QPointF pt, QgsRenderContext &context );
472  void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
474  void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
475 
480  static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
481 
490  void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
491 
492  QString mType;
493 
495 
500 
501  QgsPaintEffect *mPaintEffect = nullptr;
502 
504 
509  static void convertSymbolSizeScale( QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field );
510 
515  static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
516 
518 
520 
521  private:
522 #ifdef SIP_RUN
524  QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
525 #endif
526 
527 #ifdef QGISDEBUG
528  QThread *mThread = nullptr;
530 #endif
531 
532  Q_DISABLE_COPY( QgsFeatureRenderer )
533 };
534 
535 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRenderer::Capabilities )
536 
537 // for some reason SIP compilation fails if these lines are not included:
538 class QgsRendererWidget;
540 
541 #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:517
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrenderer.h:339
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:297
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:190
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
Definition: qgsrenderer.h:397
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:269
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:479
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:407
#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:237
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:449
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:266
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.h:457
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:268
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:73
int mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:499
#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:374
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:497
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...