QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
36class CORE_EXPORT QgsRendererRange
37{
38 public:
39
40 QgsRendererRange() = default;
42
50 QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true, const QString &uuid = QString() );
51
61 QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true, const QString &uuid = QString() );
62 QgsRendererRange( const QgsRendererRange &range );
63
64 // default dtor is OK
65 QgsRendererRange &operator=( QgsRendererRange range );
66
67 bool operator<( const QgsRendererRange &other ) const;
68
73 QString uuid() const;
74
81 double lowerValue() const;
82
89 double upperValue() const;
90
96 QgsSymbol *symbol() const;
97
103 QString label() const;
104
112 void setSymbol( QgsSymbol *s SIP_TRANSFER );
113
119 void setLabel( const QString &label );
120
127 void setLowerValue( double lowerValue );
128
135 void setUpperValue( double upperValue );
136
142 bool renderState() const;
143
149 void setRenderState( bool render );
150
154 QString dump() const;
155
164 void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const;
165
166#ifdef SIP_RUN
167 SIP_PYOBJECT __repr__();
168 % MethodCode
169 const QString str = sipCpp->label().isEmpty()
170 ? QStringLiteral( "<QgsRendererRange: %1 - %2>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
171 : QStringLiteral( "<QgsRendererRange: %1 - %2 (%3)>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
172 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
173 % End
174
175 SIP_PYOBJECT __getitem__( int );
176 % MethodCode
177 if ( a0 == 0 )
178 {
179 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
180 }
181 else if ( a0 == 1 )
182 {
183 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
184 }
185 else
186 {
187 QString msg = QString( "Bad index: %1" ).arg( a0 );
188 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
189 }
190 % End
191#endif
192
193 protected:
194 double mLowerValue = 0, mUpperValue = 0;
195 std::unique_ptr<QgsSymbol> mSymbol;
196 QString mLabel;
197 bool mRender = true;
198 QString mUuid;
199};
200
201typedef QList<QgsRendererRange> QgsRangeList;
202
203
209class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
210{
211 public:
213 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
214
215 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
216 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
217
218 QString format() const { return mFormat; }
219 void setFormat( const QString &format ) { mFormat = format; }
220
221 int precision() const { return mPrecision; }
222 void setPrecision( int precision );
223
224 bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
225 void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
226
228 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
229 QString labelForRange( const QgsRendererRange &range ) const;
230 QString formatNumber( double value ) const;
231
232 void setFromDomElement( QDomElement &element );
233 void saveToDomElement( QDomElement &element );
234
235 static const int MAX_PRECISION;
236 static const int MIN_PRECISION;
237
238 protected:
239 QString mFormat;
240 int mPrecision = 4;
241 bool mTrimTrailingZeroes = false;
242 // values used to manage number formatting - precision and trailing zeroes
243 double mNumberScale = 1.0;
245 QRegularExpression mReTrailingZeroes;
246 QRegularExpression mReNegativeZero;
247};
248
249
250#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
std::unique_ptr< QgsSymbol > mSymbol
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
#define str(x)
Definition qgis.cpp:39
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:6318
#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