QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
34 class 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
239 #include <qgsbasicnumericformat.h>
240 #include <qgsbearingnumericformat.h>
246 % End
247 #endif
248 
259 class 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
qgsfallbacknumericformat.h
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsGeographicCoordinateNumericFormat
A numeric formatter which returns a text representation of a geographic coordinate (latitude or longi...
Definition: qgscoordinatenumericformat.h:28
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
QgsFallbackNumericFormat
A basic numeric formatter which returns a simple text representation of a value.
Definition: qgsfallbacknumericformat.h:28
QgsNumericFormatContext::setPercent
void setPercent(const QChar &character)
Sets the percent character.
Definition: qgsnumericformat.h:103
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:259
qgscurrencynumericformat.h
QgsNumericFormatContext::negativeSign
QChar negativeSign() const
Returns the negative sign character.
Definition: qgsnumericformat.h:133
QgsBasicNumericFormat
A numeric formatter which returns a simple text representation of a value.
Definition: qgsbasicnumericformat.h:31
QgsNumericFormatContext::exponential
QChar exponential() const
Returns the exponential character.
Definition: qgsnumericformat.h:173
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:430
qgsbearingnumericformat.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsPercentageNumericFormat
A numeric formatter which returns a text representation of a percentage value.
Definition: qgspercentagenumericformat.h:28
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QgsNumericFormatContext::positiveSign
QChar positiveSign() const
Returns the positive sign character.
Definition: qgsnumericformat.h:153
qgis_sip.h
QgsNumericFormatContext::percent
QChar percent() const
Returns the percent character.
Definition: qgsnumericformat.h:93
qgsscientificnumericformat.h
QgsNumericFormatContext::setDecimalSeparator
void setDecimalSeparator(const QChar &separator)
Returns the decimal separator character.
Definition: qgsnumericformat.h:83
QgsFractionNumericFormat
A numeric formatter which returns a vulgar fractional representation of a decimal value (e....
Definition: qgsfractionnumericformat.h:30
qgsbasicnumericformat.h
QgsScientificNumericFormat
A numeric formatter which returns a scientific notation representation of a value.
Definition: qgsscientificnumericformat.h:28
QgsNumericFormatContext::setPositiveSign
void setPositiveSign(const QChar &character)
Sets the positive sign character.
Definition: qgsnumericformat.h:163
qgscoordinatenumericformat.h
QgsCurrencyNumericFormat
A numeric formatter which returns a text representation of a currency value.
Definition: qgscurrencynumericformat.h:28
QgsNumericFormatContext::Interpretation
Interpretation
Interpretation of numeric values.
Definition: qgsnumericformat.h:193
QgsNumericFormatContext::setInterpretation
void setInterpretation(Interpretation interpretation)
Sets the interpretation of the numbers being converted.
Definition: qgsnumericformat.h:220
QgsNumericFormatContext::setThousandsSeparator
void setThousandsSeparator(const QChar &separator)
Sets the thousands separator character.
Definition: qgsnumericformat.h:63
QgsNumericFormatContext::zeroDigit
QChar zeroDigit() const
Returns the zero digit character.
Definition: qgsnumericformat.h:113
QgsNumericFormatContext::setExponential
void setExponential(const QChar &character)
Sets the exponential character.
Definition: qgsnumericformat.h:183
QgsNumericFormatContext::setNegativeSign
void setNegativeSign(const QChar &character)
Sets the negative sign character.
Definition: qgsnumericformat.h:143
QgsBearingNumericFormat
A numeric formatter which returns a text representation of a direction/bearing.
Definition: qgsbearingnumericformat.h:28
qgspercentagenumericformat.h
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
QgsNumericFormatContext::decimalSeparator
QChar decimalSeparator() const
Returns the decimal separator character.
Definition: qgsnumericformat.h:73
QgsNumericFormatContext::setZeroDigit
void setZeroDigit(const QChar &character)
Returns the zero digit character.
Definition: qgsnumericformat.h:123
QgsNumericFormatContext
A context for numeric formats.
Definition: qgsnumericformat.h:34
QgsNumericFormatContext::thousandsSeparator
QChar thousandsSeparator() const
Returns the thousands separator character.
Definition: qgsnumericformat.h:53