/
qgsbasicnumericformat.h
166 lines (141 loc) · 4.97 KB
/
qgsbasicnumericformat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/***************************************************************************
qgsbasicnumericformat.h
--------------------------
begin : January 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSBASICNUMERICFORMAT_H
#define QGSBASICNUMERICFORMAT_H
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgsnumericformat.h"
#include <sstream>
#include <iostream>
#include <memory>
/**
* \ingroup core
* A numeric formatter which returns a simple text representation of a value.
*
* \since QGIS 3.12
*/
class CORE_EXPORT QgsBasicNumericFormat : public QgsNumericFormat
{
public:
/**
* Sets rounding type and behavior of the numberDecimalPlaces() setting.
*/
enum RoundingType
{
DecimalPlaces, //!< Maximum number of decimal places
SignificantFigures, //!< Maximum number of significant figures
};
/**
* Default constructor
*/
QgsBasicNumericFormat();
QString id() const override;
QString visibleName() const override;
int sortKey() override;
QString formatDouble( double value, const QgsNumericFormatContext &context ) const override;
QgsNumericFormat *clone() const override SIP_FACTORY;
QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const override SIP_FACTORY;
QVariantMap configuration( const QgsReadWriteContext &context ) const override;
/**
* Returns the maximum number of decimal places to show.
*
* \see setNumberDecimalPlaces()
* \see showTrailingZeros()
*/
int numberDecimalPlaces() const;
/**
* Sets the maximum number of decimal \a places to show.
*
* \see numberDecimalPlaces()
* \see setShowTrailingZeros()
*/
virtual void setNumberDecimalPlaces( int places );
/**
* Returns TRUE if the thousands grouping separator will be shown.
* \see setShowThousandsSeparator()
*/
bool showThousandsSeparator() const;
/**
* Sets whether the thousands grouping separator will be shown.
* \see showThousandsSeparator()
*/
void setShowThousandsSeparator( bool show );
/**
* Returns TRUE if a leading plus sign will be shown for positive values.
* \see setShowPlusSign()
*/
bool showPlusSign() const;
/**
* Sets whether a leading plus sign will be shown for positive values.
* \see showPlusSign()
*/
void setShowPlusSign( bool show );
/**
* Returns TRUE if trailing zeros will be shown (up to the specified
* numberDecimalPlaces()).
*
* \see setShowTrailingZeros()
* \see numberDecimalPlaces()
*/
bool showTrailingZeros() const;
/**
* Sets whether trailing zeros will be shown (up to the specified
* numberDecimalPlaces()).
*
* \see showTrailingZeros()
* \see setNumberDecimalPlaces()
*/
void setShowTrailingZeros( bool show );
/**
* Returns the rounding type, which controls the behavior of the numberDecimalPlaces() setting.
*
* \see setRoundingType()
*/
RoundingType roundingType() const;
/**
* Sets the rounding \a type, which controls the behavior of the numberDecimalPlaces() setting.
*
* \see roundingType()
*/
void setRoundingType( RoundingType type );
/**
* Returns any override for the thousands separator character. If an invalid QChar is returned,
* then the QGIS locale separator is used instead.
*
* \see setThousandsSeparator()
*/
QChar thousandsSeparator() const;
/**
* Sets an override \a character for the thousands separator character. If an invalid QChar is set,
* then the QGIS locale separator is used instead.
*
* \see thousandsSeparator()
*/
void setThousandsSeparator( QChar character );
protected:
/**
* Sets the format's \a configuration.
*/
virtual void setConfiguration( const QVariantMap &configuration, const QgsReadWriteContext &context );
bool mUseScientific = false;
private:
int mNumberDecimalPlaces = 6;
bool mShowThousandsSeparator = true;
bool mShowPlusSign = false;
bool mShowTrailingZeros = false;
RoundingType mRoundingType = DecimalPlaces;
QChar mThousandsSeparator;
};
#endif // QGSBASICNUMERICFORMAT_H