QGIS API Documentation 3.39.0-Master (47f7b3a4989)
Loading...
Searching...
No Matches
qgsgraduatedsymbolrenderer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgraduatedsymbolrenderer.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#ifndef QGSGRADUATEDSYMBOLRENDERER_H
16#define QGSGRADUATEDSYMBOLRENDERER_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgis.h"
21#include "qgsrenderer.h"
22#include "qgsrendererrange.h"
24
25class QgsVectorLayer;
26class QgsColorRamp;
28class QgsSymbol;
29class QgsExpression;
30
36{
37 public:
38
39 QgsGraduatedSymbolRenderer( const QString &attrName = QString(), const QgsRangeList &ranges = QgsRangeList() );
40
42
43 QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
44 QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
45 void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
46 void stopRender( QgsRenderContext &context ) override;
47 QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
48 bool filterNeedsGeometry() const override;
49 QString dump() const override;
51 void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override;
52 QgsFeatureRenderer::Capabilities capabilities() override { return SymbolLevels | Filter; }
53 QgsSymbolList symbols( QgsRenderContext &context ) const override;
54 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
55
61 QString classAttribute() const { return mAttrName; }
62
68 void setClassAttribute( const QString &attr ) { mAttrName = attr; }
69
73 const QgsRangeList &ranges() const { return mRanges; }
74
75 bool updateRangeSymbol( int rangeIndex, QgsSymbol *symbol SIP_TRANSFER );
76 bool updateRangeLabel( int rangeIndex, const QString &label );
77 bool updateRangeUpperValue( int rangeIndex, double value );
78 bool updateRangeLowerValue( int rangeIndex, double value );
79 bool updateRangeRenderState( int rangeIndex, bool render );
80
81 void addClass( QgsSymbol *symbol );
83 void addClass( const QgsRendererRange &range ) SIP_PYNAME( addClassRange );
85 void addClass( double lower, double upper ) SIP_PYNAME( addClassLowerUpper );
86
94 void addBreak( double breakValue, bool updateSymbols = true );
95
96 void deleteClass( int idx );
97 void deleteAllClasses();
98
100 void moveClass( int from, int to );
101
106 bool rangesOverlap() const;
107
112 bool rangesHaveGaps() const;
113
114 void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
115 void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
116
121 QgsClassificationMethod *classificationMethod() const;
122
128 void setClassificationMethod( QgsClassificationMethod *method SIP_TRANSFER );
129
143 // TODO QGIS 4: remove
144 // this could not be tagged with Q_DECL_DEPRECATED due to Doxygen warning
145 // might be fixed in newer Doxygen (does not on 1.8.13, might be ok on 1.8.16)
146
147
149 Q_DECL_DEPRECATED Mode mode() const SIP_DEPRECATED { return modeFromMethodId( mClassificationMethod->id() ); }
151 Q_DECL_DEPRECATED void setMode( Mode mode ) SIP_DEPRECATED;
152
158 Q_DECL_DEPRECATED bool useSymmetricMode() const SIP_DEPRECATED { return mClassificationMethod->symmetricModeEnabled(); }
159
165 Q_DECL_DEPRECATED void setUseSymmetricMode( bool useSymmetricMode ) SIP_DEPRECATED;
166
172 Q_DECL_DEPRECATED double symmetryPoint() const SIP_DEPRECATED { return mClassificationMethod->symmetryPoint(); }
173
179 Q_DECL_DEPRECATED void setSymmetryPoint( double symmetryPoint ) SIP_DEPRECATED;
180
181
187 Q_DECL_DEPRECATED bool astride() const SIP_DEPRECATED { return mClassificationMethod->symmetryAstride(); }
188
194 Q_DECL_DEPRECATED void setAstride( bool astride ) SIP_DEPRECATED;
195
205 Q_DECL_DEPRECATED static void makeBreaksSymmetric( QList<double> &breaks SIP_INOUT, double symmetryPoint, bool astride ) SIP_DEPRECATED;
206
217 Q_DECL_DEPRECATED static QList<double> calcEqualIntervalBreaks( double minimum, double maximum, int classes, bool useSymmetricMode, double symmetryPoint, bool astride ) SIP_DEPRECATED;
218
229 Q_DECL_DEPRECATED void updateClasses( QgsVectorLayer *vlayer, Mode mode, int nclasses, bool useSymmetricMode = false, double symmetryPoint = 0.0, bool astride = false ) SIP_DEPRECATED;
230
237 void updateClasses( const QgsVectorLayer *vl, int nclasses, QString &error SIP_OUT );
238
240
245 Q_DECL_DEPRECATED QgsRendererRangeLabelFormat labelFormat() const SIP_DEPRECATED;
246
253 Q_DECL_DEPRECATED void setLabelFormat( const QgsRendererRangeLabelFormat &labelFormat, bool updateRanges = false ) SIP_DEPRECATED;
254
256
261 void calculateLabelPrecision( bool updateRanges = true );
262
264
281 Q_DECL_DEPRECATED static QgsGraduatedSymbolRenderer *createRenderer( QgsVectorLayer *vlayer,
282 const QString &attrName,
283 int classes,
284 Mode mode,
285 QgsSymbol *symbol SIP_TRANSFER,
288 bool useSymmetricMode = false,
289 double symmetryPoint = 0.0,
290 const QStringList &listForCboPrettyBreaks = QStringList(),
291 bool astride = false ) SIP_DEPRECATED;
293
295 static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
296
297 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
298 QgsLegendSymbolList legendSymbolItems() const override;
299 QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
300 QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok ) const override;
301
308 QgsSymbol *sourceSymbol();
309
317 const QgsSymbol *sourceSymbol() const SIP_SKIP;
318
326 void setSourceSymbol( QgsSymbol *sym SIP_TRANSFER );
327
333 QgsColorRamp *sourceColorRamp();
334
341 const QgsColorRamp *sourceColorRamp() const SIP_SKIP;
342
347 void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
348
354 void updateColorRamp( QgsColorRamp *ramp SIP_TRANSFER = nullptr );
355
362 void updateSymbols( QgsSymbol *sym );
363
368 void setSymbolSizes( double minSize, double maxSize );
369
373 double minSymbolSize() const;
374
378 double maxSymbolSize() const;
379
385 Qgis::GraduatedMethod graduatedMethod() const { return mGraduatedMethod; }
386
392 void setGraduatedMethod( Qgis::GraduatedMethod method ) { mGraduatedMethod = method; }
393
394 bool legendSymbolItemsCheckable() const override;
395 bool legendSymbolItemChecked( const QString &key ) override;
396 void checkLegendSymbolItem( const QString &key, bool state = true ) override;
397 void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER ) override;
398 QString legendClassificationAttribute() const override { return classAttribute(); }
399
404 static QgsGraduatedSymbolRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
405
415 void setDataDefinedSizeLegend( QgsDataDefinedSizeLegend *settings SIP_TRANSFER );
416
421 QgsDataDefinedSizeLegend *dataDefinedSizeLegend() const;
422
427 void updateRangeLabels();
428
435 const QgsRendererRange *rangeForValue( double value ) const;
436
437 protected:
438 QString mAttrName;
440 std::unique_ptr<QgsSymbol> mSourceSymbol;
441 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
442
443 std::unique_ptr<QgsExpression> mExpression;
446
447 int mAttrNum = -1;
448 bool mCounting = false;
449
450 std::unique_ptr<QgsDataDefinedSizeLegend> mDataDefinedSizeLegend;
451
455 QgsSymbol *symbolForValue( double value ) const;
456
460 QString legendKeyForValue( double value ) const;
461
463 static QString graduatedMethodStr( Qgis::GraduatedMethod method ) SIP_SKIP;
464
465 std::shared_ptr<QgsClassificationMethod> mClassificationMethod;
466
467 private:
468
472 QVariant valueForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
473
475 QgsLegendSymbolList baseLegendSymbolItems() const;
476
477 // TODO QGIS 4: remove
479 static QString methodIdFromMode( QgsGraduatedSymbolRenderer::Mode mode );
480 static QgsGraduatedSymbolRenderer::Mode modeFromMethodId( const QString &methodId );
482
483#ifdef SIP_RUN
486#endif
487
488 friend class TestQgsGraduatedSymbolRenderer;
489
490};
491
492#endif // QGSGRADUATEDSYMBOLRENDERER_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
GraduatedMethod
Methods for modifying symbols by range in a graduated symbol renderer.
Definition qgis.h:2832
@ Color
Alter color of symbols.
QgsClassificationMethod is an abstract class for implementations of classification methods.
Abstract base class for color ramps.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Class for parsing and evaluation of expressions (formerly called "search strings").
virtual bool legendSymbolItemsCheckable() const
Returns true if symbology items in legend are checkable.
virtual bool legendSymbolItemChecked(const QString &key)
Returns true if the legend symbology item with the specified key is checked.
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
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 dump() const
Returns debug information about this renderer.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
Sets whether the legend symbology item with the specified ley should be checked.
@ Filter
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ....
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
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
QString legendClassificationAttribute() const override
If supported by the renderer, return classification attribute for the use in legend.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
Q_DECL_DEPRECATED bool useSymmetricMode() const
Returns if we want to classify symmetric around a given value.
std::unique_ptr< QgsSymbol > mSourceSymbol
void setGraduatedMethod(Qgis::GraduatedMethod method)
Set the method used for graduation (either size or color).
std::shared_ptr< QgsClassificationMethod > mClassificationMethod
Q_DECL_DEPRECATED bool astride() const
Returns if we want to have a central class astride the pivot value.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.
QString classAttribute() const
Returns the attribute name (or expression) used for the classification.
std::unique_ptr< QgsColorRamp > mSourceColorRamp
Q_DECL_DEPRECATED Mode mode() const
void setClassAttribute(const QString &attr)
Sets the attribute name (or expression) used for the classification.
std::unique_ptr< QgsExpression > mExpression
const QgsRangeList & ranges() const
Returns a list of all ranges used in the classification.
Q_DECL_DEPRECATED double symmetryPoint() const
Returns the pivot value for symmetric classification.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:94
Represents a vector layer which manages a vector based data sets.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6042
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6041
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#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_INOUT
Definition qgis_sip.h:71
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:47
QList< QgsRendererRange > QgsRangeList