Revert "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 <QString>
5 #include <QAbstractListModel>
6
7 /** Bitcoin unit definitions. Encapsulates parsing and formatting
8    and serves as list model for dropdown 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 dropdown 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     ///@}
50
51     //! @name AbstractListModel implementation
52     //! List model for unit dropdown selection box.
53     ///@{
54     enum RoleIndex {
55         /** Unit identifier */
56         UnitRole = Qt::UserRole
57     };
58     int rowCount(const QModelIndex &parent) const;
59     QVariant data(const QModelIndex &index, int role) const;
60     ///@}
61 private:
62     QList<BitcoinUnits::Unit> unitlist;
63 };
64 typedef BitcoinUnits::Unit BitcoinUnit;
65
66 #endif // BITCOINUNITS_H