QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
36class CORE_EXPORT QgsRendererRange
37{
38 public:
39
43 QgsRendererRange() = default;
45
52 QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true );
53 QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true );
54 QgsRendererRange( const QgsRendererRange &range );
55
56 // default dtor is OK
57 QgsRendererRange &operator=( QgsRendererRange range );
58
59 bool operator<( const QgsRendererRange &other ) const;
60
67 double lowerValue() const;
68
75 double upperValue() const;
76
82 QgsSymbol *symbol() const;
83
89 QString label() const;
90
98 void setSymbol( QgsSymbol *s SIP_TRANSFER );
99
105 void setLabel( const QString &label );
106
113 void setLowerValue( double lowerValue );
114
121 void setUpperValue( double upperValue );
122
129 bool renderState() const;
130
137 void setRenderState( bool render );
138
142 QString dump() const;
143
152 void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const;
153
154#ifdef SIP_RUN
155 SIP_PYOBJECT __repr__();
156 % MethodCode
157 const QString str = sipCpp->label().isEmpty()
158 ? QStringLiteral( "<QgsRendererRange: %1 - %2>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
159 : QStringLiteral( "<QgsRendererRange: %1 - %2 (%3)>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
160 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
161 % End
162
163 SIP_PYOBJECT __getitem__( int );
164 % MethodCode
165 if ( a0 == 0 )
166 {
167 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
168 }
169 else if ( a0 == 1 )
170 {
171 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
172 }
173 else
174 {
175 QString msg = QString( "Bad index: %1" ).arg( a0 );
176 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
177 }
178 % End
179#endif
180
181 protected:
182 double mLowerValue = 0, mUpperValue = 0;
183 std::unique_ptr<QgsSymbol> mSymbol;
184 QString mLabel;
185 bool mRender = true;
186
187 // for cpy+swap idiom
188 void swap( QgsRendererRange &other );
189};
190
191typedef QList<QgsRendererRange> QgsRangeList;
192
193
200class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
201{
202 public:
204 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
205
206 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
207 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
208
209 QString format() const { return mFormat; }
210 void setFormat( const QString &format ) { mFormat = format; }
211
212 int precision() const { return mPrecision; }
213 void setPrecision( int precision );
214
215 bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
216 void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
217
219 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
220 QString labelForRange( const QgsRendererRange &range ) const;
221 QString formatNumber( double value ) const;
222
223 void setFromDomElement( QDomElement &element );
224 void saveToDomElement( QDomElement &element );
225
226 static const int MAX_PRECISION;
227 static const int MIN_PRECISION;
228
229 protected:
230 QString mFormat;
231 int mPrecision = 4;
232 bool mTrimTrailingZeroes = false;
233 // values used to manage number formatting - precision and trailing zeroes
234 double mNumberScale = 1.0;
236 QRegularExpression mReTrailingZeroes;
237 QRegularExpression mReNegativeZero;
238};
239
240
241#endif // QGSRENDERERRANGE_H
QgsClassificationRange contains the information about a classification range.
void setFormat(const QString &format)
QRegularExpression mReTrailingZeroes
QRegularExpression mReNegativeZero
void setTrimTrailingZeroes(bool trimTrailingZeroes)
QgsRendererRange()=default
Constructor for QgsRendererRange.
std::unique_ptr< QgsSymbol > mSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cpp:407
#define str(x)
Definition: qgis.cpp:37
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:2885
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#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
int precision