QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 if ( dynamic_cast< QgsFractionNumericFormat * >( sipCpp ) )
235  sipType = sipType_QgsFractionNumericFormat;
236  else
237  sipType = NULL;
238  SIP_END
239 #endif
240 
241  public:
242 
246  QgsNumericFormat() = default;
247 
248  virtual ~QgsNumericFormat() = default;
249 
255  virtual QString id() const = 0;
256 
260  virtual QString visibleName() const = 0;
261 
267  virtual int sortKey();
268 
272  virtual double suggestSampleValue() const;
273 
277  virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const = 0;
278 
284  virtual QgsNumericFormat *clone() const = 0 SIP_FACTORY;
285 
291  virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const = 0 SIP_FACTORY;
292 
297  virtual QVariantMap configuration( const QgsReadWriteContext &context ) const = 0;
298 
303  void writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
304 
305  bool operator==( const QgsNumericFormat &other ) const;
306  bool operator!=( const QgsNumericFormat &other ) const;
307 
308 };
309 
310 #endif // QGSNUMERICFORMAT_H
qgsfallbacknumericformat.h
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:399
QgsFallbackNumericFormat
Definition: qgsfallbacknumericformat.h:28
QgsNumericFormatContext::setPercent
void setPercent(const QChar &character)
Sets the percent character.
Definition: qgsnumericformat.h:101
QgsNumericFormat
Definition: qgsnumericformat.h:217
qgscurrencynumericformat.h
QgsNumericFormatContext::negativeSign
QChar negativeSign() const
Returns the negative sign character.
Definition: qgsnumericformat.h:131
QgsBasicNumericFormat
Definition: qgsbasicnumericformat.h:31
QgsNumericFormatContext::exponential
QChar exponential() const
Returns the exponential character.
Definition: qgsnumericformat.h:171
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:404
qgsbearingnumericformat.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsPercentageNumericFormat
Definition: qgspercentagenumericformat.h:28
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
QgsNumericFormatContext::positiveSign
QChar positiveSign() const
Returns the positive sign character.
Definition: qgsnumericformat.h:151
qgis_sip.h
QgsNumericFormatContext::percent
QChar percent() const
Returns the percent character.
Definition: qgsnumericformat.h:91
qgsscientificnumericformat.h
QgsNumericFormatContext::setDecimalSeparator
void setDecimalSeparator(const QChar &separator)
Returns the decimal separator character.
Definition: qgsnumericformat.h:81
QgsFractionNumericFormat
Definition: qgsfractionnumericformat.h:30
qgsbasicnumericformat.h
QgsScientificNumericFormat
Definition: qgsscientificnumericformat.h:28
QgsNumericFormatContext::setPositiveSign
void setPositiveSign(const QChar &character)
Sets the positive sign character.
Definition: qgsnumericformat.h:161
QgsCurrencyNumericFormat
Definition: qgscurrencynumericformat.h:28
QgsNumericFormatContext::setThousandsSeparator
void setThousandsSeparator(const QChar &separator)
Sets the thousands separator character.
Definition: qgsnumericformat.h:61
QgsNumericFormatContext::zeroDigit
QChar zeroDigit() const
Returns the zero digit character.
Definition: qgsnumericformat.h:111
QgsNumericFormatContext::setExponential
void setExponential(const QChar &character)
Sets the exponential character.
Definition: qgsnumericformat.h:181
QgsNumericFormatContext::setNegativeSign
void setNegativeSign(const QChar &character)
Sets the negative sign character.
Definition: qgsnumericformat.h:141
QgsBearingNumericFormat
Definition: qgsbearingnumericformat.h:28
qgspercentagenumericformat.h
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
QgsNumericFormatContext::decimalSeparator
QChar decimalSeparator() const
Returns the decimal separator character.
Definition: qgsnumericformat.h:71
QgsNumericFormatContext::setZeroDigit
void setZeroDigit(const QChar &character)
Returns the zero digit character.
Definition: qgsnumericformat.h:121
QgsNumericFormatContext
Definition: qgsnumericformat.h:34
QgsNumericFormatContext::thousandsSeparator
QChar thousandsSeparator() const
Returns the thousands separator character.
Definition: qgsnumericformat.h:51