QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
53 QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true, const QString &uuid = QString() );
54
64 QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true, const QString &uuid = QString() );
65 QgsRendererRange( const QgsRendererRange &range );
66
67 // default dtor is OK
68 QgsRendererRange &operator=( QgsRendererRange range );
69
70 bool operator<( const QgsRendererRange &other ) const;
71
76 QString uuid() const;
77
84 double lowerValue() const;
85
92 double upperValue() const;
93
99 QgsSymbol *symbol() const;
100
106 QString label() const;
107
115 void setSymbol( QgsSymbol *s SIP_TRANSFER );
116
122 void setLabel( const QString &label );
123
130 void setLowerValue( double lowerValue );
131
138 void setUpperValue( double upperValue );
139
145 bool renderState() const;
146
152 void setRenderState( bool render );
153
157 QString dump() const;
158
167 void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const;
168
169#ifdef SIP_RUN
170 SIP_PYOBJECT __repr__();
171 % MethodCode
172 const QString str = sipCpp->label().isEmpty()
173 ? QStringLiteral( "<QgsRendererRange: %1 - %2>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
174 : QStringLiteral( "<QgsRendererRange: %1 - %2 (%3)>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
175 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
176 % End
177
178 SIP_PYOBJECT __getitem__( int );
179 % MethodCode
180 if ( a0 == 0 )
181 {
182 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
183 }
184 else if ( a0 == 1 )
185 {
186 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
187 }
188 else
189 {
190 QString msg = QString( "Bad index: %1" ).arg( a0 );
191 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
192 }
193 % End
194#endif
195
196 protected:
197 double mLowerValue = 0, mUpperValue = 0;
198 std::unique_ptr<QgsSymbol> mSymbol;
199 QString mLabel;
200 bool mRender = true;
201 QString mUuid;
202
203 // for cpy+swap idiom
204 void swap( QgsRendererRange &other );
205};
206
207typedef QList<QgsRendererRange> QgsRangeList;
208
209
215class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
216{
217 public:
219 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
220
221 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
222 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
223
224 QString format() const { return mFormat; }
225 void setFormat( const QString &format ) { mFormat = format; }
226
227 int precision() const { return mPrecision; }
228 void setPrecision( int precision );
229
230 bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
231 void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
232
234 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
235 QString labelForRange( const QgsRendererRange &range ) const;
236 QString formatNumber( double value ) const;
237
238 void setFromDomElement( QDomElement &element );
239 void saveToDomElement( QDomElement &element );
240
241 static const int MAX_PRECISION;
242 static const int MIN_PRECISION;
243
244 protected:
245 QString mFormat;
246 int mPrecision = 4;
247 bool mTrimTrailingZeroes = false;
248 // values used to manage number formatting - precision and trailing zeroes
249 double mNumberScale = 1.0;
251 QRegularExpression mReTrailingZeroes;
252 QRegularExpression mReNegativeZero;
253};
254
255
256#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:94
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cpp:337
#define str(x)
Definition: qgis.cpp:38
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:5600
#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