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