QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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.h"
19#include "qgis_core.h"
20#include "qgis_sip.h"
22#include "qgsrenderer.h"
23#include "qgsrendererrange.h"
24
25class QgsVectorLayer;
26class QgsColorRamp;
28class QgsSymbol;
29class QgsExpression;
30
37{
38 public:
39 QgsGraduatedSymbolRenderer( const QString &attrName = QString(), const QgsRangeList &ranges = QgsRangeList() );
40
42
43 Qgis::FeatureRendererFlags flags() const override;
44 QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
45 QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
46 void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
47 void stopRender( QgsRenderContext &context ) override;
48 QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
49 bool filterNeedsGeometry() const override;
50 QString dump() const override;
52 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override SIP_DEPRECATED;
53 bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const override;
55 QgsSymbolList symbols( QgsRenderContext &context ) const override;
56 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
57
63 QString classAttribute() const { return mAttrName; }
64
70 void setClassAttribute( const QString &attr ) { mAttrName = attr; }
71
75 const QgsRangeList &ranges() const { return mRanges; }
76
77 bool updateRangeSymbol( int rangeIndex, QgsSymbol *symbol SIP_TRANSFER );
78 bool updateRangeLabel( int rangeIndex, const QString &label );
79 bool updateRangeUpperValue( int rangeIndex, double value );
80 bool updateRangeLowerValue( int rangeIndex, double value );
81 bool updateRangeRenderState( int rangeIndex, bool render );
82
86 void addClass( QgsSymbol *symbol );
87
91 void addClass( const QgsRendererRange &range ) SIP_PYNAME( addClassRange );
92
96 void addClass( double lower, double upper ) SIP_PYNAME( addClassLowerUpper );
97
105 void addBreak( double breakValue, bool updateSymbols = true );
106
107 void deleteClass( int idx );
108 void deleteAllClasses();
109
111 void moveClass( int from, int to );
112
117 bool rangesOverlap() const;
118
123 bool rangesHaveGaps() const;
124
125 void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
126 void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
127
132 QgsClassificationMethod *classificationMethod() const;
133
139 void setClassificationMethod( QgsClassificationMethod *method SIP_TRANSFER );
140
154 // TODO QGIS 5: remove
155 // this could not be tagged with Q_DECL_DEPRECATED due to Doxygen warning
156 // might be fixed in newer Doxygen (does not on 1.8.13, might be ok on 1.8.16)
157
158
160 Q_DECL_DEPRECATED Mode mode() const SIP_DEPRECATED { return modeFromMethodId( mClassificationMethod->id() ); }
162 Q_DECL_DEPRECATED void setMode( Mode mode ) SIP_DEPRECATED;
163
169 Q_DECL_DEPRECATED bool useSymmetricMode() const SIP_DEPRECATED { return mClassificationMethod->symmetricModeEnabled(); }
170
176 Q_DECL_DEPRECATED void setUseSymmetricMode( bool useSymmetricMode ) SIP_DEPRECATED;
177
183 Q_DECL_DEPRECATED double symmetryPoint() const SIP_DEPRECATED { return mClassificationMethod->symmetryPoint(); }
184
190 Q_DECL_DEPRECATED void setSymmetryPoint( double symmetryPoint ) SIP_DEPRECATED;
191
192
198 Q_DECL_DEPRECATED bool astride() const SIP_DEPRECATED { return mClassificationMethod->symmetryAstride(); }
199
205 Q_DECL_DEPRECATED void setAstride( bool astride ) SIP_DEPRECATED;
206
216 Q_DECL_DEPRECATED static void makeBreaksSymmetric( QList<double> &breaks SIP_INOUT, double symmetryPoint, bool astride ) SIP_DEPRECATED;
217
228 Q_DECL_DEPRECATED static QList<double> calcEqualIntervalBreaks( double minimum, double maximum, int classes, bool useSymmetricMode, double symmetryPoint, bool astride ) SIP_DEPRECATED;
229
240 Q_DECL_DEPRECATED void updateClasses( QgsVectorLayer *vlayer, Mode mode, int nclasses, bool useSymmetricMode = false, double symmetryPoint = 0.0, bool astride = false ) SIP_DEPRECATED;
241
248 void updateClasses( const QgsVectorLayer *vl, int nclasses, QString &error SIP_OUT );
249
251
257
264 Q_DECL_DEPRECATED void setLabelFormat( const QgsRendererRangeLabelFormat &labelFormat, bool updateRanges = false ) SIP_DEPRECATED;
265
267
272 void calculateLabelPrecision( bool updateRanges = true );
273
275
292 Q_DECL_DEPRECATED static QgsGraduatedSymbolRenderer *createRenderer(
293 QgsVectorLayer *vlayer,
294 const QString &attrName,
295 int classes,
296 Mode mode,
297 QgsSymbol *symbol SIP_TRANSFER,
300 bool useSymmetricMode = false,
301 double symmetryPoint = 0.0,
302 const QStringList &listForCboPrettyBreaks = QStringList(),
303 bool astride = false
306
308 static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
309
310 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
311 QgsLegendSymbolList legendSymbolItems() const override;
312 QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
313 QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok ) const override;
314
322
330 const QgsSymbol *sourceSymbol() const SIP_SKIP;
331
340
347
355
361
367 void updateColorRamp( QgsColorRamp *ramp SIP_TRANSFER = nullptr );
368
375 void updateSymbols( QgsSymbol *sym );
376
381 void setSymbolSizes( double minSize, double maxSize );
382
386 double minSymbolSize() const;
387
391 double maxSymbolSize() const;
392
398 Qgis::GraduatedMethod graduatedMethod() const { return mGraduatedMethod; }
399
406
407 bool legendSymbolItemsCheckable() const override;
408 bool legendSymbolItemChecked( const QString &key ) override;
409 void checkLegendSymbolItem( const QString &key, bool state = true ) override;
410 void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER ) override;
411 QString legendClassificationAttribute() const override { return classAttribute(); }
412
417 static QgsGraduatedSymbolRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
418
428 void setDataDefinedSizeLegend( QgsDataDefinedSizeLegend *settings SIP_TRANSFER );
429
434 QgsDataDefinedSizeLegend *dataDefinedSizeLegend() const;
435
440 void updateRangeLabels();
441
448 const QgsRendererRange *rangeForValue( double value ) const;
449
450 protected:
451 QString mAttrName;
453 std::unique_ptr<QgsSymbol> mSourceSymbol;
454 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
455
456 std::unique_ptr<QgsExpression> mExpression;
459
460 int mAttrNum = -1;
461 bool mCounting = false;
462
463 std::unique_ptr<QgsDataDefinedSizeLegend> mDataDefinedSizeLegend;
464
468 QgsSymbol *symbolForValue( double value ) const;
469
473 QString legendKeyForValue( double value ) const;
474
476 static QString graduatedMethodStr( Qgis::GraduatedMethod method ) SIP_SKIP;
477
478 std::shared_ptr<QgsClassificationMethod> mClassificationMethod;
479
480 private:
484 QVariant valueForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
485
487 QgsLegendSymbolList baseLegendSymbolItems() const;
488
489 // TODO QGIS 5: remove
491 static QString methodIdFromMode( QgsGraduatedSymbolRenderer::Mode mode );
492 static QgsGraduatedSymbolRenderer::Mode modeFromMethodId( const QString &methodId );
494
495#ifdef SIP_RUN
498#endif
499
501};
502
503#endif // QGSGRADUATEDSYMBOLRENDERER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
Definition qgis.h:864
GraduatedMethod
Methods for modifying symbols by range in a graduated symbol renderer.
Definition qgis.h:3420
@ Color
Alter color of symbols.
Definition qgis.h:3421
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.
Handles parsing and evaluation of expressions (formerly called "search strings").
Abstract base class for all 2D vector feature renderers.
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.
QgsFeatureRenderer(const QString &type)
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual Qgis::FeatureRendererFlags flags() const
Returns flags associated with 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 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.
@ 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 ....
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
virtual Q_DECL_DEPRECATED 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 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:60
Container of fields for a vector layer.
Definition qgsfields.h:46
A vector feature renderer which uses numeric attributes to classify features into different ranges.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol befo...
QString legendClassificationAttribute() const override
If supported by the renderer, return classification attribute for the use in legend.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
void updateSymbols(QgsSymbol *sym)
Update all the symbols but leave breaks and colors.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each classes' color is derived.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
double maxSymbolSize() const
Returns the max symbol size when graduated by size.
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).
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
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.
Q_DECL_DEPRECATED void setLabelFormat(const QgsRendererRangeLabelFormat &labelFormat, bool updateRanges=false)
Set the label format used to generate default classification labels.
QString classAttribute() const
Returns the attribute name (or expression) used for the classification.
QString legendKeyToExpression(const QString &key, QgsVectorLayer *layer, bool &ok) const override
Attempts to convert the specified legend rule key to a QGIS expression matching the features displaye...
QString legendKeyForValue(double value) const
Returns the matching legend key for a value.
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol b...
std::unique_ptr< QgsColorRamp > mSourceColorRamp
void updateColorRamp(QgsColorRamp *ramp=nullptr)
Update the color ramp used.
Q_DECL_DEPRECATED Mode mode() const
QgsGraduatedSymbolRenderer(const QString &attrName=QString(), const QgsRangeList &ranges=QgsRangeList())
double minSymbolSize() const
Returns the min symbol size when graduated by size.
Qgis::GraduatedMethod graduatedMethod() const
Returns the method used for graduation (either size or color).
int mAttrNum
attribute index (derived from attribute name in startRender)
void setClassAttribute(const QString &attr)
Sets the attribute name (or expression) used for the classification.
std::unique_ptr< QgsExpression > mExpression
static QString graduatedMethodStr(Qgis::GraduatedMethod method)
void setSymbolSizes(double minSize, double maxSize)
set varying symbol size for classes
void calculateLabelPrecision(bool updateRanges=true)
Reset the label decimal places to a numberbased on the minimum class interval.
const QgsRangeList & ranges() const
Returns a list of all ranges used in the classification.
Q_DECL_DEPRECATED QgsRendererRangeLabelFormat labelFormat() const
Returns the label format used to generate default classification labels.
static Q_DECL_DEPRECATED QgsGraduatedSymbolRenderer * createRenderer(QgsVectorLayer *vlayer, const QString &attrName, int classes, Mode mode, QgsSymbol *symbol, QgsColorRamp *ramp, const QgsRendererRangeLabelFormat &legendFormat=QgsRendererRangeLabelFormat(), bool useSymmetricMode=false, double symmetryPoint=0.0, const QStringList &listForCboPrettyBreaks=QStringList(), bool astride=false)
Creates a new graduated renderer.
Q_DECL_DEPRECATED double symmetryPoint() const
Returns the pivot value for symmetric classification.
QgsSymbol * symbolForValue(double value) const
Gets the symbol which is used to represent value.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
Encapsulates the formatting for a QgsRendererRange label.
Represents a value range for a QgsGraduatedSymbolRenderer.
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.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
#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_INOUT
Definition qgis_sip.h:78
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:51
QList< QgsRendererRange > QgsRangeList