QGIS API Documentation 3.99.0-Master (d270888f95f)
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#include <QString>
25
26using namespace Qt::StringLiterals;
27
28class QDomDocument;
29class QDomElement;
30
31class QgsSymbol;
33
34
40class CORE_EXPORT QgsRendererRange
41{
42 public:
43
44 QgsRendererRange() = default;
46
54 QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true, const QString &uuid = QString() );
55
65 QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true, const QString &uuid = QString() );
66 QgsRendererRange( const QgsRendererRange &range );
67
68 // default dtor is OK
70
71 bool operator<( const QgsRendererRange &other ) const;
72
77 QString uuid() const;
78
85 double lowerValue() const;
86
93 double upperValue() const;
94
100 QgsSymbol *symbol() const;
101
107 QString label() const;
108
117
123 void setLabel( const QString &label );
124
131 void setLowerValue( double lowerValue );
132
139 void setUpperValue( double upperValue );
140
146 bool renderState() const;
147
153 void setRenderState( bool render );
154
158 QString dump() const;
159
169 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const SIP_DEPRECATED;
170
181 bool toSld( QDomDocument &doc, QDomElement &element, const QString &classAttribute, QgsSldExportContext &context, bool firstRange = false ) const;
182
183#ifdef SIP_RUN
184 SIP_PYOBJECT __repr__();
185 % MethodCode
186 const QString str = sipCpp->label().isEmpty()
187 ? u"<QgsRendererRange: %1 - %2>"_s.arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() )
188 : u"<QgsRendererRange: %1 - %2 (%3)>"_s.arg( sipCpp->lowerValue() ).arg( sipCpp->upperValue() ).arg( sipCpp->label() );
189 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
190 % End
191
192 SIP_PYOBJECT __getitem__( int );
193 % MethodCode
194 if ( a0 == 0 )
195 {
196 sipRes = Py_BuildValue( "d", sipCpp->lowerValue() );
197 }
198 else if ( a0 == 1 )
199 {
200 sipRes = Py_BuildValue( "d", sipCpp->upperValue() );
201 }
202 else
203 {
204 QString msg = QString( "Bad index: %1" ).arg( a0 );
205 PyErr_SetString( PyExc_IndexError, msg.toLatin1().constData() );
206 }
207 % End
208#endif
209
210 protected:
212
213 double mLowerValue = 0, mUpperValue = 0;
214 std::unique_ptr<QgsSymbol> mSymbol;
215 QString mLabel;
216 bool mRender = true;
217 QString mUuid;
218};
219
220typedef QList<QgsRendererRange> QgsRangeList;
221
222
230class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
231{
232 public:
234 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
235
236 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
237 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
238
239 QString format() const { return mFormat; }
240 void setFormat( const QString &format ) { mFormat = format; }
241
242 int precision() const { return mPrecision; }
243 void setPrecision( int precision );
244
247
251 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
252 QString labelForRange( const QgsRendererRange &range ) const;
253 QString formatNumber( double value ) const;
254
255 void setFromDomElement( QDomElement &element );
256 void saveToDomElement( QDomElement &element );
257
258 static const int MAX_PRECISION;
259 static const int MIN_PRECISION;
260
261 protected:
262 QString mFormat;
263 int mPrecision = 4;
265 // values used to manage number formatting - precision and trailing zeroes
266 double mNumberScale = 1.0;
268 QRegularExpression mReTrailingZeroes;
269 QRegularExpression mReNegativeZero;
270};
271
272
273#endif // QGSRENDERERRANGE_H
Contains the information about a classification range.
void setFormat(const QString &format)
QRegularExpression mReTrailingZeroes
QRegularExpression mReNegativeZero
void setTrimTrailingZeroes(bool trimTrailingZeroes)
Represents a value range for a QgsGraduatedSymbolRenderer.
void setUpperValue(double upperValue)
Sets the upper bound of the range.
QgsRendererRange()=default
QString label() const
Returns the label used for the range.
void setSymbol(QgsSymbol *s)
Sets the symbol used for the range.
std::unique_ptr< QgsSymbol > mSymbol
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange=false) const
Creates a DOM element representing the range in SLD format.
QgsRendererRange & operator=(QgsRendererRange range)
QgsSymbol * symbol() const
Returns the symbol used for the range.
void setLabel(const QString &label)
Sets the label used for the range.
bool renderState() const
Returns true if the range should be rendered.
friend class QgsGraduatedSymbolRendererWidget
void setRenderState(bool render)
Sets whether the range should be rendered.
QString dump() const
Dumps a string representation of the range.
double upperValue() const
Returns the upper bound of the range.
void setLowerValue(double lowerValue)
Sets the lower bound of the range.
QString uuid() const
Returns the unique identifier for this range.
double lowerValue() const
Returns the lower bound of the range.
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:7330
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_PYNAME(name)
Definition qgis_sip.h:89
#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