5ac3d47a3f0d0c3ce91a0e38576740924257c41a
[novacoin.git] / src / qt / bitcoinunits.h
1 #ifndef BITCOINUNITS_H
2 #define BITCOINUNITS_H
3
4 #include <QString>
5 #include <QAbstractListModel>
6
7 /** Bitcoin unit definitions. Encapsulates parsing and formatting
8    and serves as list model for drop-down selection boxes.
9 */
10 class BitcoinUnits: public QAbstractListModel
11 {
12 public:
13     explicit BitcoinUnits(QObject *parent);
14
15     /** Bitcoin units.
16       @note Source: https://en.bitcoin.it/wiki/Units . Please add only sensible ones
17      */
18     enum Unit
19     {
20         BTC,
21         mBTC,
22         uBTC
23     };
24
25     //! @name Static API
26     //! Unit conversion and formatting
27     ///@{
28
29     //! Get list of units, for drop-down box
30     static QList<Unit> availableUnits();
31     //! Is unit ID valid?
32     static bool valid(int unit);
33     //! Short name
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);
43     //! Format as string
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);
49     //! Gets title for amount column including current display unit if optionsModel reference available */
50     static QString getAmountColumnTitle(int unit);
51     ///@}
52
53     //! @name AbstractListModel implementation
54     //! List model for unit drop-down selection box.
55     ///@{
56     enum RoleIndex {
57         /** Unit identifier */
58         UnitRole = Qt::UserRole
59     };
60     int rowCount(const QModelIndex &parent) const;
61     QVariant data(const QModelIndex &index, int role) const;
62     ///@}
63 private:
64     QList<BitcoinUnits::Unit> unitlist;
65 };
66 typedef BitcoinUnits::Unit BitcoinUnit;
67
68 #endif // BITCOINUNITS_H