QGIS API Documentation 4.1.0-Master (60fea48833c)
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#ifdef SIP_RUN
114
115 const QString type = sipCpp->type();
116
117 if ( type == "singleSymbol"_L1 )
118 sipType = sipType_QgsSingleSymbolRenderer;
119 else if ( type == "categorizedSymbol"_L1 )
120 sipType = sipType_QgsCategorizedSymbolRenderer;
121 else if ( type == "graduatedSymbol"_L1 )
122 sipType = sipType_QgsGraduatedSymbolRenderer;
123 else if ( type == "RuleRenderer"_L1 )
124 sipType = sipType_QgsRuleBasedRenderer;
125 else if ( type == "heatmapRenderer"_L1 )
126 sipType = sipType_QgsHeatmapRenderer;
127 else if ( type == "invertedPolygonRenderer"_L1 )
128 sipType = sipType_QgsInvertedPolygonRenderer;
129 else if ( type == "pointCluster"_L1 )
130 sipType = sipType_QgsPointClusterRenderer;
131 else if ( type == "pointDisplacement"_L1 )
132 sipType = sipType_QgsPointDisplacementRenderer;
133 else if ( type == "25dRenderer"_L1 )
134 sipType = sipType_Qgs25DRenderer;
135 else if ( type == "nullSymbol"_L1 )
136 sipType = sipType_QgsNullSymbolRenderer;
137 else if ( type == "embeddedSymbol"_L1 )
138 sipType = sipType_QgsEmbeddedSymbolRenderer;
139 else
140 sipType = 0;
141 SIP_END
142#endif
143
144 public:
145
151 enum class Property : int
152 {
153 HeatmapRadius,
154 HeatmapMaximum,
155 };
156
161 static const QgsPropertiesDefinition &propertyDefinitions();
162
163 // renderer takes ownership of its symbols!
164
166 static QgsFeatureRenderer *defaultRenderer( Qgis::GeometryType geomType ) SIP_FACTORY;
167
168 QString type() const { return mType; }
169
178 virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
179
185 virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
186
190 virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
191
204 virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
205
216 virtual void stopRender( QgsRenderContext &context );
217
226 virtual bool canSkipRender();
227
239 virtual QString filter( const QgsFields &fields = QgsFields() )
240 {
241 Q_UNUSED( fields )
242 return QString();
243 }
244
251 virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
252
259 virtual bool usesEmbeddedSymbols() const;
260
264 virtual bool filterNeedsGeometry() const;
265
266 virtual ~QgsFeatureRenderer();
267
275
289 virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
290
292 virtual QString dump() const;
293
299 {
302 Filter = 1 << 3,
304 };
305
306 Q_DECLARE_FLAGS( Capabilities, Capability )
307
308
321
327 virtual Qgis::FeatureRendererFlags flags() const;
328
333 virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
334
335 bool usingSymbolLevels() const { return mUsingSymbolLevels; }
337
339 static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
340
347 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
348
352 virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props = QVariantMap() ) const;
353
365 static QgsFeatureRenderer *loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
366
372 Q_DECL_DEPRECATED virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const SIP_DEPRECATED;
373
381 virtual bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const;
382
390 QSet< QString > legendKeys() const;
391
396 virtual bool legendSymbolItemsCheckable() const;
397
405 virtual bool legendSymbolItemChecked( const QString &key );
406
414 virtual void checkLegendSymbolItem( const QString &key, bool state = true );
415
424 virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
425
440 virtual QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok SIP_OUT ) const;
441
448 virtual QgsLegendSymbolList legendSymbolItems() const;
449
461 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const SIP_FACTORY;
462
466 virtual QString legendClassificationAttribute() const { return QString(); }
467
469 void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
470
476 virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
477
483 virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
484
489 virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
490
497 virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
498
504 QgsPaintEffect *paintEffect() const;
505
511 void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
512
517 bool forceRasterRender() const { return mForceRaster; }
518
526 void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
527
537 void setDataDefinedProperty( Property key, const QgsProperty &property );
538
547 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
548
556 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
557
567 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
568
583 double referenceScale() const { return mReferenceScale; }
584
599 void setReferenceScale( double scale ) { mReferenceScale = scale; }
600
606 QgsFeatureRequest::OrderBy orderBy() const;
607
613 void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
614
620 bool orderByEnabled() const;
621
628 void setOrderByEnabled( bool enabled );
629
636 virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
637
643 virtual const QgsFeatureRenderer *embeddedRenderer() const;
644
654 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
655
671 void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
672
679 double maximumExtentBuffer( QgsRenderContext &context ) const;
680
681 protected:
682 QgsFeatureRenderer( const QString &type );
683
690 void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
691
693 void renderVertexMarker( QPointF pt, QgsRenderContext &context );
695 void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
697 void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
698
703 static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
704
713 void saveRendererData( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context );
714
715 QString mType;
716
717 bool mUsingSymbolLevels = false;
718
721
724
725 std::unique_ptr<QgsPaintEffect> mPaintEffect;
726
727 bool mForceRaster = false;
728
729 double mReferenceScale = -1.0;
730
734 static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
735
739 static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
740
742
743 bool mOrderByEnabled = false;
744
745 private:
746#ifdef SIP_RUN
748 QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
749#endif
750
751 static void initPropertyDefinitions();
753 static QgsPropertiesDefinition sPropertyDefinitions;
754
755#ifdef QGISDEBUG
757 QThread *mThread = nullptr;
758#endif
759
760 QgsPropertyCollection mDataDefinedProperties;
761
762 Q_DISABLE_COPY( QgsFeatureRenderer )
763};
764
766
767// for some reason SIP compilation fails if these lines are not included:
770
771#endif // QGSRENDERER_H
ScaleMethod
Scale methods.
Definition qgis.h:650
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
Definition qgis.h:864
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition qgis.h:1912
@ Cross
Cross marker.
Definition qgis.h:1914
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:227
Represents a vector layer which manages a vector based dataset.
QMap< QString, QString > QgsStringMap
Definition qgis.h:7475
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
#define SIP_END
Definition qgis_sip.h:215
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