QGIS API Documentation 3.43.0-Master (32433f7016e)
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
6 email : denis@opengis.ch
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
37class CORE_EXPORT QgsRendererRange
38{
39 public:
40
41 QgsRendererRange() = default;
43
51 QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true, const QString &uuid = QString() );
52
62 QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true, const QString &uuid = QString() );
63 QgsRendererRange( const QgsRendererRange &range );
64
65 // default dtor is OK
66 QgsRendererRange &operator=( QgsRendererRange range );
67
68 bool operator<( const QgsRendererRange &other ) const;
69
74 QString uuid() const;
75
82 double lowerValue() const;
83
90 double upperValue() const;
91
97 QgsSymbol *symbol() const;
98
104 QString label() const;
105
113 void setSymbol( QgsSymbol *s SIP_TRANSFER );
114
120 void setLabel( const QString &label );
121
128 void setLowerValue( double lowerValue );
129
136 void setUpperValue( double upperValue );
137
143 bool renderState() const;
144
150 void setRenderState( bool render );
151
155 QString dump() const;
156
165 void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const;
166
167#ifdef SIP_RUN
168 SIP_PYOBJECT __repr__();
169 % MethodCode
170 const QString str = sipCpp->label().isEmpty()
171 ? QStringLiteral( "<QgsRendererRange: %1 - %2>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
172 : QStringLiteral( "<QgsRendererRange: %1 - %2 (%3)>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
173 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
174 % End
175
176 SIP_PYOBJECT __getitem__( int );
177 % MethodCode
178 if ( a0 == 0 )
179 {
180 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
181 }
182 else if ( a0 == 1 )
183 {
184 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
185 }
186 else
187 {
188 QString msg = QString( "Bad index: %1" ).arg( a0 );
189 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
190 }
191 % End
192#endif
193
194 protected:
196
197 double mLowerValue = 0, mUpperValue = 0;
198 std::unique_ptr<QgsSymbol> mSymbol;
199 QString mLabel;
200 bool mRender = true;
201 QString mUuid;
202};
203
204typedef QList<QgsRendererRange> QgsRangeList;
205
206
214class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
215{
216 public:
218 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
219
220 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
221 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
222
223 QString format() const { return mFormat; }
224 void setFormat( const QString &format ) { mFormat = format; }
225
226 int precision() const { return mPrecision; }
227 void setPrecision( int precision );
228
229 bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
230 void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
231
235 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
236 QString labelForRange( const QgsRendererRange &range ) const;
237 QString formatNumber( double value ) const;
238
239 void setFromDomElement( QDomElement &element );
240 void saveToDomElement( QDomElement &element );
241
242 static const int MAX_PRECISION;
243 static const int MIN_PRECISION;
244
245 protected:
246 QString mFormat;
247 int mPrecision = 4;
248 bool mTrimTrailingZeroes = false;
249 // values used to manage number formatting - precision and trailing zeroes
250 double mNumberScale = 1.0;
252 QRegularExpression mReTrailingZeroes;
253 QRegularExpression mReNegativeZero;
254};
255
256
257#endif // QGSRENDERERRANGE_H
Contains the information about a classification range.
A widget for configuring a QgsGraduatedSymbolRenderer.
Encapsulates the formatting for a QgsRendererRange label.
void setFormat(const QString &format)
QRegularExpression mReTrailingZeroes
QRegularExpression mReNegativeZero
void setTrimTrailingZeroes(bool trimTrailingZeroes)
Represents a value range for a QgsGraduatedSymbolRenderer.
QgsRendererRange()=default
std::unique_ptr< QgsSymbol > mSymbol
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
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:6687
#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