QGIS API Documentation 3.41.0-Master (3440c17df1d)
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 <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
278class CORE_EXPORT QgsNumericFormat
279{
280
281#ifdef SIP_RUN
283 if ( dynamic_cast< QgsBearingNumericFormat * >( sipCpp ) )
284 sipType = sipType_QgsBearingNumericFormat;
285 else if ( dynamic_cast< QgsGeographicCoordinateNumericFormat * >( sipCpp ) )
286 sipType = sipType_QgsGeographicCoordinateNumericFormat;
287 else if ( dynamic_cast< QgsFallbackNumericFormat * >( sipCpp ) )
288 sipType = sipType_QgsFallbackNumericFormat;
289 else if ( dynamic_cast< QgsPercentageNumericFormat * >( sipCpp ) )
290 sipType = sipType_QgsPercentageNumericFormat;
291 else if ( dynamic_cast< QgsScientificNumericFormat * >( sipCpp ) )
292 sipType = sipType_QgsScientificNumericFormat;
293 else if ( dynamic_cast< QgsCurrencyNumericFormat * >( sipCpp ) )
294 sipType = sipType_QgsCurrencyNumericFormat;
295 else if ( dynamic_cast< QgsBasicNumericFormat * >( sipCpp ) )
296 sipType = sipType_QgsBasicNumericFormat;
297 else if ( dynamic_cast< QgsFractionNumericFormat * >( sipCpp ) )
298 sipType = sipType_QgsFractionNumericFormat;
299 else if ( dynamic_cast< QgsExpressionBasedNumericFormat * >( sipCpp ) )
300 sipType = sipType_QgsExpressionBasedNumericFormat;
301 else
302 sipType = NULL;
303 SIP_END
304#endif
305
306 public:
307
308 QgsNumericFormat() = default;
309
310 virtual ~QgsNumericFormat() = default;
311
317 virtual QString id() const = 0;
318
322 virtual QString visibleName() const = 0;
323
329 virtual int sortKey();
330
334 virtual double suggestSampleValue() const;
335
339 virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const = 0;
340
346 virtual QgsNumericFormat *clone() const = 0 SIP_FACTORY;
347
353 virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const = 0 SIP_FACTORY;
354
359 virtual QVariantMap configuration( const QgsReadWriteContext &context ) const = 0;
360
365 void writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
366
367 bool operator==( const QgsNumericFormat &other ) const;
368 bool operator!=( const QgsNumericFormat &other ) const;
369
370 protected:
371
372 static constexpr int DEFAULT_SORT_KEY = 100;
373};
374
375#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.
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
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: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)