|
|
@ -4,51 +4,60 @@ |
|
|
|
#include <QString> |
|
|
|
#include <QString> |
|
|
|
#include <QAbstractListModel> |
|
|
|
#include <QAbstractListModel> |
|
|
|
|
|
|
|
|
|
|
|
// Bitcoin unit definitions, encapsulates parsing and formatting
|
|
|
|
/** Bitcoin unit definitions. Encapsulates parsing and formatting
|
|
|
|
// and serves as list model for dropdown selection boxes.
|
|
|
|
and serves as list model for dropdown selection boxes. |
|
|
|
|
|
|
|
*/ |
|
|
|
class BitcoinUnits: public QAbstractListModel |
|
|
|
class BitcoinUnits: public QAbstractListModel |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit BitcoinUnits(QObject *parent); |
|
|
|
explicit BitcoinUnits(QObject *parent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Bitcoin units.
|
|
|
|
|
|
|
|
@note Source: https://en.bitcoin.it/wiki/Units . Please add only sensible ones
|
|
|
|
|
|
|
|
*/ |
|
|
|
enum Unit |
|
|
|
enum Unit |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Source: https://en.bitcoin.it/wiki/Units
|
|
|
|
|
|
|
|
// Please add only sensible ones
|
|
|
|
|
|
|
|
BTC, |
|
|
|
BTC, |
|
|
|
mBTC, |
|
|
|
mBTC, |
|
|
|
uBTC |
|
|
|
uBTC |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/// Static API
|
|
|
|
//! @name Static API
|
|
|
|
// Get list of units, for dropdown box
|
|
|
|
//! Unit conversion and formatting
|
|
|
|
|
|
|
|
///@{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! Get list of units, for dropdown box
|
|
|
|
static QList<Unit> availableUnits(); |
|
|
|
static QList<Unit> availableUnits(); |
|
|
|
// Is unit ID valid?
|
|
|
|
//! Is unit ID valid?
|
|
|
|
static bool valid(int unit); |
|
|
|
static bool valid(int unit); |
|
|
|
// Short name
|
|
|
|
//! Short name
|
|
|
|
static QString name(int unit); |
|
|
|
static QString name(int unit); |
|
|
|
// Longer description
|
|
|
|
//! Longer description
|
|
|
|
static QString description(int unit); |
|
|
|
static QString description(int unit); |
|
|
|
// Number of satoshis / unit
|
|
|
|
//! Number of Satoshis (1e-8) per unit
|
|
|
|
static qint64 factor(int unit); |
|
|
|
static qint64 factor(int unit); |
|
|
|
// Number of amount digits (to represent max number of coins)
|
|
|
|
//! Number of amount digits (to represent max number of coins)
|
|
|
|
static int amountDigits(int unit); |
|
|
|
static int amountDigits(int unit); |
|
|
|
// Number of decimals left
|
|
|
|
//! Number of decimals left
|
|
|
|
static int decimals(int unit); |
|
|
|
static int decimals(int unit); |
|
|
|
// Format as string
|
|
|
|
//! Format as string
|
|
|
|
static QString format(int unit, qint64 amount, bool plussign=false); |
|
|
|
static QString format(int unit, qint64 amount, bool plussign=false); |
|
|
|
// Format as string (with unit)
|
|
|
|
//! Format as string (with unit)
|
|
|
|
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false); |
|
|
|
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false); |
|
|
|
// Parse string to coin amount
|
|
|
|
//! Parse string to coin amount
|
|
|
|
static bool parse(int unit, const QString &value, qint64 *val_out); |
|
|
|
static bool parse(int unit, const QString &value, qint64 *val_out); |
|
|
|
|
|
|
|
///@}
|
|
|
|
|
|
|
|
|
|
|
|
/// AbstractListModel implementation
|
|
|
|
//! @name AbstractListModel implementation
|
|
|
|
enum { |
|
|
|
//! List model for unit dropdown selection box.
|
|
|
|
// Unit identifier
|
|
|
|
///@{
|
|
|
|
|
|
|
|
enum RoleIndex { |
|
|
|
|
|
|
|
/** Unit identifier */ |
|
|
|
UnitRole = Qt::UserRole |
|
|
|
UnitRole = Qt::UserRole |
|
|
|
} RoleIndex; |
|
|
|
}; |
|
|
|
int rowCount(const QModelIndex &parent) const; |
|
|
|
int rowCount(const QModelIndex &parent) const; |
|
|
|
QVariant data(const QModelIndex &index, int role) const; |
|
|
|
QVariant data(const QModelIndex &index, int role) const; |
|
|
|
|
|
|
|
///@}
|
|
|
|
private: |
|
|
|
private: |
|
|
|
QList<BitcoinUnits::Unit> unitlist; |
|
|
|
QList<BitcoinUnits::Unit> unitlist; |
|
|
|
}; |
|
|
|
}; |
|
|
|