QGIS API Documentation 3.35.0-Master (274c3da7543)
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
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
146 bool renderState() const;
147
154 void setRenderState( bool render );
155
159 QString dump() const;
160
169 void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const;
170
171#ifdef SIP_RUN
172 SIP_PYOBJECT __repr__();
173 % MethodCode
174 const QString str = sipCpp->label().isEmpty()
175 ? QStringLiteral( "<QgsRendererRange: %1 - %2>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
176 : QStringLiteral( "<QgsRendererRange: %1 - %2 (%3)>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
177 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
178 % End
179
180 SIP_PYOBJECT __getitem__( int );
181 % MethodCode
182 if ( a0 == 0 )
183 {
184 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
185 }
186 else if ( a0 == 1 )
187 {
188 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
189 }
190 else
191 {
192 QString msg = QString( "Bad index: %1" ).arg( a0 );
193 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
194 }
195 % End
196#endif
197
198 protected:
199 double mLowerValue = 0, mUpperValue = 0;
200 std::unique_ptr<QgsSymbol> mSymbol;
201 QString mLabel;
202 bool mRender = true;
203 QString mUuid;
204
205 // for cpy+swap idiom
206 void swap( QgsRendererRange &other );
207};
208
209typedef QList<QgsRendererRange> QgsRangeList;
210
211
218class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
219{
220 public:
222 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
223
224 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
225 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
226
227 QString format() const { return mFormat; }
228 void setFormat( const QString &format ) { mFormat = format; }
229
230 int precision() const { return mPrecision; }
231 void setPrecision( int precision );
232
233 bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
234 void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
235
237 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
238 QString labelForRange( const QgsRendererRange &range ) const;
239 QString formatNumber( double value ) const;
240
241 void setFromDomElement( QDomElement &element );
242 void saveToDomElement( QDomElement &element );
243
244 static const int MAX_PRECISION;
245 static const int MIN_PRECISION;
246
247 protected:
248 QString mFormat;
249 int mPrecision = 4;
250 bool mTrimTrailingZeroes = false;
251 // values used to manage number formatting - precision and trailing zeroes
252 double mNumberScale = 1.0;
254 QRegularExpression mReTrailingZeroes;
255 QRegularExpression mReNegativeZero;
256};
257
258
259#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
#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:5227
#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