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