QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 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
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
116
122 void setLabel( const QString &label );
123
130 void setLowerValue( double lowerValue );
131
138 void setUpperValue( double upperValue );
139
145 bool renderState() const;
146
152 void setRenderState( bool render );
153
157 QString dump() const;
158
168 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const SIP_DEPRECATED;
169
180 bool toSld( QDomDocument &doc, QDomElement &element, const QString &classAttribute, QgsSldExportContext &context, bool firstRange = false ) const;
181
182#ifdef SIP_RUN
183 // clang-format off
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// clang-format on
209#endif
210
211 // clang-format off
212 protected:
213 // clang-format on
215
216 double mLowerValue = 0, mUpperValue = 0;
217 std::unique_ptr<QgsSymbol> mSymbol;
218 QString mLabel;
219 bool mRender = true;
220 QString mUuid;
221};
222
223typedef QList<QgsRendererRange> QgsRangeList;
224
225
233class CORE_DEPRECATED_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
234{
235 public:
237 QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
238
239 bool operator==( const QgsRendererRangeLabelFormat &other ) const;
240 bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
241
242 QString format() const { return mFormat; }
243 void setFormat( const QString &format ) { mFormat = format; }
244
245 int precision() const { return mPrecision; }
246 void setPrecision( int precision );
247
250
254 QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
255 QString labelForRange( const QgsRendererRange &range ) const;
256 QString formatNumber( double value ) const;
257
258 void setFromDomElement( QDomElement &element );
259 void saveToDomElement( QDomElement &element );
260
261 static const int MAX_PRECISION;
262 static const int MIN_PRECISION;
263
264 protected:
265 QString mFormat;
266 int mPrecision = 4;
268 // values used to manage number formatting - precision and trailing zeroes
269 double mNumberScale = 1.0;
271 QRegularExpression mReTrailingZeroes;
272 QRegularExpression mReNegativeZero;
273};
274
275
276#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:227
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:7396
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
#define SIP_TRANSFER
Definition qgis_sip.h:35
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QList< QgsRendererRange > QgsRangeList