Dash Core  0.12.2.1
P2P Digital Currency
bitcoinunits.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Copyright (c) 2014-2017 The Dash Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_QT_BITCOINUNITS_H
7 #define BITCOIN_QT_BITCOINUNITS_H
8 
9 #include "amount.h"
10 
11 #include <QAbstractListModel>
12 #include <QString>
13 
14 // U+2009 THIN SPACE = UTF-8 E2 80 89
15 #define REAL_THIN_SP_CP 0x2009
16 #define REAL_THIN_SP_UTF8 "\xE2\x80\x89"
17 #define REAL_THIN_SP_HTML "&thinsp;"
18 
19 // U+200A HAIR SPACE = UTF-8 E2 80 8A
20 #define HAIR_SP_CP 0x200A
21 #define HAIR_SP_UTF8 "\xE2\x80\x8A"
22 #define HAIR_SP_HTML "&#8202;"
23 
24 // U+2006 SIX-PER-EM SPACE = UTF-8 E2 80 86
25 #define SIXPEREM_SP_CP 0x2006
26 #define SIXPEREM_SP_UTF8 "\xE2\x80\x86"
27 #define SIXPEREM_SP_HTML "&#8198;"
28 
29 // U+2007 FIGURE SPACE = UTF-8 E2 80 87
30 #define FIGURE_SP_CP 0x2007
31 #define FIGURE_SP_UTF8 "\xE2\x80\x87"
32 #define FIGURE_SP_HTML "&#8199;"
33 
34 // QMessageBox seems to have a bug whereby it doesn't display thin/hair spaces
35 // correctly. Workaround is to display a space in a small font. If you
36 // change this, please test that it doesn't cause the parent span to start
37 // wrapping.
38 #define HTML_HACK_SP "<span style='white-space: nowrap; font-size: 6pt'> </span>"
39 
40 // Define THIN_SP_* variables to be our preferred type of thin space
41 #define THIN_SP_CP REAL_THIN_SP_CP
42 #define THIN_SP_UTF8 REAL_THIN_SP_UTF8
43 #define THIN_SP_HTML HTML_HACK_SP
44 
48 class BitcoinUnits: public QAbstractListModel
49 {
50  Q_OBJECT
51 
52 public:
53  explicit BitcoinUnits(QObject *parent);
54 
58  enum Unit
59  {
64  };
65 
67  {
71  };
72 
76 
78  static QList<Unit> availableUnits();
80  static bool valid(int unit);
82  static QString name(int unit);
84  static QString description(int unit);
86  static qint64 factor(int unit);
88  static int decimals(int unit);
90  static QString format(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
91  static QString simpleFormat(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
93  static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
95  static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
97  static QString floorWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
98  static QString floorHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
100  static bool parse(int unit, const QString &value, CAmount *val_out);
102  static QString getAmountColumnTitle(int unit);
104 
108  enum RoleIndex {
110  UnitRole = Qt::UserRole
111  };
112  int rowCount(const QModelIndex &parent) const;
113  QVariant data(const QModelIndex &index, int role) const;
115 
116  static QString removeSpaces(QString text)
117  {
118  text.remove(' ');
119  text.remove(QChar(THIN_SP_CP));
120 #if (THIN_SP_CP != REAL_THIN_SP_CP)
121  text.remove(QChar(REAL_THIN_SP_CP));
122 #endif
123  return text;
124  }
125 
127  static CAmount maxMoney();
128 
129 private:
130  QList<BitcoinUnits::Unit> unitlist;
131 };
133 
134 #endif // BITCOIN_QT_BITCOINUNITS_H
static QString floorWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit) but floor value up to "digits" settings.
BitcoinUnits::Unit BitcoinUnit
Definition: bitcoinunits.h:132
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */...
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
static bool valid(int unit)
Is unit ID valid?
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
static QString floorHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
int64_t CAmount
Definition: amount.h:14
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)
int rowCount(const QModelIndex &parent) const
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
#define REAL_THIN_SP_CP
Definition: bitcoinunits.h:15
static QString simpleFormat(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
QVariant data(const QModelIndex &index, int role) const
static int decimals(int unit)
Number of decimals left.
QList< BitcoinUnits::Unit > unitlist
Definition: bitcoinunits.h:130
BitcoinUnits(QObject *parent)
static QString name(int unit)
Short name.
static QString removeSpaces(QString text)
Definition: bitcoinunits.h:116
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
#define THIN_SP_CP
Definition: bitcoinunits.h:41
static QString description(int unit)
Longer description.