QGIS API Documentation 3.39.0-Master (d0dedde5474)
Loading...
Searching...
No Matches
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
62class CORE_EXPORT QgsSymbolLevelItem
63{
64 public:
65 QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
66 : mSymbol( symbol )
67 , mLayer( layer )
68 {}
69
73 QgsSymbol *symbol() const;
74
78 int layer() const;
79
80 // TODO QGIS 4.0 -> make private
81 protected:
82 QgsSymbol *mSymbol = nullptr;
83 int mLayer;
84};
85
86// every level has list of items: symbol + symbol layer num
87typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
88
89// this is a list of levels
90#ifndef SIP_RUN
91typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
92#else
93typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
94#endif
95
96
98// renderers
99
105class CORE_EXPORT QgsFeatureRenderer
106{
107
108#ifdef SIP_RUN
110
111 const QString type = sipCpp->type();
112
113 if ( type == QLatin1String( "singleSymbol" ) )
114 sipType = sipType_QgsSingleSymbolRenderer;
115 else if ( type == QLatin1String( "categorizedSymbol" ) )
116 sipType = sipType_QgsCategorizedSymbolRenderer;
117 else if ( type == QLatin1String( "graduatedSymbol" ) )
118 sipType = sipType_QgsGraduatedSymbolRenderer;
119 else if ( type == QLatin1String( "RuleRenderer" ) )
120 sipType = sipType_QgsRuleBasedRenderer;
121 else if ( type == QLatin1String( "heatmapRenderer" ) )
122 sipType = sipType_QgsHeatmapRenderer;
123 else if ( type == QLatin1String( "invertedPolygonRenderer" ) )
124 sipType = sipType_QgsInvertedPolygonRenderer;
125 else if ( type == QLatin1String( "pointCluster" ) )
126 sipType = sipType_QgsPointClusterRenderer;
127 else if ( type == QLatin1String( "pointDisplacement" ) )
128 sipType = sipType_QgsPointDisplacementRenderer;
129 else if ( type == QLatin1String( "25dRenderer" ) )
130 sipType = sipType_Qgs25DRenderer;
131 else if ( type == QLatin1String( "nullSymbol" ) )
132 sipType = sipType_QgsNullSymbolRenderer;
133 else if ( type == QLatin1String( "embeddedSymbol" ) )
134 sipType = sipType_QgsEmbeddedSymbolRenderer;
135 else
136 sipType = 0;
137 SIP_END
138#endif
139
140 public:
141
147 enum class Property : int
148 {
149 HeatmapRadius,
150 HeatmapMaximum,
151 };
152
157 static const QgsPropertiesDefinition &propertyDefinitions();
158
159 // renderer takes ownership of its symbols!
160
162 static QgsFeatureRenderer *defaultRenderer( Qgis::GeometryType geomType ) SIP_FACTORY;
163
164 QString type() const { return mType; }
165
174 virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
175
181 virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
182
186 virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
187
200 virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
201
212 virtual void stopRender( QgsRenderContext &context );
213
222 virtual bool canSkipRender();
223
235 virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
236
243 virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
244
251 virtual bool usesEmbeddedSymbols() const;
252
256 virtual bool filterNeedsGeometry() const;
257
258 virtual ~QgsFeatureRenderer();
259
267
281 virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
282
284 virtual QString dump() const;
285
291 {
292 SymbolLevels = 1,
293 MoreSymbolsPerFeature = 1 << 2,
294 Filter = 1 << 3,
295 ScaleDependent = 1 << 4
296 };
297
298 Q_DECLARE_FLAGS( Capabilities, Capability )
299
300
313
318 virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
319
320 bool usingSymbolLevels() const { return mUsingSymbolLevels; }
321 void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
322
324 static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
325
332 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
333
337 virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props = QVariantMap() ) const;
338
350 static QgsFeatureRenderer *loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
351
353 virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const
354 {
355 element.appendChild( doc.createComment( QStringLiteral( "FeatureRenderer %1 not implemented yet" ).arg( type() ) ) );
356 ( void ) props; // warning avoidance
357 }
358
366 QSet< QString > legendKeys() const;
367
372 virtual bool legendSymbolItemsCheckable() const;
373
381 virtual bool legendSymbolItemChecked( const QString &key );
382
390 virtual void checkLegendSymbolItem( const QString &key, bool state = true );
391
400 virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
401
416 virtual QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok SIP_OUT ) const;
417
424 virtual QgsLegendSymbolList legendSymbolItems() const;
425
437 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const SIP_FACTORY;
438
442 virtual QString legendClassificationAttribute() const { return QString(); }
443
445 void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
446
452 virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
453
459 virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
460
465 virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
466
473 virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
474
480 QgsPaintEffect *paintEffect() const;
481
487 void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
488
493 bool forceRasterRender() const { return mForceRaster; }
494
502 void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
503
513 void setDataDefinedProperty( Property key, const QgsProperty &property );
514
523 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
524
532 const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
533
543 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
544
559 double referenceScale() const { return mReferenceScale; }
560
575 void setReferenceScale( double scale ) { mReferenceScale = scale; }
576
582 QgsFeatureRequest::OrderBy orderBy() const;
583
589 void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
590
596 bool orderByEnabled() const;
597
604 void setOrderByEnabled( bool enabled );
605
612 virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
613
619 virtual const QgsFeatureRenderer *embeddedRenderer() const;
620
630 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
631
647 void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
648
649 protected:
650 QgsFeatureRenderer( const QString &type );
651
658 void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
659
661 void renderVertexMarker( QPointF pt, QgsRenderContext &context );
663 void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
665 void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
666
671 static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
672
681 void saveRendererData( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context );
682
683 QString mType;
684
685 bool mUsingSymbolLevels = false;
686
689
691 double mCurrentVertexMarkerSize = 2;
692
693 QgsPaintEffect *mPaintEffect = nullptr;
694
695 bool mForceRaster = false;
696
697 double mReferenceScale = -1.0;
698
703 static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
704
709 static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
710
712
713 bool mOrderByEnabled = false;
714
715 private:
716#ifdef SIP_RUN
718 QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
719#endif
720
721 static void initPropertyDefinitions();
723 static QgsPropertiesDefinition sPropertyDefinitions;
724
725#ifdef QGISDEBUG
727 QThread *mThread = nullptr;
728#endif
729
730 QgsPropertyCollection mDataDefinedProperties;
731
732 Q_DISABLE_COPY( QgsFeatureRenderer )
733};
734
736
737// for some reason SIP compilation fails if these lines are not included:
740
741#endif // QGSRENDERER_H
ScaleMethod
Scale methods.
Definition qgis.h:588
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:1659
@ 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.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
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 a integer key value.
A store for object properties.
The class is used as a container of context for various read/write operations on other 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.
QgsSymbolLevelItem(QgsSymbol *symbol, int layer)
Definition qgsrenderer.h:65
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Represents a vector layer which manages a vector based data sets.
QMap< QString, QString > QgsStringMap
Definition qgis.h:6333
#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:91
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition qgsrenderer.h:87
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:48
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:47
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)