QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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  public:
37 
44 
45 
51  QChar thousandsSeparator() const
52  {
53  return mThousandsSep;
54  }
55 
61  void setThousandsSeparator( const QChar &separator )
62  {
63  mThousandsSep = separator;
64  }
65 
71  QChar decimalSeparator() const
72  {
73  return mDecimalSep;
74  }
75 
81  void setDecimalSeparator( const QChar &separator )
82  {
83  mDecimalSep = separator;
84  }
85 
91  QChar percent() const
92  {
93  return mPercent;
94  }
95 
101  void setPercent( const QChar &character )
102  {
103  mPercent = character;
104  }
105 
111  QChar zeroDigit() const
112  {
113  return mZeroDigit;
114  }
115 
121  void setZeroDigit( const QChar &character )
122  {
123  mZeroDigit = character;
124  }
125 
131  QChar negativeSign() const
132  {
133  return mNegativeSign;
134  }
135 
141  void setNegativeSign( const QChar &character )
142  {
143  mNegativeSign = character;
144  }
145 
151  QChar positiveSign() const
152  {
153  return mPositiveSign;
154  }
155 
161  void setPositiveSign( const QChar &character )
162  {
163  mPositiveSign = character;
164  }
165 
171  QChar exponential() const
172  {
173  return mExponential;
174  }
175 
181  void setExponential( const QChar &character )
182  {
183  mExponential = character;
184  }
185 
186  private:
187  QChar mThousandsSep;
188  QChar mDecimalSep;
189  QChar mPercent;
190  QChar mZeroDigit;
191  QChar mNegativeSign;
192  QChar mPositiveSign;
193  QChar mExponential;
194 };
195 
196 #ifdef SIP_RUN
197 % ModuleHeaderCode
198 #include <qgsbasicnumericformat.h>
199 #include <qgsbearingnumericformat.h>
204 % End
205 #endif
206 
217 class CORE_EXPORT QgsNumericFormat
218 {
219 
220 #ifdef SIP_RUN
222  if ( dynamic_cast< QgsBearingNumericFormat * >( sipCpp ) )
223  sipType = sipType_QgsBearingNumericFormat;
224  else if ( dynamic_cast< QgsFallbackNumericFormat * >( sipCpp ) )
225  sipType = sipType_QgsFallbackNumericFormat;
226  else if ( dynamic_cast< QgsPercentageNumericFormat * >( sipCpp ) )
227  sipType = sipType_QgsPercentageNumericFormat;
228  else if ( dynamic_cast< QgsScientificNumericFormat * >( sipCpp ) )
229  sipType = sipType_QgsScientificNumericFormat;
230  else if ( dynamic_cast< QgsCurrencyNumericFormat * >( sipCpp ) )
231  sipType = sipType_QgsCurrencyNumericFormat;
232  else if ( dynamic_cast< QgsBasicNumericFormat * >( sipCpp ) )
233  sipType = sipType_QgsBasicNumericFormat;
234  else
235  sipType = NULL;
236  SIP_END
237 #endif
238 
239  public:
240 
244  QgsNumericFormat() = default;
245 
246  virtual ~QgsNumericFormat() = default;
247 
253  virtual QString id() const = 0;
254 
258  virtual QString visibleName() const = 0;
259 
265  virtual int sortKey();
266 
270  virtual double suggestSampleValue() const;
271 
275  virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const = 0;
276 
282  virtual QgsNumericFormat *clone() const = 0 SIP_FACTORY;
283 
289  virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const = 0 SIP_FACTORY;
290 
295  virtual QVariantMap configuration( const QgsReadWriteContext &context ) const = 0;
296 
301  void writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
302 
303  bool operator==( const QgsNumericFormat &other ) const;
304  bool operator!=( const QgsNumericFormat &other ) const;
305 
306 };
307 
308 #endif // QGSNUMERICFORMAT_H
QChar thousandsSeparator() const
Returns the thousands separator character.
The class is used as a container of context for various read/write operations on other objects...
void setZeroDigit(const QChar &character)
Returns the zero digit character.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
void setPercent(const QChar &character)
Sets the percent character.
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
QChar negativeSign() const
Returns the negative sign character.
QChar positiveSign() const
Returns the positive sign character.
QChar percent() const
Returns the percent character.
QChar exponential() const
Returns the exponential character.
#define SIP_END
Definition: qgis_sip.h:189
void setDecimalSeparator(const QChar &separator)
Returns the decimal separator character.
#define SIP_FACTORY
Definition: qgis_sip.h:76
void setPositiveSign(const QChar &character)
Sets the positive sign character.
QChar zeroDigit() const
Returns the zero digit character.
QChar decimalSeparator() const
Returns the decimal separator character.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
A context for numeric formats.
void setNegativeSign(const QChar &character)
Sets the negative sign character.
void setThousandsSeparator(const QChar &separator)
Sets the thousands separator character.
void setExponential(const QChar &character)
Sets the exponential character.