QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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 "qgsconfig.h"
20
21#include "qgis.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgsfeaturerequest.h"
25#include "qgsfields.h"
27#include "qgsrectangle.h"
28
29#include <QDomDocument>
30#include <QDomElement>
31#include <QList>
32#include <QPair>
33#include <QPixmap>
34#include <QString>
35#include <QVariant>
36
37class QgsFeature;
38class QgsVectorLayer;
39class QgsPaintEffect;
46
47typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
48
49typedef QList<QgsSymbol *> QgsSymbolList;
50typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
51
52#include "qgslegendsymbolitem.h"
53
54
55#define RENDERER_TAG_NAME "renderer-v2"
56
58// symbol levels
59
65class CORE_EXPORT QgsSymbolLevelItem
66{
67 public:
72
76 QgsSymbol *symbol() const;
77
81 int layer() const;
82
83 // TODO QGIS 4.0 -> make private
84 protected:
85 QgsSymbol *mSymbol = nullptr;
86 int mLayer;
87};
88
89// every level has list of items: symbol + symbol layer num
90typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
91
92// this is a list of levels
93#ifndef SIP_RUN
94typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
95#else
96typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
97#endif
98
99
101// renderers
102
108class CORE_EXPORT QgsFeatureRenderer
109{
110
111#ifdef SIP_RUN
113
114 const QString type = sipCpp->type();
115
116 if ( type == QLatin1String( "singleSymbol" ) )
117 sipType = sipType_QgsSingleSymbolRenderer;
118 else if ( type == QLatin1String( "categorizedSymbol" ) )
119 sipType = sipType_QgsCategorizedSymbolRenderer;
120 else if ( type == QLatin1String( "graduatedSymbol" ) )
121 sipType = sipType_QgsGraduatedSymbolRenderer;
122 else if ( type == QLatin1String( "RuleRenderer" ) )
123 sipType = sipType_QgsRuleBasedRenderer;
124 else if ( type == QLatin1String( "heatmapRenderer" ) )
125 sipType = sipType_QgsHeatmapRenderer;
126 else if ( type == QLatin1String( "invertedPolygonRenderer" ) )
127 sipType = sipType_QgsInvertedPolygonRenderer;
128 else if ( type == QLatin1String( "pointCluster" ) )
129 sipType = sipType_QgsPointClusterRenderer;
130 else if ( type == QLatin1String( "pointDisplacement" ) )
131 sipType = sipType_QgsPointDisplacementRenderer;
132 else if ( type == QLatin1String( "25dRenderer" ) )
133 sipType = sipType_Qgs25DRenderer;
134 else if ( type == QLatin1String( "nullSymbol" ) )
135 sipType = sipType_QgsNullSymbolRenderer;
136 else if ( type == QLatin1String( "embeddedSymbol" ) )
137 sipType = sipType_QgsEmbeddedSymbolRenderer;
138 else
139 sipType = 0;
140 SIP_END
141#endif
142
143 public:
144
150 enum class Property : int
151 {
152 HeatmapRadius,
153 HeatmapMaximum,
154 };
155
160 static const QgsPropertiesDefinition &propertyDefinitions();
161
162 // renderer takes ownership of its symbols!
163
165 static QgsFeatureRenderer *defaultRenderer( Qgis::GeometryType geomType ) SIP_FACTORY;
166
167 QString type() const { return mType; }
168
177 virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
178
184 virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
185
189 virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
190
203 virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
204
215 virtual void stopRender( QgsRenderContext &context );
216
225 virtual bool canSkipRender();
226
238 virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
239
246 virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
247
254 virtual bool usesEmbeddedSymbols() const;
255
259 virtual bool filterNeedsGeometry() const;
260
261 virtual ~QgsFeatureRenderer();
262
270
284 virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
285
287 virtual QString dump() const;
288
294 {
297 Filter = 1 << 3,
299 };
300
301 Q_DECLARE_FLAGS( Capabilities, Capability )
302
303
316
322 virtual Qgis::FeatureRendererFlags flags() const;
323
328 virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
329
330 bool usingSymbolLevels() const { return mUsingSymbolLevels; }
332
334 static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
335
342 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
343
347 virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props = QVariantMap() ) const;
348
360 static QgsFeatureRenderer *loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
361
367 Q_DECL_DEPRECATED virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const SIP_DEPRECATED;
368
376 virtual bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const;
377
385 QSet< QString > legendKeys() const;
386
391 virtual bool legendSymbolItemsCheckable() const;
392
400 virtual bool legendSymbolItemChecked( const QString &key );
401
409 virtual void checkLegendSymbolItem( const QString &key, bool state = true );
410
419 virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
420
435 virtual QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok SIP_OUT ) const;
436
443 virtual QgsLegendSymbolList legendSymbolItems() const;
444
456 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const SIP_FACTORY;
457
461 virtual QString legendClassificationAttribute() const { return QString(); }
462
464 void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
465
471 virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
472
478 virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
479
484 virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
485
492 virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
493
499 QgsPaintEffect *paintEffect() const;
500
506 void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
507
512 bool forceRasterRender() const { return mForceRaster; }
513
521 void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
522
532 void setDataDefinedProperty( Property key, const QgsProperty &property );
533
542 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
543
551 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
552
562 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
563
578 double referenceScale() const { return mReferenceScale; }
579
594 void setReferenceScale( double scale ) { mReferenceScale = scale; }
595
601 QgsFeatureRequest::OrderBy orderBy() const;
602
608 void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
609
615 bool orderByEnabled() const;
616
623 void setOrderByEnabled( bool enabled );
624
631 virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
632
638 virtual const QgsFeatureRenderer *embeddedRenderer() const;
639
649 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
650
666 void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
667
674 double maximumExtentBuffer( QgsRenderContext &context ) const;
675
676 protected:
677 QgsFeatureRenderer( const QString &type );
678
685 void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
686
688 void renderVertexMarker( QPointF pt, QgsRenderContext &context );
690 void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
692 void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
693
698 static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
699
708 void saveRendererData( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context );
709
710 QString mType;
711
712 bool mUsingSymbolLevels = false;
713
716
719
720 std::unique_ptr<QgsPaintEffect> mPaintEffect;
721
722 bool mForceRaster = false;
723
724 double mReferenceScale = -1.0;
725
729 static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
730
734 static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
735
737
738 bool mOrderByEnabled = false;
739
740 private:
741#ifdef SIP_RUN
743 QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
744#endif
745
746 static void initPropertyDefinitions();
748 static QgsPropertiesDefinition sPropertyDefinitions;
749
750#ifdef QGISDEBUG
752 QThread *mThread = nullptr;
753#endif
754
755 QgsPropertyCollection mDataDefinedProperties;
756
757 Q_DISABLE_COPY( QgsFeatureRenderer )
758};
759
761
762// for some reason SIP compilation fails if these lines are not included:
765
766#endif // QGSRENDERER_H
ScaleMethod
Scale methods.
Definition qgis.h:624
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
Definition qgis.h:838
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition qgis.h:1833
@ Cross
Cross marker.
Definition qgis.h:1835
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for all 2D vector feature renderers.
virtual bool canSkipRender()
Returns true if the renderer can be entirely skipped, i.e.
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.
QgsFeatureRenderer(const QString &type)
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Property
Data definable properties for renderers.
QFlags< Capability > Capabilities
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
QString type() const
virtual bool usesEmbeddedSymbols() const
Returns true if the renderer uses embedded symbols for features.
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
double referenceScale() const
Returns the symbology reference scale.
void setReferenceScale(double scale)
Sets the symbology reference scale.
bool usingSymbolLevels() const
virtual QString dump() const
Returns debug information about this renderer.
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
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.
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
@ ScaleDependent
Depends on scale if feature will be rendered (rule based ).
@ SymbolLevels
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature()).
@ Filter
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ....
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the renderer's property collection, used for data defined overrides.
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Converts old rotation expressions to symbol level data defined angles.
QgsFeatureRequest::OrderBy mOrderBy
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
Qgis::VertexMarkerType mCurrentVertexMarkerType
The current type of editing marker.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the renderer's property collection, used for data defined overrides.
double mCurrentVertexMarkerSize
The current size of editing marker.
std::unique_ptr< QgsPaintEffect > mPaintEffect
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
static void convertSymbolSizeScale(QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field)
Converts old sizeScale expressions to symbol level data defined sizes.
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.
int layer() const
The layer of this symbol level.
QgsSymbolLevelItem(QgsSymbol *symbol, int layer)
Definition qgsrenderer.h:68
QgsSymbol * mSymbol
Definition qgsrenderer.h:85
QgsSymbol * symbol() const
The symbol of this symbol level.
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:7132
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
#define SIP_END
Definition qgis_sip.h:216
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition qgsrenderer.h:94
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition qgsrenderer.h:90
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:50
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:49