12 QAbstractListModel(parent),
13 unitlist(availableUnits())
21 unitlist.append(
mFAB);
22 unitlist.append(
uFAB);
43 case FAB:
return QString(
"FAB");
44 case mFAB:
return QString(
"mFAB");
45 case uFAB:
return QString::fromUtf8(
"μFAB");
46 default:
return QString(
"???");
54 case FAB:
return QString(
"Fabcoins");
57 default:
return QString(
"???");
65 case FAB:
return 100000000;
66 case mFAB:
return 100000;
67 case uFAB:
return 100;
68 default:
return 100000000;
77 for(
int i = 0; i < decimalUnits; i++){
99 qint64 n = (qint64)nIn;
100 qint64 coin =
factor(unit);
102 qint64 n_abs = (n > 0 ? n : -n);
103 qint64 quotient = n_abs / coin;
104 qint64 remainder = n_abs % coin;
105 QString quotient_str = QString::number(quotient);
106 QString remainder_str = QString::number(remainder).rightJustified(num_decimals,
'0');
111 int q_size = quotient_str.size();
113 for (
int i = 3; i < q_size; i += 3)
114 quotient_str.insert(q_size - i, thin_sp);
117 quotient_str.insert(0,
'-');
118 else if (fPlus && n > 0)
119 quotient_str.insert(0,
'+');
120 return quotient_str + QString(
".") + remainder_str;
134 return format(unit, amount, plussign, separators) + QString(
" ") +
name(unit);
141 return QString(
"<span style='white-space: nowrap;'>%1</span>").arg(str);
147 if(!
valid(unit) || value.isEmpty())
158 QString whole = parts[0];
165 if(decimals.size() > num_decimals)
170 QString str = whole + decimals.leftJustified(num_decimals,
'0');
176 CAmount retvalue(str.toLongLong(&ok));
196 QString whole = parts[0];
203 if(decimals.size() > decimal_units)
208 QString str = whole + decimals.leftJustified(decimal_units,
'0');
211 while (str.startsWith(
'0'))
224 retvalue = int256_t(str.toStdString());
242 int256_t n_abs = (n > 0 ? n : -n);
245 QString quotient_str;
246 QString remainder_str;
250 quotient = n_abs / coin;
251 remainder = n_abs % coin;
252 remainder_str = QString::fromStdString(remainder.str()).rightJustified(decimal_units,
'0');
258 quotient_str = QString::fromStdString(quotient.str());
263 int q_size = quotient_str.size();
265 for (
int i = 3; i < q_size; i += 3)
266 quotient_str.insert(q_size - i, thin_sp);
269 quotient_str.insert(0,
'-');
270 else if (fPlus && n > 0)
271 quotient_str.insert(0,
'+');
272 if(remainder_str.size())
274 return quotient_str + QString(
".") + remainder_str;
281 return formatToken(decimals, amount, plussign, separators) +
" " + unit;
286 QString amountTitle = QObject::tr(
"Amount");
302 int row = index.row();
303 if(row >= 0 && row <
unitlist.size())
309 case Qt::DisplayRole:
310 return QVariant(
name(unit));
311 case Qt::ToolTipRole:
314 return QVariant(static_cast<int>(unit));
static QString formatTokenWithUnit(const QString unit, int decimals, const int256_t &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format token as string.
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
static int decimals(int unit)
Number of decimals left.
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
int64_t CAmount
Amount in lius (Can be negative)
FabcoinUnits(QObject *parent)
static bool valid(int unit)
Is unit ID valid?
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
QVariant data(const QModelIndex &index, int role) const
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
static QString formatToken(int decimal_units, const int256_t &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format token as string.
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
static int256_t tokenFactor(int unit)
Token factor from decimals.
QList< FabcoinUnits::Unit > unitlist
int rowCount(const QModelIndex &parent) const
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */...
static QString name(int unit)
Short name.
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
static QString removeSpaces(QString text)
static bool parseToken(int decimal_units, const QString &value, int256_t *val_out)
Parse string to token amount.
static QString description(int unit)
Longer description.
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)