QGIS API Documentation 3.43.0-Master (32433f7016e)
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;
44
45typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
46
47typedef QList<QgsSymbol *> QgsSymbolList;
48typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
49
50#include "qgslegendsymbolitem.h"
51
52
53#define RENDERER_TAG_NAME "renderer-v2"
54
56// symbol levels
57
63class CORE_EXPORT QgsSymbolLevelItem
64{
65 public:
66 QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
67 : mSymbol( symbol )
68 , mLayer( layer )
69 {}
70
74 QgsSymbol *symbol() const;
75
79 int layer() const;
80
81 // TODO QGIS 4.0 -> make private
82 protected:
83 QgsSymbol *mSymbol = nullptr;
84 int mLayer;
85};
86
87// every level has list of items: symbol + symbol layer num
88typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
89
90// this is a list of levels
91#ifndef SIP_RUN
92typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
93#else
94typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
95#endif
96
97
99// renderers
100
106class CORE_EXPORT QgsFeatureRenderer
107{
108
109#ifdef SIP_RUN
111
112 const QString type = sipCpp->type();
113
114 if ( type == QLatin1String( "singleSymbol" ) )
115 sipType = sipType_QgsSingleSymbolRenderer;
116 else if ( type == QLatin1String( "categorizedSymbol" ) )
117 sipType = sipType_QgsCategorizedSymbolRenderer;
118 else if ( type == QLatin1String( "graduatedSymbol" ) )
119 sipType = sipType_QgsGraduatedSymbolRenderer;
120 else if ( type == QLatin1String( "RuleRenderer" ) )
121 sipType = sipType_QgsRuleBasedRenderer;
122 else if ( type == QLatin1String( "heatmapRenderer" ) )
123 sipType = sipType_QgsHeatmapRenderer;
124 else if ( type == QLatin1String( "invertedPolygonRenderer" ) )
125 sipType = sipType_QgsInvertedPolygonRenderer;
126 else if ( type == QLatin1String( "pointCluster" ) )
127 sipType = sipType_QgsPointClusterRenderer;
128 else if ( type == QLatin1String( "pointDisplacement" ) )
129 sipType = sipType_QgsPointDisplacementRenderer;
130 else if ( type == QLatin1String( "25dRenderer" ) )
131 sipType = sipType_Qgs25DRenderer;
132 else if ( type == QLatin1String( "nullSymbol" ) )
133 sipType = sipType_QgsNullSymbolRenderer;
134 else if ( type == QLatin1String( "embeddedSymbol" ) )
135 sipType = sipType_QgsEmbeddedSymbolRenderer;
136 else
137 sipType = 0;
138 SIP_END
139#endif
140
141 public:
142
148 enum class Property : int
149 {
150 HeatmapRadius,
151 HeatmapMaximum,
152 };
153
158 static const QgsPropertiesDefinition &propertyDefinitions();
159
160 // renderer takes ownership of its symbols!
161
163 static QgsFeatureRenderer *defaultRenderer( Qgis::GeometryType geomType ) SIP_FACTORY;
164
165 QString type() const { return mType; }
166
175 virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
176
182 virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
183
187 virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
188
201 virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
202
213 virtual void stopRender( QgsRenderContext &context );
214
223 virtual bool canSkipRender();
224
236 virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
237
244 virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
245
252 virtual bool usesEmbeddedSymbols() const;
253
257 virtual bool filterNeedsGeometry() const;
258
259 virtual ~QgsFeatureRenderer();
260
268
282 virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
283
285 virtual QString dump() const;
286
292 {
293 SymbolLevels = 1,
294 MoreSymbolsPerFeature = 1 << 2,
295 Filter = 1 << 3,
296 ScaleDependent = 1 << 4
297 };
298
299 Q_DECLARE_FLAGS( Capabilities, Capability )
300
301
314
320 virtual Qgis::FeatureRendererFlags flags() const;
321
326 virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
327
328 bool usingSymbolLevels() const { return mUsingSymbolLevels; }
329 void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
330
332 static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
333
340 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
341
345 virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props = QVariantMap() ) const;
346
358 static QgsFeatureRenderer *loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
359
361 virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const
362 {
363 element.appendChild( doc.createComment( QStringLiteral( "FeatureRenderer %1 not implemented yet" ).arg( type() ) ) );
364 ( void ) props; // warning avoidance
365 }
366
374 QSet< QString > legendKeys() const;
375
380 virtual bool legendSymbolItemsCheckable() const;
381
389 virtual bool legendSymbolItemChecked( const QString &key );
390
398 virtual void checkLegendSymbolItem( const QString &key, bool state = true );
399
408 virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
409
424 virtual QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok SIP_OUT ) const;
425
432 virtual QgsLegendSymbolList legendSymbolItems() const;
433
445 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const SIP_FACTORY;
446
450 virtual QString legendClassificationAttribute() const { return QString(); }
451
453 void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
454
460 virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
461
467 virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
468
473 virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
474
481 virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
482
488 QgsPaintEffect *paintEffect() const;
489
495 void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
496
501 bool forceRasterRender() const { return mForceRaster; }
502
510 void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
511
521 void setDataDefinedProperty( Property key, const QgsProperty &property );
522
531 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
532
540 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
541
551 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
552
567 double referenceScale() const { return mReferenceScale; }
568
583 void setReferenceScale( double scale ) { mReferenceScale = scale; }
584
590 QgsFeatureRequest::OrderBy orderBy() const;
591
597 void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
598
604 bool orderByEnabled() const;
605
612 void setOrderByEnabled( bool enabled );
613
620 virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
621
627 virtual const QgsFeatureRenderer *embeddedRenderer() const;
628
638 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
639
655 void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
656
663 double maximumExtentBuffer( QgsRenderContext &context ) const;
664
665 protected:
666 QgsFeatureRenderer( const QString &type );
667
674 void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
675
677 void renderVertexMarker( QPointF pt, QgsRenderContext &context );
679 void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
681 void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
682
687 static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
688
697 void saveRendererData( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context );
698
699 QString mType;
700
701 bool mUsingSymbolLevels = false;
702
705
707 double mCurrentVertexMarkerSize = 2;
708
709 QgsPaintEffect *mPaintEffect = nullptr;
710
711 bool mForceRaster = false;
712
713 double mReferenceScale = -1.0;
714
718 static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
719
723 static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
724
726
727 bool mOrderByEnabled = false;
728
729 private:
730#ifdef SIP_RUN
732 QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
733#endif
734
735 static void initPropertyDefinitions();
737 static QgsPropertiesDefinition sPropertyDefinitions;
738
739#ifdef QGISDEBUG
741 QThread *mThread = nullptr;
742#endif
743
744 QgsPropertyCollection mDataDefinedProperties;
745
746 Q_DISABLE_COPY( QgsFeatureRenderer )
747};
748
750
751// for some reason SIP compilation fails if these lines are not included:
754
755#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
virtual void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
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.
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.
An interface for classes which can visit style entity (e.g.
Represents a symbol level during vector rendering operations.
Definition qgsrenderer.h:64
QgsSymbolLevelItem(QgsSymbol *symbol, int layer)
Definition qgsrenderer.h:66
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:6780
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#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:92
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition qgsrenderer.h:88
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:48
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:47
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)