5 #include <QAbstractListModel>
7 /** Bitcoin unit definitions. Encapsulates parsing and formatting
8 and serves as list model for drop-down selection boxes.
10 class BitcoinUnits: public QAbstractListModel
13 explicit BitcoinUnits(QObject *parent);
16 @note Source: https://en.bitcoin.it/wiki/Units . Please add only sensible ones
26 //! Unit conversion and formatting
29 //! Get list of units, for drop-down box
30 static QList<Unit> availableUnits();
32 static bool valid(int unit);
34 static QString name(int unit);
35 //! Longer description
36 static QString description(int unit);
37 //! Number of Satoshis (1e-8) per unit
38 static qint64 factor(int unit);
39 //! Number of amount digits (to represent max number of coins)
40 static int amountDigits(int unit);
41 //! Number of decimals left
42 static int decimals(int unit);
44 static QString format(int unit, qint64 amount, bool plussign=false);
45 //! Format as string (with unit)
46 static QString formatWithUnit(int unit, qint64 amount, bool plussign=false);
47 //! Parse string to coin amount
48 static bool parse(int unit, const QString &value, qint64 *val_out);
51 //! @name AbstractListModel implementation
52 //! List model for unit drop-down selection box.
55 /** Unit identifier */
56 UnitRole = Qt::UserRole
58 int rowCount(const QModelIndex &parent) const;
59 QVariant data(const QModelIndex &index, int role) const;
62 QList<BitcoinUnits::Unit> unitlist;
64 typedef BitcoinUnits::Unit BitcoinUnit;
66 #endif // BITCOINUNITS_H