6 #include <QAbstractListModel>
8 /** Bitcoin unit definitions. Encapsulates parsing and formatting
9 and serves as list model for dropdown selection boxes.
11 class BitcoinUnits: public QAbstractListModel
14 explicit BitcoinUnits(QObject *parent);
17 @note Source: https://en.bitcoin.it/wiki/Units . Please add only sensible ones
27 //! Unit conversion and formatting
30 //! Get list of units, for dropdown box
31 static QList<Unit> availableUnits();
33 static bool valid(int unit);
35 static QString name(int unit);
36 //! Longer description
37 static QString description(int unit);
38 //! Number of Satoshis (1e-8) per unit
39 static qint64 factor(int unit);
40 //! Number of amount digits (to represent max number of coins)
41 static int amountDigits(int unit);
42 //! Number of decimals left
43 static int decimals(int unit);
45 static QString format(int unit, qint64 amount, bool plussign=false);
46 //! Format as string (with unit)
47 static QString formatWithUnit(int unit, qint64 amount, bool plussign=false);
48 //! Parse string to coin amount
49 static bool parse(int unit, const QString &value, qint64 *val_out);
52 //! @name AbstractListModel implementation
53 //! List model for unit dropdown selection box.
56 /** Unit identifier */
57 UnitRole = Qt::UserRole
59 int rowCount(const QModelIndex &parent) const;
60 QVariant data(const QModelIndex &index, int role) const;
63 QList<BitcoinUnits::Unit> unitlist;
65 typedef BitcoinUnits::Unit BitcoinUnit;
67 #endif // BITCOINUNITS_H