QGIS API Documentation 3.39.0-Master (bca3cdb6021)
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 // for cpy+swap idiom
201 void swap( QgsRendererRange &other );
202};
203
204typedef QList<QgsRendererRange> QgsRangeList;
205
206
212class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
213{
214 public:
216 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
217
218 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
219 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
220
221 QString format() const { return mFormat; }
222 void setFormat( const QString &format ) { mFormat = format; }
223
224 int precision() const { return mPrecision; }
225 void setPrecision( int precision );
226
227 bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
228 void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
229
231 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
232 QString labelForRange( const QgsRendererRange &range ) const;
233 QString formatNumber( double value ) const;
234
235 void setFromDomElement( QDomElement &element );
236 void saveToDomElement( QDomElement &element );
237
238 static const int MAX_PRECISION;
239 static const int MIN_PRECISION;
240
241 protected:
242 QString mFormat;
243 int mPrecision = 4;
244 bool mTrimTrailingZeroes = false;
245 // values used to manage number formatting - precision and trailing zeroes
246 double mNumberScale = 1.0;
248 QRegularExpression mReTrailingZeroes;
249 QRegularExpression mReNegativeZero;
250};
251
252
253#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: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:6284
#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