QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsnumericformat.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsnumericformat.h
3 -------------------
4 begin : January 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
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#ifndef QGSNUMERICFORMAT_H
16#define QGSNUMERICFORMAT_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
21
22#include <QDomDocument>
23#include <QString>
24#include <QVariantMap>
25
27
34class CORE_EXPORT QgsNumericFormatContext
35{
36 Q_GADGET
37
38 public:
45
51 QChar thousandsSeparator() const { return mThousandsSep; }
52
58 void setThousandsSeparator( const QChar &separator ) { mThousandsSep = separator; }
59
65 QChar decimalSeparator() const { return mDecimalSep; }
66
72 void setDecimalSeparator( const QChar &separator ) { mDecimalSep = separator; }
73
79 QChar percent() const { return mPercent; }
80
86 void setPercent( const QChar &character ) { mPercent = character; }
87
93 QChar zeroDigit() const { return mZeroDigit; }
94
100 void setZeroDigit( const QChar &character ) { mZeroDigit = character; }
101
107 QChar negativeSign() const { return mNegativeSign; }
108
114 void setNegativeSign( const QChar &character ) { mNegativeSign = character; }
115
121 QChar positiveSign() const { return mPositiveSign; }
122
128 void setPositiveSign( const QChar &character ) { mPositiveSign = character; }
129
135 QChar exponential() const { return mExponential; }
136
142 void setExponential( const QChar &character ) { mExponential = character; }
143
149 enum class Interpretation
150 {
151 Generic,
152 Latitude,
153 Longitude,
154 };
155 Q_ENUM( Interpretation )
156
157
164 Interpretation interpretation() const { return mInterpretation; }
165
174
181 QgsExpressionContext expressionContext() const;
182
189 void setExpressionContext( const QgsExpressionContext &context );
190
191 private:
192 QChar mThousandsSep;
193 QChar mDecimalSep;
194 QChar mPercent;
195 QChar mZeroDigit;
196 QChar mNegativeSign;
197 QChar mPositiveSign;
198 QChar mExponential;
199
200 Interpretation mInterpretation = Interpretation::Generic;
201
202 QgsExpressionContext mExpressionContext;
203};
204
205#ifdef SIP_RUN
206// clang-format off
207% ModuleHeaderCode
216% End
217// clang-format on
218#endif
219
231 class CORE_EXPORT QgsNumericFormat
232{
233#ifdef SIP_RUN
235 if ( dynamic_cast< QgsBearingNumericFormat * >( sipCpp ) )
236 sipType = sipType_QgsBearingNumericFormat;
237 else if ( dynamic_cast< QgsGeographicCoordinateNumericFormat * >( sipCpp ) )
238 sipType = sipType_QgsGeographicCoordinateNumericFormat;
239 else if ( dynamic_cast< QgsFallbackNumericFormat * >( sipCpp ) )
240 sipType = sipType_QgsFallbackNumericFormat;
241 else if ( dynamic_cast< QgsPercentageNumericFormat * >( sipCpp ) )
242 sipType = sipType_QgsPercentageNumericFormat;
243 else if ( dynamic_cast< QgsScientificNumericFormat * >( sipCpp ) )
244 sipType = sipType_QgsScientificNumericFormat;
245 else if ( dynamic_cast< QgsCurrencyNumericFormat * >( sipCpp ) )
246 sipType = sipType_QgsCurrencyNumericFormat;
247 else if ( dynamic_cast< QgsBasicNumericFormat * >( sipCpp ) )
248 sipType = sipType_QgsBasicNumericFormat;
249 else if ( dynamic_cast< QgsFractionNumericFormat * >( sipCpp ) )
250 sipType = sipType_QgsFractionNumericFormat;
251 else if ( dynamic_cast< QgsExpressionBasedNumericFormat * >( sipCpp ) )
252 sipType = sipType_QgsExpressionBasedNumericFormat;
253 else
254 sipType = NULL;
255 SIP_END
256#endif
257
258 public:
259
260 QgsNumericFormat() = default;
261
262 virtual ~QgsNumericFormat() = default;
263
269 virtual QString id() const = 0;
270
274 virtual QString visibleName() const = 0;
275
281 virtual int sortKey();
282
286 virtual double suggestSampleValue() const;
287
291 virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const = 0;
292
298 virtual QgsNumericFormat *clone() const = 0 SIP_FACTORY;
299
305 virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const = 0 SIP_FACTORY;
306
311 virtual QVariantMap configuration( const QgsReadWriteContext &context ) const = 0;
312
317 void writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
318
319 bool operator==( const QgsNumericFormat &other ) const;
320 bool operator!=( const QgsNumericFormat &other ) const;
321
322 protected:
323 static constexpr int DEFAULT_SORT_KEY = 100;
324};
325
326#endif // QGSNUMERICFORMAT_H
A numeric formatter which returns a simple text representation of a value.
A numeric formatter which returns a text representation of a direction/bearing.
A numeric formatter which returns a text representation of a currency value.
A numeric formatter which uses a QgsExpression to calculate the text representation of a value.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A basic numeric formatter which returns a simple text representation of a value.
A numeric formatter which returns a vulgar fractional representation of a decimal value (e....
A numeric formatter which returns a text representation of a geographic coordinate (latitude or longi...
A context for numeric formats.
void setThousandsSeparator(const QChar &separator)
Sets the thousands separator character.
QChar negativeSign() const
Returns the negative sign character.
QChar thousandsSeparator() const
Returns the thousands separator character.
void setPercent(const QChar &character)
Sets the percent character.
void setPositiveSign(const QChar &character)
Sets the positive sign character.
void setExponential(const QChar &character)
Sets the exponential character.
void setNegativeSign(const QChar &character)
Sets the negative sign character.
QChar zeroDigit() const
Returns the zero digit character.
QgsNumericFormatContext()
Constructor for QgsNumericFormatContext.
QChar exponential() const
Returns the exponential character.
Interpretation interpretation() const
Returns the interpretation of the numbers being converted.
void setInterpretation(Interpretation interpretation)
Sets the interpretation of the numbers being converted.
QChar decimalSeparator() const
Returns the decimal separator character.
void setDecimalSeparator(const QChar &separator)
Returns the decimal separator character.
void setZeroDigit(const QChar &character)
Returns the zero digit character.
QChar positiveSign() const
Returns the positive sign character.
QChar percent() const
Returns the percent character.
Interpretation
Interpretation of numeric values.
static constexpr int DEFAULT_SORT_KEY
virtual QgsNumericFormat * create(const QVariantMap &configuration, const QgsReadWriteContext &context) const =0
Creates a new copy of the format, using the supplied configuration.
virtual QString formatDouble(double value, const QgsNumericFormatContext &context) const =0
Returns a formatted string representation of a numeric double value.
virtual QgsNumericFormat * clone() const =0
Clones the format, returning a new object.
virtual int sortKey()
Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
QgsNumericFormat()=default
virtual QString visibleName() const =0
Returns the translated, user-visible name for this format.
virtual QString id() const =0
Returns a unique id for this numeric format.
void writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the format to an XML element.
virtual double suggestSampleValue() const
Returns a suggested sample value which nicely represents the current format configuration.
virtual QVariantMap configuration(const QgsReadWriteContext &context) const =0
Returns the current configuration of the formatter.
virtual ~QgsNumericFormat()=default
A numeric formatter which returns a text representation of a percentage value.
A container for the context for various read/write operations on objects.
A numeric formatter which returns a scientific notation representation of a value.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)