QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsrendererrange.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrendererrange.h
3 ---------------------
4 begin : September 2019
5 copyright : (C) 2019 by Denis Rouzaud
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 QGSRENDERERRANGE_H
17#define QGSRENDERERRANGE_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgssymbollayerutils.h"
22
23#include <QRegularExpression>
24
25class QDomDocument;
26class QDomElement;
27
28class QgsSymbol;
30
31
37class CORE_EXPORT QgsRendererRange
38{
39 public:
40
41 QgsRendererRange() = default;
43
51 QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true, const QString &uuid = QString() );
52
62 QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true, const QString &uuid = QString() );
63 QgsRendererRange( const QgsRendererRange &range );
64
65 // default dtor is OK
67
68 bool operator<( const QgsRendererRange &other ) const;
69
74 QString uuid() const;
75
82 double lowerValue() const;
83
90 double upperValue() const;
91
97 QgsSymbol *symbol() const;
98
104 QString label() const;
105
114
120 void setLabel( const QString &label );
121
128 void setLowerValue( double lowerValue );
129
136 void setUpperValue( double upperValue );
137
143 bool renderState() const;
144
150 void setRenderState( bool render );
151
155 QString dump() const;
156
166 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const SIP_DEPRECATED;
167
178 bool toSld( QDomDocument &doc, QDomElement &element, const QString &classAttribute, QgsSldExportContext &context, bool firstRange = false ) const;
179
180#ifdef SIP_RUN
181 SIP_PYOBJECT __repr__();
182 % MethodCode
183 const QString str = sipCpp->label().isEmpty()
184 ? QStringLiteral( "<QgsRendererRange: %1 - %2>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
185 : QStringLiteral( "<QgsRendererRange: %1 - %2 (%3)>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
186 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
187 % End
188
189 SIP_PYOBJECT __getitem__( int );
190 % MethodCode
191 if ( a0 == 0 )
192 {
193 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
194 }
195 else if ( a0 == 1 )
196 {
197 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
198 }
199 else
200 {
201 QString msg = QString( "Bad index: %1" ).arg( a0 );
202 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
203 }
204 % End
205#endif
206
207 protected:
209
210 double mLowerValue = 0, mUpperValue = 0;
211 std::unique_ptr<QgsSymbol> mSymbol;
212 QString mLabel;
213 bool mRender = true;
214 QString mUuid;
215};
216
217typedef QList<QgsRendererRange> QgsRangeList;
218
219
227class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
228{
229 public:
231 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
232
233 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
234 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
235
236 QString format() const { return mFormat; }
237 void setFormat( const QString &format ) { mFormat = format; }
238
239 int precision() const { return mPrecision; }
240 void setPrecision( int precision );
241
244
248 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
249 QString labelForRange( const QgsRendererRange &range ) const;
250 QString formatNumber( double value ) const;
251
252 void setFromDomElement( QDomElement &element );
253 void saveToDomElement( QDomElement &element );
254
255 static const int MAX_PRECISION;
256 static const int MIN_PRECISION;
257
258 protected:
259 QString mFormat;
260 int mPrecision = 4;
262 // values used to manage number formatting - precision and trailing zeroes
263 double mNumberScale = 1.0;
265 QRegularExpression mReTrailingZeroes;
266 QRegularExpression mReNegativeZero;
267};
268
269
270#endif // QGSRENDERERRANGE_H
Contains the information about a classification range.
void setFormat(const QString &format)
QRegularExpression mReTrailingZeroes
QRegularExpression mReNegativeZero
void setTrimTrailingZeroes(bool trimTrailingZeroes)
Represents a value range for a QgsGraduatedSymbolRenderer.
void setUpperValue(double upperValue)
Sets the upper bound of the range.
QgsRendererRange()=default
QString label() const
Returns the label used for the range.
void setSymbol(QgsSymbol *s)
Sets the symbol used for the range.
std::unique_ptr< QgsSymbol > mSymbol
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange=false) const
Creates a DOM element representing the range in SLD format.
QgsRendererRange & operator=(QgsRendererRange range)
QgsSymbol * symbol() const
Returns the symbol used for the range.
void setLabel(const QString &label)
Sets the label used for the range.
bool renderState() const
Returns true if the range should be rendered.
friend class QgsGraduatedSymbolRendererWidget
void setRenderState(bool render)
Sets whether the range should be rendered.
QString dump() const
Dumps a string representation of the range.
double upperValue() const
Returns the upper bound of the range.
void setLowerValue(double lowerValue)
Sets the lower bound of the range.
QString uuid() const
Returns the unique identifier for this range.
double lowerValue() const
Returns the lower bound of the range.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
bool operator<(const QVariant &v1, const QVariant &v2)
Compares two QVariant values and returns whether the first is less than the second.
Definition qgis.h:7039
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_PYNAME(name)
Definition qgis_sip.h:89
#define SIP_TRANSFER
Definition qgis_sip.h:36
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QList< QgsRendererRange > QgsRangeList