QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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:
39
46
52 QChar thousandsSeparator() const
53 {
54 return mThousandsSep;
55 }
56
62 void setThousandsSeparator( const QChar &separator )
63 {
64 mThousandsSep = separator;
65 }
66
72 QChar decimalSeparator() const
73 {
74 return mDecimalSep;
75 }
76
82 void setDecimalSeparator( const QChar &separator )
83 {
84 mDecimalSep = separator;
85 }
86
92 QChar percent() const
93 {
94 return mPercent;
95 }
96
102 void setPercent( const QChar &character )
103 {
104 mPercent = character;
105 }
106
112 QChar zeroDigit() const
113 {
114 return mZeroDigit;
115 }
116
122 void setZeroDigit( const QChar &character )
123 {
124 mZeroDigit = character;
125 }
126
132 QChar negativeSign() const
133 {
134 return mNegativeSign;
135 }
136
142 void setNegativeSign( const QChar &character )
143 {
144 mNegativeSign = character;
145 }
146
152 QChar positiveSign() const
153 {
154 return mPositiveSign;
155 }
156
162 void setPositiveSign( const QChar &character )
163 {
164 mPositiveSign = character;
165 }
166
172 QChar exponential() const
173 {
174 return mExponential;
175 }
176
182 void setExponential( const QChar &character )
183 {
184 mExponential = character;
185 }
186
192 enum class Interpretation
193 {
194 Generic,
195 Latitude,
196 Longitude,
197 };
198 Q_ENUM( Interpretation )
199
200
208 {
209 return mInterpretation;
210 }
211
220 {
221 mInterpretation = interpretation;
222 }
223
230 QgsExpressionContext expressionContext() const;
231
238 void setExpressionContext( const QgsExpressionContext &context );
239
240 private:
241 QChar mThousandsSep;
242 QChar mDecimalSep;
243 QChar mPercent;
244 QChar mZeroDigit;
245 QChar mNegativeSign;
246 QChar mPositiveSign;
247 QChar mExponential;
248
249 Interpretation mInterpretation = Interpretation::Generic;
250
251 QgsExpressionContext mExpressionContext;
252};
253
254#ifdef SIP_RUN
255% ModuleHeaderCode
264% End
265#endif
266
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.
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:199
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)