16 QAbstractListModel(parent),
17 unitlist(availableUnits())
36 case Unit::uBTC:
return QString::fromUtf8(
"µBTC (bits)");
37 case Unit::SAT:
return QString(
"Satoshi (sat)");
56 case Unit::BTC:
return QString(
"Bitcoins");
90 qint64 n = (qint64)nIn;
91 qint64 coin =
factor(unit);
93 qint64 n_abs = (n > 0 ? n : -n);
94 qint64 quotient = n_abs / coin;
95 QString quotient_str = QString::number(quotient);
97 quotient_str = quotient_str.rightJustified(
MAX_DIGITS_BTC - num_decimals,
' ');
103 int q_size = quotient_str.size();
105 for (
int i = 3; i < q_size; i += 3)
106 quotient_str.insert(q_size - i, thin_sp);
109 quotient_str.insert(0,
'-');
110 else if (fPlus && n > 0)
111 quotient_str.insert(0,
'+');
113 if (num_decimals > 0) {
114 qint64 remainder = n_abs % coin;
115 QString remainder_str = QString::number(remainder).rightJustified(num_decimals,
'0');
116 return quotient_str + QString(
".") + remainder_str;
133 return format(unit, amount, plussign, separators) + QString(
" ") +
shortName(unit);
140 return QString(
"<span style='white-space: nowrap;'>%1</span>").arg(str);
148 value =
format(unit, 0,
false, separators,
true).replace(
'0',
'#');
150 value =
format(unit, amount,
false, separators,
true);
152 return value + QString(
" ") +
shortName(unit);
157 if (value.isEmpty()) {
169 const QString& whole = parts[0];
181 QString str = whole +
decimals.leftJustified(num_decimals,
'0');
187 CAmount retvalue(str.toLongLong(&ok));
197 return QObject::tr(
"Amount") +
" (" +
shortName(unit) +
")";
208 int row = index.row();
209 if(row >= 0 && row <
unitlist.size())
215 case Qt::DisplayRole:
217 case Qt::ToolTipRole:
220 return QVariant::fromValue(unit);
257 return out << ToQint8(unit);
264 unit = FromQint8(input);
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
int64_t CAmount
Amount in satoshis (Can be negative)
QDataStream & operator<<(QDataStream &out, const BitcoinUnit &unit)
static constexpr auto MAX_DIGITS_BTC
QDataStream & operator>>(QDataStream &in, BitcoinUnit &unit)
@ UnitRole
Unit identifier.
int rowCount(const QModelIndex &parent) const override
static QString formatWithPrivacy(Unit unit, const CAmount &amount, SeparatorStyle separators, bool privacy)
Format as string (with unit) of fixed length to preserve privacy, if it is set.
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
static QString format(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
QVariant data(const QModelIndex &index, int role) const override
static QString formatHtmlWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
static QString removeSpaces(QString text)
static QString getAmountColumnTitle(Unit unit)
Gets title for amount column including current display unit if optionsModel reference available */.
static QString shortName(Unit unit)
Short name.
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
static QString longName(Unit unit)
Long name.
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
static qint64 factor(Unit unit)
Number of Satoshis (1e-8) per unit.
static bool parse(Unit unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
static QString description(Unit unit)
Longer description.
BitcoinUnits(QObject *parent)
static int decimals(Unit unit)
Number of decimals left.