QtUI code cleanup / comment improvements
[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 dropdown selection boxes.
9 class BitcoinUnits: public QAbstractListModel
10 {
11 public:
12     explicit BitcoinUnits(QObject *parent);
13
14     enum Unit
15     {
16         // Source: https://en.bitcoin.it/wiki/Units
17         // Please add only sensible ones
18         BTC,
19         mBTC,
20         uBTC
21     };
22
23     /// Static API
24     // Get list of units, for dropdown box
25     static QList<Unit> availableUnits();
26     // Is unit ID valid?
27     static bool valid(int unit);
28     // Short name
29     static QString name(int unit);
30     // Longer description
31     static QString description(int unit);
32     // Number of satoshis / unit
33     static qint64 factor(int unit);
34     // Number of amount digits (to represent max number of coins)
35     static int amountDigits(int unit);
36     // Number of decimals left
37     static int decimals(int unit);
38     // Format as string
39     static QString format(int unit, qint64 amount, bool plussign=false);
40     // Format as string (with unit)
41     static QString formatWithUnit(int unit, qint64 amount, bool plussign=false);
42     // Parse string to coin amount
43     static bool parse(int unit, const QString &value, qint64 *val_out);
44
45     /// AbstractListModel implementation
46     enum {
47         // Unit identifier
48         UnitRole = Qt::UserRole
49     } RoleIndex;
50     int rowCount(const QModelIndex &parent) const;
51     QVariant data(const QModelIndex &index, int role) const;
52 private:
53     QList<BitcoinUnits::Unit> unitlist;
54 };
55 typedef BitcoinUnits::Unit BitcoinUnit;
56
57 #endif // BITCOINUNITS_H