/
qgsbasicnumericformat.h
133 lines (113 loc) · 4.06 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
/***************************************************************************
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:
/**
* Default constructor
*/
QgsBasicNumericFormat();
//! QgsBasicNumericFormat cannot be copied
QgsBasicNumericFormat( const QgsBasicNumericFormat & ) = delete;
//! QgsBasicNumericFormat cannot be copied
QgsBasicNumericFormat &operator=( const QgsBasicNumericFormat & ) = delete;
QString id() const override;
QString formatDouble( double value, const QgsNumericFormatContext &context ) const override;
QgsNumericFormat *clone() const override SIP_FACTORY;
QgsNumericFormat *create( const QVariantMap &configuration ) const override SIP_FACTORY;
QVariantMap configuration() const override;
/**
* Sets the format's \a configuration.
*/
void setConfiguration( const QVariantMap &configuration );
/**
* Returns the maximum number of decimal places to show.
*
* \see setNumberDecimalPlaces()
* \see showTrailingZeros()
*/
int numberDecimalPlaces() const;
/**
* Sets the maximum number of decimal places to show.
*
* \see numberDecimalPlaces()
* \see setShowTrailingZeros()
*/
void setNumberDecimalPlaces( int numberDecimalPlaces );
/**
* 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 showThousandsSeparator );
/**
* 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 showPlusSign );
/**
* 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 showTrailingZeros );
protected:
bool mUseScientific = false;
private:
#ifdef SIP_RUN
QgsBasicNumericFormat( const QgsBasicNumericFormat &other );
#endif
int mNumberDecimalPlaces = 6;
bool mShowThousandsSeparator = true;
bool mShowPlusSign = false;
bool mShowTrailingZeros = false;
mutable QChar mPrevThousandsSep;
mutable QChar mPrevDecimalSep;
mutable std::unique_ptr< std::ostringstream > mOs;
};
#endif // QGSBASICNUMERICFORMAT_H