11 unitlist(availableUnits())
19 unitlist.append(
mBTC);
20 unitlist.append(
uBTC);
41 case BTC:
return QString(
"BTC");
42 case mBTC:
return QString(
"mBTC");
43 case uBTC:
return QString::fromUtf8(
"μBTC");
44 default:
return QString(
"???");
52 case BTC:
return QString(
"Bitcoins");
53 case mBTC:
return QString(
"Milli-Bitcoins (1 / 1,000)");
54 case uBTC:
return QString(
"Micro-Bitcoins (1 / 1,000,000)");
55 default:
return QString(
"???");
63 case BTC:
return 100000000;
64 case mBTC:
return 100000;
65 case uBTC:
return 100;
66 default:
return 100000000;
74 case BTC:
return Q_INT64_C(21000000);
75 case mBTC:
return Q_INT64_C(21000000000);
76 case uBTC:
return Q_INT64_C(21000000000000);
109 qint64 coin =
factor(unit);
111 qint64 n_abs = (n > 0 ? n : -n);
112 qint64 quotient = n_abs / coin;
113 qint64 remainder = n_abs % coin;
114 QString quotient_str = QString::number(quotient);
115 QString remainder_str = QString::number(remainder).rightJustified(num_decimals,
'0');
119 for (
int i = remainder_str.size()-1; i>=2 && (remainder_str.at(i) ==
'0'); --i)
121 remainder_str.chop(nTrim);
124 quotient_str.insert(0,
'-');
125 else if (fPlus && n > 0)
126 quotient_str.insert(0,
'+');
127 return quotient_str + QString(
".") + remainder_str;
132 return format(unit, amount, plussign) + QString(
" ") +
name(unit);
137 if(!
valid(unit) || value.isEmpty())
140 QStringList parts = value.split(
".");
146 QString whole = parts[0];
153 if(decimals.size() > num_decimals)
158 QString str = whole + decimals.leftJustified(num_decimals,
'0');
164 qint64 retvalue = str.toLongLong(&ok);
180 int row = index.row();
181 if(row >= 0 && row <
unitlist.size())
187 case Qt::DisplayRole:
188 return QVariant(
name(unit));
189 case Qt::ToolTipRole:
192 return QVariant(static_cast<int>(unit));
static qint64 maxAmount(int unit)
Max amount per unit.
QList< BitcoinUnits::Unit > unitlist
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false)
Format as string (with unit)
QVariant data(const QModelIndex &index, int role) const
int rowCount(const QModelIndex &parent) const
static bool valid(int unit)
Is unit ID valid?
BitcoinUnits(QObject *parent)
static QString description(int unit)
Longer description.
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
static QString name(int unit)
Short name.
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
static int amountDigits(int unit)
Number of amount digits (to represent max number of coins)
static bool parse(int unit, const QString &value, qint64 *val_out)
Parse string to coin amount.
static QString format(int unit, qint64 amount, bool plussign=false)
Format as string.
static int decimals(int unit)
Number of decimals left.