QGIS API Documentation 3.43.0-Master (56aa1fd18d7)
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
166 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const SIP_DEPRECATED;
167
178 bool toSld( QDomDocument &doc, QDomElement &element, const QString &classAttribute, QgsSldExportContext &context, bool firstRange = false ) const;
179
180#ifdef SIP_RUN
181 SIP_PYOBJECT __repr__();
182 % MethodCode
183 const QString str = sipCpp->label().isEmpty()
184 ? QStringLiteral( "<QgsRendererRange: %1 - %2>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
185 : QStringLiteral( "<QgsRendererRange: %1 - %2 (%3)>" ).arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
186 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
187 % End
188
189 SIP_PYOBJECT __getitem__( int );
190 % MethodCode
191 if ( a0 == 0 )
192 {
193 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
194 }
195 else if ( a0 == 1 )
196 {
197 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
198 }
199 else
200 {
201 QString msg = QString( "Bad index: %1" ).arg( a0 );
202 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
203 }
204 % End
205#endif
206
207 protected:
209
210 double mLowerValue = 0, mUpperValue = 0;
211 std::unique_ptr<QgsSymbol> mSymbol;
212 QString mLabel;
213 bool mRender = true;
214 QString mUuid;
215};
216
217typedef QList<QgsRendererRange> QgsRangeList;
218
219
227class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
228{
229 public:
231 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
232
233 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
234 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
235
236 QString format() const { return mFormat; }
237 void setFormat( const QString &format ) { mFormat = format; }
238
239 int precision() const { return mPrecision; }
240 void setPrecision( int precision );
241
242 bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
243 void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
244
248 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
249 QString labelForRange( const QgsRendererRange &range ) const;
250 QString formatNumber( double value ) const;
251
252 void setFromDomElement( QDomElement &element );
253 void saveToDomElement( QDomElement &element );
254
255 static const int MAX_PRECISION;
256 static const int MIN_PRECISION;
257
258 protected:
259 QString mFormat;
260 int mPrecision = 4;
261 bool mTrimTrailingZeroes = false;
262 // values used to manage number formatting - precision and trailing zeroes
263 double mNumberScale = 1.0;
265 QRegularExpression mReTrailingZeroes;
266 QRegularExpression mReNegativeZero;
267};
268
269
270#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
Holds SLD export options and other information related to SLD export of a QGIS layer style.
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:6723
#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