QGIS API Documentation 3.99.0-Master (d270888f95f)
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
37using namespace Qt::StringLiterals;
38
39class QgsFeature;
40class QgsVectorLayer;
41class QgsPaintEffect;
48
49typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
50
51typedef QList<QgsSymbol *> QgsSymbolList;
52typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
53
54#include "qgslegendsymbolitem.h"
55
56
57#define RENDERER_TAG_NAME "renderer-v2"
58
60// symbol levels
61
67class CORE_EXPORT QgsSymbolLevelItem
68{
69 public:
74
78 QgsSymbol *symbol() const;
79
83 int layer() const;
84
85 // TODO QGIS 5.0 -> make private
86 protected:
87 QgsSymbol *mSymbol = nullptr;
88 int mLayer;
89};
90
91// every level has list of items: symbol + symbol layer num
92typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
93
94// this is a list of levels
95#ifndef SIP_RUN
96typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
97#else
98typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
99#endif
100
101
103// renderers
104
110class CORE_EXPORT QgsFeatureRenderer
111{
112
113#ifdef SIP_RUN
115
116 const QString type = sipCpp->type();
117
118 if ( type == "singleSymbol"_L1 )
119 sipType = sipType_QgsSingleSymbolRenderer;
120 else if ( type == "categorizedSymbol"_L1 )
121 sipType = sipType_QgsCategorizedSymbolRenderer;
122 else if ( type == "graduatedSymbol"_L1 )
123 sipType = sipType_QgsGraduatedSymbolRenderer;
124 else if ( type == "RuleRenderer"_L1 )
125 sipType = sipType_QgsRuleBasedRenderer;
126 else if ( type == "heatmapRenderer"_L1 )
127 sipType = sipType_QgsHeatmapRenderer;
128 else if ( type == "invertedPolygonRenderer"_L1 )
129 sipType = sipType_QgsInvertedPolygonRenderer;
130 else if ( type == "pointCluster"_L1 )
131 sipType = sipType_QgsPointClusterRenderer;
132 else if ( type == "pointDisplacement"_L1 )
133 sipType = sipType_QgsPointDisplacementRenderer;
134 else if ( type == "25dRenderer"_L1 )
135 sipType = sipType_Qgs25DRenderer;
136 else if ( type == "nullSymbol"_L1 )
137 sipType = sipType_QgsNullSymbolRenderer;
138 else if ( type == "embeddedSymbol"_L1 )
139 sipType = sipType_QgsEmbeddedSymbolRenderer;
140 else
141 sipType = 0;
142 SIP_END
143#endif
144
145 public:
146
152 enum class Property : int
153 {
154 HeatmapRadius,
155 HeatmapMaximum,
156 };
157
162 static const QgsPropertiesDefinition &propertyDefinitions();
163
164 // renderer takes ownership of its symbols!
165
167 static QgsFeatureRenderer *defaultRenderer( Qgis::GeometryType geomType ) SIP_FACTORY;
168
169 QString type() const { return mType; }
170
179 virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
180
186 virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
187
191 virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
192
205 virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
206
217 virtual void stopRender( QgsRenderContext &context );
218
227 virtual bool canSkipRender();
228
240 virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
241
248 virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
249
256 virtual bool usesEmbeddedSymbols() const;
257
261 virtual bool filterNeedsGeometry() const;
262
263 virtual ~QgsFeatureRenderer();
264
272
286 virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
287
289 virtual QString dump() const;
290
296 {
299 Filter = 1 << 3,
301 };
302
303 Q_DECLARE_FLAGS( Capabilities, Capability )
304
305
318
324 virtual Qgis::FeatureRendererFlags flags() const;
325
330 virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
331
332 bool usingSymbolLevels() const { return mUsingSymbolLevels; }
334
336 static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
337
344 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
345
349 virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props = QVariantMap() ) const;
350
362 static QgsFeatureRenderer *loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
363
369 Q_DECL_DEPRECATED virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const SIP_DEPRECATED;
370
378 virtual bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const;
379
387 QSet< QString > legendKeys() const;
388
393 virtual bool legendSymbolItemsCheckable() const;
394
402 virtual bool legendSymbolItemChecked( const QString &key );
403
411 virtual void checkLegendSymbolItem( const QString &key, bool state = true );
412
421 virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
422
437 virtual QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok SIP_OUT ) const;
438
445 virtual QgsLegendSymbolList legendSymbolItems() const;
446
458 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const SIP_FACTORY;
459
463 virtual QString legendClassificationAttribute() const { return QString(); }
464
466 void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
467
473 virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
474
480 virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
481
486 virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
487
494 virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
495
501 QgsPaintEffect *paintEffect() const;
502
508 void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
509
514 bool forceRasterRender() const { return mForceRaster; }
515
523 void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
524
534 void setDataDefinedProperty( Property key, const QgsProperty &property );
535
544 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
545
553 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
554
564 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
565
580 double referenceScale() const { return mReferenceScale; }
581
596 void setReferenceScale( double scale ) { mReferenceScale = scale; }
597
603 QgsFeatureRequest::OrderBy orderBy() const;
604
610 void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
611
617 bool orderByEnabled() const;
618
625 void setOrderByEnabled( bool enabled );
626
633 virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
634
640 virtual const QgsFeatureRenderer *embeddedRenderer() const;
641
651 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
652
668 void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
669
676 double maximumExtentBuffer( QgsRenderContext &context ) const;
677
678 protected:
679 QgsFeatureRenderer( const QString &type );
680
687 void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
688
690 void renderVertexMarker( QPointF pt, QgsRenderContext &context );
692 void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
694 void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
695
700 static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
701
710 void saveRendererData( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context );
711
712 QString mType;
713
714 bool mUsingSymbolLevels = false;
715
718
721
722 std::unique_ptr<QgsPaintEffect> mPaintEffect;
723
724 bool mForceRaster = false;
725
726 double mReferenceScale = -1.0;
727
731 static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
732
736 static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
737
739
740 bool mOrderByEnabled = false;
741
742 private:
743#ifdef SIP_RUN
745 QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
746#endif
747
748 static void initPropertyDefinitions();
750 static QgsPropertiesDefinition sPropertyDefinitions;
751
752#ifdef QGISDEBUG
754 QThread *mThread = nullptr;
755#endif
756
757 QgsPropertyCollection mDataDefinedProperties;
758
759 Q_DISABLE_COPY( QgsFeatureRenderer )
760};
761
763
764// for some reason SIP compilation fails if these lines are not included:
767
768#endif // QGSRENDERER_H
ScaleMethod
Scale methods.
Definition qgis.h:643
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
Definition qgis.h:857
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:365
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition qgis.h:1891
@ Cross
Cross marker.
Definition qgis.h:1893
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:60
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:53
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:70
QgsSymbol * mSymbol
Definition qgsrenderer.h:87
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:7413
#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:96
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition qgsrenderer.h:92
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:52
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:51