QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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"
26
27#include <QList>
28#include <QString>
29#include <QVariant>
30#include <QPair>
31#include <QPixmap>
32#include <QDomDocument>
33#include <QDomElement>
34
35class QgsFeature;
36class QgsVectorLayer;
37class QgsPaintEffect;
41
42typedef QMap<QString, QString> QgsStringMap SIP_SKIP;
43
44typedef QList<QgsSymbol *> QgsSymbolList;
45typedef QMap<QString, QgsSymbol * > QgsSymbolMap SIP_SKIP;
46
47#include "qgslegendsymbolitem.h"
48
49
50#define RENDERER_TAG_NAME "renderer-v2"
51
53// symbol levels
54
59class CORE_EXPORT QgsSymbolLevelItem
60{
61 public:
62 QgsSymbolLevelItem( QgsSymbol *symbol, int layer )
63 : mSymbol( symbol )
64 , mLayer( layer )
65 {}
66
70 QgsSymbol *symbol() const;
71
75 int layer() const;
76
77 // TODO QGIS 4.0 -> make private
78 protected:
79 QgsSymbol *mSymbol = nullptr;
80 int mLayer;
81};
82
83// every level has list of items: symbol + symbol layer num
84typedef QList< QgsSymbolLevelItem > QgsSymbolLevel;
85
86// this is a list of levels
87#ifndef SIP_RUN
88typedef QList< QgsSymbolLevel > QgsSymbolLevelOrder;
89#else
90typedef QList< QList< QgsSymbolLevelItem > > QgsSymbolLevelOrder;
91#endif
92
93
95// renderers
96
101class CORE_EXPORT QgsFeatureRenderer
102{
103
104#ifdef SIP_RUN
106
107 const QString type = sipCpp->type();
108
109 if ( type == QLatin1String( "singleSymbol" ) )
110 sipType = sipType_QgsSingleSymbolRenderer;
111 else if ( type == QLatin1String( "categorizedSymbol" ) )
112 sipType = sipType_QgsCategorizedSymbolRenderer;
113 else if ( type == QLatin1String( "graduatedSymbol" ) )
114 sipType = sipType_QgsGraduatedSymbolRenderer;
115 else if ( type == QLatin1String( "RuleRenderer" ) )
116 sipType = sipType_QgsRuleBasedRenderer;
117 else if ( type == QLatin1String( "heatmapRenderer" ) )
118 sipType = sipType_QgsHeatmapRenderer;
119 else if ( type == QLatin1String( "invertedPolygonRenderer" ) )
120 sipType = sipType_QgsInvertedPolygonRenderer;
121 else if ( type == QLatin1String( "pointCluster" ) )
122 sipType = sipType_QgsPointClusterRenderer;
123 else if ( type == QLatin1String( "pointDisplacement" ) )
124 sipType = sipType_QgsPointDisplacementRenderer;
125 else if ( type == QLatin1String( "25dRenderer" ) )
126 sipType = sipType_Qgs25DRenderer;
127 else if ( type == QLatin1String( "nullSymbol" ) )
128 sipType = sipType_QgsNullSymbolRenderer;
129 else if ( type == QLatin1String( "embeddedSymbol" ) )
130 sipType = sipType_QgsEmbeddedSymbolRenderer;
131 else
132 sipType = 0;
133 SIP_END
134#endif
135
136 public:
137 // renderer takes ownership of its symbols!
138
140 static QgsFeatureRenderer *defaultRenderer( Qgis::GeometryType geomType ) SIP_FACTORY;
141
142 QString type() const { return mType; }
143
152 virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
153
159 virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
160
164 virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
165
178 virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
179
190 virtual void stopRender( QgsRenderContext &context );
191
200 virtual bool canSkipRender();
201
213 virtual QString filter( const QgsFields &fields = QgsFields() ) { Q_UNUSED( fields ) return QString(); }
214
221 virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const = 0;
222
229 virtual bool usesEmbeddedSymbols() const;
230
234 virtual bool filterNeedsGeometry() const;
235
236 virtual ~QgsFeatureRenderer();
237
245
259 virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) SIP_THROW( QgsCsException );
260
262 virtual QString dump() const;
263
269 {
270 SymbolLevels = 1,
271 MoreSymbolsPerFeature = 1 << 2,
272 Filter = 1 << 3,
273 ScaleDependent = 1 << 4
274 };
275
276 Q_DECLARE_FLAGS( Capabilities, Capability )
277
278
290 virtual QgsFeatureRenderer::Capabilities capabilities() { return QgsFeatureRenderer::Capabilities(); }
291
296 virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
297
298 bool usingSymbolLevels() const { return mUsingSymbolLevels; }
299 void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
300
302 static QgsFeatureRenderer *load( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
303
310 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
311
315 virtual QDomElement writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props = QVariantMap() ) const;
316
328 static QgsFeatureRenderer *loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage ) SIP_FACTORY;
329
331 virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const
332 {
333 element.appendChild( doc.createComment( QStringLiteral( "FeatureRenderer %1 not implemented yet" ).arg( type() ) ) );
334 ( void ) props; // warning avoidance
335 }
336
344 QSet< QString > legendKeys() const;
345
350 virtual bool legendSymbolItemsCheckable() const;
351
359 virtual bool legendSymbolItemChecked( const QString &key );
360
368 virtual void checkLegendSymbolItem( const QString &key, bool state = true );
369
378 virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER );
379
394 virtual QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok SIP_OUT ) const;
395
402 virtual QgsLegendSymbolList legendSymbolItems() const;
403
407 virtual QString legendClassificationAttribute() const { return QString(); }
408
410 void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
411
417 virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
418
424 virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
425
430 virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
431
438 virtual void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context );
439
445 QgsPaintEffect *paintEffect() const;
446
452 void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
453
458 bool forceRasterRender() const { return mForceRaster; }
459
467 void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
468
483 double referenceScale() const { return mReferenceScale; }
484
499 void setReferenceScale( double scale ) { mReferenceScale = scale; }
500
506 QgsFeatureRequest::OrderBy orderBy() const;
507
513 void setOrderBy( const QgsFeatureRequest::OrderBy &orderBy );
514
520 bool orderByEnabled() const;
521
528 void setOrderByEnabled( bool enabled );
529
536 virtual void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER );
537
543 virtual const QgsFeatureRenderer *embeddedRenderer() const;
544
554 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
555
570 void copyRendererData( QgsFeatureRenderer *destRenderer ) const;
571
572 protected:
573 QgsFeatureRenderer( const QString &type );
574
581 void renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker ) SIP_THROW( QgsCsException );
582
584 void renderVertexMarker( QPointF pt, QgsRenderContext &context );
586 void renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context );
588 void renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context );
589
594 static QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point );
595
604 void saveRendererData( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context );
605
606 QString mType;
607
608 bool mUsingSymbolLevels = false;
609
612
614 double mCurrentVertexMarkerSize = 2;
615
616 QgsPaintEffect *mPaintEffect = nullptr;
617
618 bool mForceRaster = false;
619
620 double mReferenceScale = -1.0;
621
626 static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
627
632 static void convertSymbolRotation( QgsSymbol *symbol, const QString &field );
633
635
636 bool mOrderByEnabled = false;
637
638 private:
639#ifdef SIP_RUN
641 QgsFeatureRenderer &operator=( const QgsFeatureRenderer & );
642#endif
643
644#ifdef QGISDEBUG
646 QThread *mThread = nullptr;
647#endif
648
649 Q_DISABLE_COPY( QgsFeatureRenderer )
650};
651
652Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRenderer::Capabilities )
653
654// for some reason SIP compilation fails if these lines are not included:
657
658#endif // QGSRENDERER_H
ScaleMethod
Scale methods.
Definition qgis.h:415
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:255
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition qgis.h:1401
@ Cross
Cross marker.
Custom exception class for Coordinate Reference System related exceptions.
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.
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.
QgsFeatureRequest::OrderBy mOrderBy
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:56
Container of fields for a vector layer.
Definition qgsfields.h:45
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
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:62
Abstract base class for all rendered symbols.
Definition qgssymbol.h:94
Represents a vector layer which manages a vector based data sets.
QMap< QString, QString > QgsStringMap
Definition qgis.h:5674
#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
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition qgsrenderer.h:88
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition qgsrenderer.h:84
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:45
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:44
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)