QGIS API Documentation 3.43.0-Master (b60ef06885e)
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 <QString>
23#include <QVariantMap>
24#include <QDomDocument>
25
26
28
35class CORE_EXPORT QgsNumericFormatContext
36{
37 Q_GADGET
38
39 public:
40
47
53 QChar thousandsSeparator() const
54 {
55 return mThousandsSep;
56 }
57
63 void setThousandsSeparator( const QChar &separator )
64 {
65 mThousandsSep = separator;
66 }
67
73 QChar decimalSeparator() const
74 {
75 return mDecimalSep;
76 }
77
83 void setDecimalSeparator( const QChar &separator )
84 {
85 mDecimalSep = separator;
86 }
87
93 QChar percent() const
94 {
95 return mPercent;
96 }
97
103 void setPercent( const QChar &character )
104 {
105 mPercent = character;
106 }
107
113 QChar zeroDigit() const
114 {
115 return mZeroDigit;
116 }
117
123 void setZeroDigit( const QChar &character )
124 {
125 mZeroDigit = character;
126 }
127
133 QChar negativeSign() const
134 {
135 return mNegativeSign;
136 }
137
143 void setNegativeSign( const QChar &character )
144 {
145 mNegativeSign = character;
146 }
147
153 QChar positiveSign() const
154 {
155 return mPositiveSign;
156 }
157
163 void setPositiveSign( const QChar &character )
164 {
165 mPositiveSign = character;
166 }
167
173 QChar exponential() const
174 {
175 return mExponential;
176 }
177
183 void setExponential( const QChar &character )
184 {
185 mExponential = character;
186 }
187
193 enum class Interpretation
194 {
195 Generic,
196 Latitude,
197 Longitude,
198 };
199 Q_ENUM( Interpretation )
200
201
208 Interpretation interpretation() const
209 {
210 return mInterpretation;
211 }
212
220 void setInterpretation( Interpretation interpretation )
221 {
222 mInterpretation = interpretation;
223 }
224
231 QgsExpressionContext expressionContext() const;
232
239 void setExpressionContext( const QgsExpressionContext &context );
240
241 private:
242 QChar mThousandsSep;
243 QChar mDecimalSep;
244 QChar mPercent;
245 QChar mZeroDigit;
246 QChar mNegativeSign;
247 QChar mPositiveSign;
248 QChar mExponential;
249
250 Interpretation mInterpretation = Interpretation::Generic;
251
252 QgsExpressionContext mExpressionContext;
253};
254
255#ifdef SIP_RUN
256% ModuleHeaderCode
265% End
266#endif
267
279class CORE_EXPORT QgsNumericFormat
280{
281
282#ifdef SIP_RUN
284 if ( dynamic_cast< QgsBearingNumericFormat * >( sipCpp ) )
285 sipType = sipType_QgsBearingNumericFormat;
286 else if ( dynamic_cast< QgsGeographicCoordinateNumericFormat * >( sipCpp ) )
287 sipType = sipType_QgsGeographicCoordinateNumericFormat;
288 else if ( dynamic_cast< QgsFallbackNumericFormat * >( sipCpp ) )
289 sipType = sipType_QgsFallbackNumericFormat;
290 else if ( dynamic_cast< QgsPercentageNumericFormat * >( sipCpp ) )
291 sipType = sipType_QgsPercentageNumericFormat;
292 else if ( dynamic_cast< QgsScientificNumericFormat * >( sipCpp ) )
293 sipType = sipType_QgsScientificNumericFormat;
294 else if ( dynamic_cast< QgsCurrencyNumericFormat * >( sipCpp ) )
295 sipType = sipType_QgsCurrencyNumericFormat;
296 else if ( dynamic_cast< QgsBasicNumericFormat * >( sipCpp ) )
297 sipType = sipType_QgsBasicNumericFormat;
298 else if ( dynamic_cast< QgsFractionNumericFormat * >( sipCpp ) )
299 sipType = sipType_QgsFractionNumericFormat;
300 else if ( dynamic_cast< QgsExpressionBasedNumericFormat * >( sipCpp ) )
301 sipType = sipType_QgsExpressionBasedNumericFormat;
302 else
303 sipType = NULL;
304 SIP_END
305#endif
306
307 public:
308
309 QgsNumericFormat() = default;
310
311 virtual ~QgsNumericFormat() = default;
312
318 virtual QString id() const = 0;
319
323 virtual QString visibleName() const = 0;
324
330 virtual int sortKey();
331
335 virtual double suggestSampleValue() const;
336
340 virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const = 0;
341
347 virtual QgsNumericFormat *clone() const = 0 SIP_FACTORY;
348
354 virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const = 0 SIP_FACTORY;
355
360 virtual QVariantMap configuration( const QgsReadWriteContext &context ) const = 0;
361
366 void writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
367
368 bool operator==( const QgsNumericFormat &other ) const;
369 bool operator!=( const QgsNumericFormat &other ) const;
370
371 protected:
372
373 static constexpr int DEFAULT_SORT_KEY = 100;
374};
375
376#endif // QGSNUMERICFORMAT_H
A numeric formater which returns a simple text representation of a value.
A numeric formater which returns a text representation of a direction/bearing.
A numeric formater 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 formater which returns a simple text representation of a value.
A numeric formater which returns a vulgar fractional representation of a decimal value (e....
A numeric formater which returns a text representation of a geographic coordinate (latitude or longit...
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.
QChar exponential() const
Returns the exponential character.
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.
Abstract base class for numeric formatters, which allow for formatting a numeric value for display.
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.
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.
virtual QVariantMap configuration(const QgsReadWriteContext &context) const =0
Returns the current configuration of the formatter.
virtual ~QgsNumericFormat()=default
A numeric formater which returns a text representation of a percentage value.
A container for the context for various read/write operations on objects.
A numeric formater which returns a scientific notation representation of a value.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)