mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
qt: Add BitcoinUnits::formatWithPrivacy() function
This commit is contained in:
parent
978c5a2122
commit
73d8ef7274
2 changed files with 18 additions and 2 deletions
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <QStringList>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
BitcoinUnits::BitcoinUnits(QObject *parent):
|
||||
QAbstractListModel(parent),
|
||||
unitlist(availableUnits())
|
||||
|
@ -94,7 +96,7 @@ int BitcoinUnits::decimals(int unit)
|
|||
}
|
||||
}
|
||||
|
||||
QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators)
|
||||
QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators, bool justify)
|
||||
{
|
||||
// Note: not using straight sprintf here because we do NOT want
|
||||
// localized number formatting.
|
||||
|
@ -106,6 +108,7 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
|
|||
qint64 n_abs = (n > 0 ? n : -n);
|
||||
qint64 quotient = n_abs / coin;
|
||||
QString quotient_str = QString::number(quotient);
|
||||
if (justify) quotient_str = quotient_str.rightJustified(16 - num_decimals, ' ');
|
||||
|
||||
// Use SI-style thin space separators as these are locale independent and can't be
|
||||
// confused with the decimal marker.
|
||||
|
@ -150,6 +153,17 @@ QString BitcoinUnits::formatHtmlWithUnit(int unit, const CAmount& amount, bool p
|
|||
return QString("<span style='white-space: nowrap;'>%1</span>").arg(str);
|
||||
}
|
||||
|
||||
QString BitcoinUnits::formatWithPrivacy(int unit, const CAmount& amount, SeparatorStyle separators, bool privacy)
|
||||
{
|
||||
assert(amount >= 0);
|
||||
QString value;
|
||||
if (privacy) {
|
||||
value = format(unit, 0, false, separators, true).replace('0', '#');
|
||||
} else {
|
||||
value = format(unit, amount, false, separators, true);
|
||||
}
|
||||
return value + QString(" ") + shortName(unit);
|
||||
}
|
||||
|
||||
bool BitcoinUnits::parse(int unit, const QString &value, CAmount *val_out)
|
||||
{
|
||||
|
|
|
@ -72,11 +72,13 @@ public:
|
|||
//! Number of decimals left
|
||||
static int decimals(int unit);
|
||||
//! Format as string
|
||||
static QString format(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
|
||||
static QString format(int unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = separatorStandard, bool justify = false);
|
||||
//! Format as string (with unit)
|
||||
static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
|
||||
//! Format as HTML string (with unit)
|
||||
static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
|
||||
//! Format as string (with unit) of fixed length to preserve privacy, if it is set.
|
||||
static QString formatWithPrivacy(int unit, const CAmount& amount, SeparatorStyle separators, bool privacy);
|
||||
//! Parse string to coin amount
|
||||
static bool parse(int unit, const QString &value, CAmount *val_out);
|
||||
//! Gets title for amount column including current display unit if optionsModel reference available */
|
||||
|
|
Loading…
Add table
Reference in a new issue