-
Notifications
You must be signed in to change notification settings - Fork 0
/
numeral.h
75 lines (68 loc) · 2.3 KB
/
numeral.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
#ifndef NUMERAL_H
#define NUMERAL_H
#include <QString>
#include <QLocale>
class NumeralFormat
{
public:
NumeralFormat();
NumeralFormat(const QString &st);
NumeralFormat(bool sign, bool thousandSeparate, int precision, bool extraPrecision, bool percent);
bool operator == (const NumeralFormat &another);
bool operator != (const NumeralFormat &another);
void clear();
void setFormatString(const QString &st);
QString formatString() const;
void setSign(bool value);
bool sign() const;
void setThousandSeparate(bool value);
bool thousandSeparate() const;
void setPrecision(int value);
int precision() const;
void setExtraPrecision(bool value);
bool extraPrecision() const;
void setPercent(bool value);
bool percent() const;
private:
bool m_sign;
bool m_thousandSeparate;
int m_precision;
bool m_extraPrecision;
bool m_percent;
void parse(const QStringRef &st);
void parseIntegerPart(const QStringRef &st);
void parseFractionalPart(const QStringRef &st);
};
class Numeral
{
public:
Numeral();
Numeral(const NumeralFormat &numberFormat);
Numeral(const NumeralFormat &numberFormat, const QLocale &locale);
void setNumberFormat(const NumeralFormat &value);
NumeralFormat numberFormat() const;
void setlocale(const QLocale &value);
QLocale locale() const;
void setNanStub(const QString &value);
QString nanStub() const;
static void setDefaultLocale(const QLocale &value);
static QLocale defaultLocale();
static void setDefaultNanStub(const QString &value);
static QString defaultNanStub();
QString toString(double number) const;
static QString format(double number, const NumeralFormat &numberFormat = NumeralFormat());
private:
NumeralFormat m_numberFormat;
QLocale m_locale;
QString m_nanStub;
static QLocale *m_defaultLocale;
static QString *m_defaultNanStub;
public:
QString decorateSign(const QString &formattedNumber, double number) const;
QString decorateThousandSeparator(const QString &formattedNumber) const;
QString decorateTrimmingZeros(const QString &formattedNumber) const;
QString initialFormat(double positiveNumber) const;
static void createDefaultLocaleIfNeeded();
static void createDefaultNanStubIfNeeded();
};
#endif // NUMERAL_H