Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

bitcoinunits.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Copyright (c) 2014-2019 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;
114  QVariant data(const int &row, int role) const;
116 
117  static QString removeSpaces(QString text)
118  {
119  text.remove(' ');
120  text.remove(QChar(THIN_SP_CP));
121 #if (THIN_SP_CP != REAL_THIN_SP_CP)
122  text.remove(QChar(REAL_THIN_SP_CP));
123 #endif
124  return text;
125  }
126 
128  static CAmount maxMoney();
129 
130 private:
131  QList<BitcoinUnits::Unit> unitlist;
132 };
134 
135 #endif // BITCOIN_QT_BITCOINUNITS_H
QList< BitcoinUnits::Unit > unitlist
Definition: bitcoinunits.h:131
Unit
Dash units.
Definition: bitcoinunits.h:58
Dash unit definitions.
Definition: bitcoinunits.h:48
BitcoinUnits::Unit BitcoinUnit
Definition: bitcoinunits.h:133
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)
static bool valid(int unit)
Is unit ID valid?
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */...
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
BitcoinUnits(QObject *parent)
static QString description(int unit)
Longer description.
int rowCount(const QModelIndex &parent) const
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
Unit identifier.
Definition: bitcoinunits.h:110
#define REAL_THIN_SP_CP
Definition: bitcoinunits.h:15
static QString name(int unit)
Short name.
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
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.
QVariant data(const QModelIndex &index, int role) const
static QString removeSpaces(QString text)
Definition: bitcoinunits.h:117
static QString floorHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
#define THIN_SP_CP
Definition: bitcoinunits.h:41
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
static int decimals(int unit)
Number of decimals left.
static QString simpleFormat(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Released under the MIT license