25 {BitcoinUnits::Unit::base,
28 {BitcoinUnits::Unit::sub,
30 "Satoshi (sat) (1 / 100)"}},
33 {BitcoinUnits::Unit::base,
36 {BitcoinUnits::Unit::sub,
47 : QAbstractListModel(parent), unitlist(availableUnits()) {}
69 return it != units.end() ? std::get<0>(it->second) :
"???";
74 return QString(
"sat");
82 return it != units.end() ? std::get<1>(it->second) :
"???";
89 return currency.baseunit;
91 return currency.subunit;
93 assert(
false &&
"non-existent BitcoinUnits::Unit");
104 assert(
false &&
"non-existent BitcoinUnits::Unit");
116 qint64 n = qint64(nIn /
SATOSHI);
119 qint64 n_abs = (n > 0 ? n : -n);
120 qint64 quotient = n_abs / coin;
121 QString quotient_str = QString::number(quotient);
123 quotient_str = quotient_str.rightJustified(16 - num_decimals,
' ');
129 int q_size = quotient_str.size();
132 for (
int i = 3; i < q_size; i += 3) {
133 quotient_str.insert(q_size - i, thin_sp);
138 quotient_str.insert(0,
'-');
139 }
else if (fPlus && n > 0) {
140 quotient_str.insert(0,
'+');
143 if (num_decimals > 0) {
144 qint64 remainder = n_abs % coin;
145 QString remainder_str =
146 QString::number(remainder).rightJustified(num_decimals,
'0');
147 return quotient_str + QString(
".") + remainder_str;
163 return format(unit, amount, plussign, separators) + QString(
" ") +
172 return QString(
"<span style='white-space: nowrap;'>%1</span>").arg(str);
184 value =
format(unit, amount,
false, separators,
true);
186 return value + QString(
" ") +
shortName(unit);
190 if (!
valid(unit) || value.isEmpty()) {
199 if (parts.size() > 2) {
203 QString whole = parts[0];
206 if (parts.size() > 1) {
209 if (
decimals.size() > num_decimals) {
214 QString str = whole +
decimals.leftJustified(num_decimals,
'0');
216 if (str.size() > 18) {
228 QString amountTitle = QObject::tr(
"Amount");
241 int row = index.row();
242 if (row >= 0 && row <
unitlist.size()) {
246 case Qt::DisplayRole:
248 case Qt::ToolTipRole:
251 return QVariant(
static_cast<int>(unit));
static constexpr Amount SATOSHI
static constexpr Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
static const unitNameMap xecUnits
static const unitNameMap bchUnits
std::map< BitcoinUnits::Unit, std::tuple< QString, QString > > unitNameMap
static const unitNameMap & getUnitsAtRuntime()
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
@ UnitRole
Unit identifier.
int rowCount(const QModelIndex &parent) const override
QList< BitcoinUnits::Unit > unitlist
static QString formatWithUnit(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
static int decimals(int unit)
Number of decimals left.
QVariant data(const QModelIndex &index, int role) const override
static Amount factor(int unit)
Number of Satoshis (1e-8) per unit.
static bool valid(int unit)
Is unit ID valid?
static QString formatWithPrivacy(int unit, const Amount &amount, SeparatorStyle separators, bool privacy)
Format as string (with unit) of fixed length to preserve privacy, if it is set.
static QString description(int unit)
Longer description.
static QString removeSpaces(QString text)
static QString longName(int unit)
Long name.
static Amount maxMoney()
Return maximum number of base units (Satoshis)
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
static QString format(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static bool parse(int unit, const QString &value, Amount *val_out)
Parse string to coin amount.
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */.
Unit
Currency units Please add only sensible ones.
BitcoinUnits(QObject *parent)
static QString shortName(int unit)
Short name.
static QString formatHtmlWithUnit(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
constexpr bool DEFAULT_ECASH
static constexpr Amount zero() noexcept
static const Currency & get()