QGIS API Documentation 3.43.0-Master (56aa1fd18d7)
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 "qgsfields.h"
24#include "qgsfeaturerequest.h"
25#include "qgsconfig.h"
27
28#include <QList>
29#include <QString>
30#include <QVariant>
31#include <QPair>
32#include <QPixmap>
33#include <QDomDocument>
34#include <QDomElement>
35
36class QgsFeature;
37class QgsVectorLayer;
38class QgsPaintEffect;
45
46typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
47
48typedef QList<QgsSymbol *> QgsSymbolList;
49typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
50
51#include "qgslegendsymbolitem.h"
52
53
54#define RENDERER_TAG_NAME "renderer-v2"
55
57// symbol levels
58
64class CORE_EXPORT QgsSymbolLevelItem
65{
66 public:
67 QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
68 : mSymbol( symbol )
69 , mLayer( layer )
70 {}
71
75 QgsSymbol *symbol() const;
76
80 int layer() const;
81
82 // TODO QGIS 4.0 -> make private
83 protected:
84 QgsSymbol *mSymbol = nullptr;
85 int mLayer;
86};
87
88// every level has list of items: symbol + symbol layer num
89typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
90
91// this is a list of levels
92#ifndef SIP_RUN
93typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
94#else
95typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
96#endif
97
98
100// renderers
101
107class CORE_EXPORT QgsFeatureRenderer
108{
109
110#ifdef SIP_RUN
112
113 const QString type = sipCpp->type();
114
115 if ( type == QLatin1String( "singleSymbol" ) )
116 sipType = sipType_QgsSingleSymbolRenderer;
117 else if ( type == QLatin1String( "categorizedSymbol" ) )
118 sipType = sipType_QgsCategorizedSymbolRenderer;
119 else if ( type == QLatin1String( "graduatedSymbol" ) )
120 sipType = sipType_QgsGraduatedSymbolRenderer;
121 else if ( type == QLatin1String( "RuleRenderer" ) )
122 sipType = sipType_QgsRuleBasedRenderer;
123 else if ( type == QLatin1String( "heatmapRenderer" ) )
124 sipType = sipType_QgsHeatmapRenderer;
125 else if ( type == QLatin1String( "invertedPolygonRenderer" ) )
126 sipType = sipType_QgsInvertedPolygonRenderer;
127 else if ( type == QLatin1String( "pointCluster" ) )
128 sipType = sipType_QgsPointClusterRenderer;
129 else if ( type == QLatin1String( "pointDisplacement" ) )
130 sipType = sipType_QgsPointDisplacementRenderer;
131 else if ( type == QLatin1String( "25dRenderer" ) )
132 sipType = sipType_Qgs25DRenderer;
133 else if ( type == QLatin1String( "nullSymbol" ) )
134 sipType = sipType_QgsNullSymbolRenderer;
135 else if ( type == QLatin1String( "embeddedSymbol" ) )
136 sipType = sipType_QgsEmbeddedSymbolRenderer;
137 else
138 sipType = 0;
139 SIP_END
140#endif
141
142 public:
143
149 enum class Property : int
150 {
151 HeatmapRadius,
152 HeatmapMaximum,
153 };
154
159 static const QgsPropertiesDefinition &propertyDefinitions();
160
161 // renderer takes ownership of its symbols!
162
164 static QgsFeatureRenderer *defaultRenderer( Qgis::GeometryType geomType ) SIP_FACTORY;
165
166 QString type() const { return mType; }
167
176 virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
177
183 virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
184
188 virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
189
202 virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
203
214 virtual void stopRender( QgsRenderContext &context );
215
224 virtual bool canSkipRender();
225
237 virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
238
245 virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
246
253 virtual bool usesEmbeddedSymbols() const;
254
258 virtual bool filterNeedsGeometry() const;
259
260 virtual ~QgsFeatureRenderer();
261
269
283 virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
284
286 virtual QString dump() const;
287
293 {
294 SymbolLevels = 1,
295 MoreSymbolsPerFeature = 1 << 2,
296 Filter = 1 << 3,
297 ScaleDependent = 1 << 4
298 };
299
300 Q_DECLARE_FLAGS( Capabilities, Capability )
301
302
315
321 virtual Qgis::FeatureRendererFlags flags() const;
322
327 virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
328
329 bool usingSymbolLevels() const { return mUsingSymbolLevels; }
330 void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
331
333 static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
334
341 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
342
346 virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props = QVariantMap() ) const;
347
359 static QgsFeatureRenderer *loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
360
366 Q_DECL_DEPRECATED virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const SIP_DEPRECATED;
367
375 virtual bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const;
376
384 QSet< QString > legendKeys() const;
385
390 virtual bool legendSymbolItemsCheckable() const;
391
399 virtual bool legendSymbolItemChecked( const QString &key );
400
408 virtual void checkLegendSymbolItem( const QString &key, bool state = true );
409
418 virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
419
434 virtual QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok SIP_OUT ) const;
435
442 virtual QgsLegendSymbolList legendSymbolItems() const;
443
455 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const SIP_FACTORY;
456
460 virtual QString legendClassificationAttribute() const { return QString(); }
461
463 void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
464
470 virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
471
477 virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
478
483 virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
484
491 virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
492
498 QgsPaintEffect *paintEffect() const;
499
505 void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
506
511 bool forceRasterRender() const { return mForceRaster; }
512
520 void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
521
531 void setDataDefinedProperty( Property key, const QgsProperty &property );
532
541 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
542
550 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
551
561 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
562
577 double referenceScale() const { return mReferenceScale; }
578
593 void setReferenceScale( double scale ) { mReferenceScale = scale; }
594
600 QgsFeatureRequest::OrderBy orderBy() const;
601
607 void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
608
614 bool orderByEnabled() const;
615
622 void setOrderByEnabled( bool enabled );
623
630 virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
631
637 virtual const QgsFeatureRenderer *embeddedRenderer() const;
638
648 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
649
665 void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
666
673 double maximumExtentBuffer( QgsRenderContext &context ) const;
674
675 protected:
676 QgsFeatureRenderer( const QString &type );
677
684 void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
685
687 void renderVertexMarker( QPointF pt, QgsRenderContext &context );
689 void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
691 void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
692
697 static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
698
707 void saveRendererData( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context );
708
709 QString mType;
710
711 bool mUsingSymbolLevels = false;
712
715
717 double mCurrentVertexMarkerSize = 2;
718
719 std::unique_ptr<QgsPaintEffect> mPaintEffect;
720
721 bool mForceRaster = false;
722
723 double mReferenceScale = -1.0;
724
728 static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
729
733 static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
734
736
737 bool mOrderByEnabled = false;
738
739 private:
740#ifdef SIP_RUN
742 QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
743#endif
744
745 static void initPropertyDefinitions();
747 static QgsPropertiesDefinition sPropertyDefinitions;
748
749#ifdef QGISDEBUG
751 QThread *mThread = nullptr;
752#endif
753
754 QgsPropertyCollection mDataDefinedProperties;
755
756 Q_DISABLE_COPY( QgsFeatureRenderer )
757};
758
760
761// for some reason SIP compilation fails if these lines are not included:
764
765#endif // QGSRENDERER_H
ScaleMethod
Scale methods.
Definition qgis.h:588
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
Definition qgis.h:802
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition qgis.h:1796
@ Cross
Cross marker.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for all 2D vector feature renderers.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the renderer's property collection, used for data defined overrides.
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...
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
Property
Data definable properties for renderers.
QFlags< Capability > Capabilities
QString type() const
double referenceScale() const
Returns the symbology reference scale.
void setReferenceScale(double scale)
Sets the symbology reference scale.
bool usingSymbolLevels() const
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
void setUsingSymbolLevels(bool usingSymbolLevels)
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
Capability
Used to specify details about a renderer.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the renderer's property collection, used for data defined overrides.
QgsFeatureRequest::OrderBy mOrderBy
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the renderer's property collection, used for data defined overrides.
std::unique_ptr< QgsPaintEffect > mPaintEffect
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
Represents a list of OrderByClauses, with the most important first and the least important last.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Container of fields for a vector layer.
Definition qgsfields.h:46
Layer tree node points to a map layer.
An abstract interface for legend items returned from QgsMapLayerLegend implementation.
Base class for effect properties widgets.
Base class for visual effects which can be applied to QPicture drawings.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
A store for object properties.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Base class for renderer settings widgets.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
An interface for classes which can visit style entity (e.g.
Represents a symbol level during vector rendering operations.
Definition qgsrenderer.h:65
QgsSymbolLevelItem(QgsSymbol *symbol, int layer)
Definition qgsrenderer.h:67
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Represents a vector layer which manages a vector based dataset.
QMap< QString, QString > QgsStringMap
Definition qgis.h:6816
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
#define SIP_END
Definition qgis_sip.h:208
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition qgsrenderer.h:93
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition qgsrenderer.h:89
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:49
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:48
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)