QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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"
20
21#include <QString>
22#include <QVariantMap>
23#include <QDomDocument>
24
25
27
34class CORE_EXPORT QgsNumericFormatContext
35{
36 Q_GADGET
37
38 public:
39
46
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
225 private:
226 QChar mThousandsSep;
227 QChar mDecimalSep;
228 QChar mPercent;
229 QChar mZeroDigit;
230 QChar mNegativeSign;
231 QChar mPositiveSign;
232 QChar mExponential;
233
234 Interpretation mInterpretation = Interpretation::Generic;
235};
236
237#ifdef SIP_RUN
238% ModuleHeaderCode
246% End
247#endif
248
259class CORE_EXPORT QgsNumericFormat
260{
261
262#ifdef SIP_RUN
264 if ( dynamic_cast< QgsBearingNumericFormat * >( sipCpp ) )
265 sipType = sipType_QgsBearingNumericFormat;
266 else if ( dynamic_cast< QgsGeographicCoordinateNumericFormat * >( sipCpp ) )
267 sipType = sipType_QgsGeographicCoordinateNumericFormat;
268 else if ( dynamic_cast< QgsFallbackNumericFormat * >( sipCpp ) )
269 sipType = sipType_QgsFallbackNumericFormat;
270 else if ( dynamic_cast< QgsPercentageNumericFormat * >( sipCpp ) )
271 sipType = sipType_QgsPercentageNumericFormat;
272 else if ( dynamic_cast< QgsScientificNumericFormat * >( sipCpp ) )
273 sipType = sipType_QgsScientificNumericFormat;
274 else if ( dynamic_cast< QgsCurrencyNumericFormat * >( sipCpp ) )
275 sipType = sipType_QgsCurrencyNumericFormat;
276 else if ( dynamic_cast< QgsBasicNumericFormat * >( sipCpp ) )
277 sipType = sipType_QgsBasicNumericFormat;
278 else if ( dynamic_cast< QgsFractionNumericFormat * >( sipCpp ) )
279 sipType = sipType_QgsFractionNumericFormat;
280 else
281 sipType = NULL;
282 SIP_END
283#endif
284
285 public:
286
290 QgsNumericFormat() = default;
291
292 virtual ~QgsNumericFormat() = default;
293
299 virtual QString id() const = 0;
300
304 virtual QString visibleName() const = 0;
305
311 virtual int sortKey();
312
316 virtual double suggestSampleValue() const;
317
321 virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const = 0;
322
328 virtual QgsNumericFormat *clone() const = 0 SIP_FACTORY;
329
335 virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const = 0 SIP_FACTORY;
336
341 virtual QVariantMap configuration( const QgsReadWriteContext &context ) const = 0;
342
347 void writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
348
349 bool operator==( const QgsNumericFormat &other ) const;
350 bool operator!=( const QgsNumericFormat &other ) const;
351
352 protected:
353
354 static constexpr int DEFAULT_SORT_KEY = 100;
355};
356
357#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 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.
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.
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
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
Default constructor.
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 formatter which returns a text representation of a percentage value.
The class is used as a container of context for various read/write operations on other objects.
A numeric formatter which returns a scientific notation representation of a value.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:186
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:203
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)