QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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
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 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 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.
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.
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
virtual QString formatDouble(double value, const QgsNumericFormatContext &context) const =0
Returns a formatted string representation of a numeric double value.
virtual QgsNumericFormat * create(const QVariantMap &configuration, const QgsReadWriteContext &context) const =0
Creates a new copy of the format, using the supplied configuration.
QgsNumericFormat()=default
Default constructor.
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 * clone() const =0
Clones the format, returning a new object.
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:177
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:194
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)