6
6
7
7
#include < QStringList>
8
8
9
+ #include < cassert>
10
+
9
11
BitcoinUnits::BitcoinUnits (QObject *parent):
10
12
QAbstractListModel(parent),
11
13
unitlist(availableUnits())
@@ -94,7 +96,7 @@ int BitcoinUnits::decimals(int unit)
94
96
}
95
97
}
96
98
97
- QString BitcoinUnits::format (int unit, const CAmount& nIn, bool fPlus , SeparatorStyle separators)
99
+ QString BitcoinUnits::format (int unit, const CAmount& nIn, bool fPlus , SeparatorStyle separators, bool justify )
98
100
{
99
101
// Note: not using straight sprintf here because we do NOT want
100
102
// localized number formatting.
@@ -106,6 +108,7 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
106
108
qint64 n_abs = (n > 0 ? n : -n);
107
109
qint64 quotient = n_abs / coin;
108
110
QString quotient_str = QString::number (quotient);
111
+ if (justify) quotient_str = quotient_str.rightJustified (16 - num_decimals, ' ' );
109
112
110
113
// Use SI-style thin space separators as these are locale independent and can't be
111
114
// confused with the decimal marker.
@@ -150,6 +153,17 @@ QString BitcoinUnits::formatHtmlWithUnit(int unit, const CAmount& amount, bool p
150
153
return QString (" <span style='white-space: nowrap;'>%1</span>" ).arg (str);
151
154
}
152
155
156
+ QString BitcoinUnits::formatWithPrivacy (int unit, const CAmount& amount, SeparatorStyle separators, bool privacy)
157
+ {
158
+ assert (amount >= 0 );
159
+ QString value;
160
+ if (privacy) {
161
+ value = format (unit, 0 , false , separators, true ).replace (' 0' , ' #' );
162
+ } else {
163
+ value = format (unit, amount, false , separators, true );
164
+ }
165
+ return value + QString (" " ) + shortName (unit);
166
+ }
153
167
154
168
bool BitcoinUnits::parse (int unit, const QString &value, CAmount *val_out)
155
169
{
0 commit comments