Raven Core  3.0.0
P2P Digital Currency
ravenunits.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven 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 RAVEN_QT_RAVENUNITS_H
7 #define RAVEN_QT_RAVENUNITS_H
8 
9 #include "amount.h"
10 
11 #include <QAbstractListModel>
12 #include <QString>
13 
14 // Asset units
15 #define MAX_ASSET_UNITS 8
16 #define MIN_ASSET_UNITS 0
17 
18 
19 // U+2009 THIN SPACE = UTF-8 E2 80 89
20 #define REAL_THIN_SP_CP 0x2009
21 #define REAL_THIN_SP_UTF8 "\xE2\x80\x89"
22 #define REAL_THIN_SP_HTML "&thinsp;"
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 RavenUnits: public QAbstractListModel
54 {
55  Q_OBJECT
56 
57 public:
58  explicit RavenUnits(QObject *parent);
59 
63  enum Unit
64  {
65  RVN,
68  };
69 
71  {
75  };
76 
80 
82  static QList<Unit> availableUnits();
84  static bool valid(int unit);
86  static QString name(int unit);
88  static QString description(int unit);
90  static qint64 factor(int unit);
92  static qint64 factorAsset(int unit);
94  static int decimals(int unit);
96  static QString format(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard, const int nAssetUnit = MIN_ASSET_UNITS - 1);
98  static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
100  static QString formatWithCustomName(QString customName, const CAmount& amount, int unit = MAX_ASSET_UNITS, bool plussign=false, SeparatorStyle separators=separatorStandard);
102  static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
104  static bool parse(int unit, const QString &value, CAmount *val_out);
105  static bool assetParse(int assetUnit, const QString &value, CAmount *val_out);
107  static QString getAmountColumnTitle(int unit);
109 
113  enum RoleIndex {
115  UnitRole = Qt::UserRole
116  };
117  int rowCount(const QModelIndex &parent) const;
118  QVariant data(const QModelIndex &index, int role) const;
120 
121  static QString removeSpaces(QString text)
122  {
123  text.remove(' ');
124  text.remove(QChar(THIN_SP_CP));
125 #if (THIN_SP_CP != REAL_THIN_SP_CP)
126  text.remove(QChar(REAL_THIN_SP_CP));
127 #endif
128  return text;
129  }
130 
132  static CAmount maxMoney();
133 
134 private:
135  QList<RavenUnits::Unit> unitlist;
136 };
138 
139 #endif // RAVEN_QT_RAVENUNITS_H
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, const int nAssetUnit=MIN_ASSET_UNITS - 1)
Format as string.
Definition: ravenunits.cpp:101
static bool assetParse(int assetUnit, const QString &value, CAmount *val_out)
Definition: ravenunits.cpp:203
static bool valid(int unit)
Is unit ID valid?
Definition: ravenunits.cpp:27
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */...
Definition: ravenunits.cpp:242
QList< RavenUnits::Unit > unitlist
Definition: ravenunits.h:135
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
Definition: ravenunits.cpp:164
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
Definition: ravenunits.cpp:146
int rowCount(const QModelIndex &parent) const
Definition: ravenunits.cpp:252
static QString removeSpaces(QString text)
Definition: ravenunits.h:121
QVariant data(const QModelIndex &index, int role) const
Definition: ravenunits.cpp:258
RavenUnits(QObject *parent)
Definition: ravenunits.cpp:12
static qint64 factorAsset(int unit)
Number of Satoshis (1e-8) per unit for assets.
Definition: ravenunits.cpp:73
#define MIN_ASSET_UNITS
Definition: ravenunits.h:16
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)
Definition: ravenunits.cpp:156
#define REAL_THIN_SP_CP
Definition: ravenunits.h:20
#define THIN_SP_CP
Definition: ravenunits.h:46
Unit identifier.
Definition: ravenunits.h:115
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
Definition: ravenunits.cpp:18
static QString name(int unit)
Short name.
Definition: ravenunits.cpp:40
Unit
Raven units.
Definition: ravenunits.h:63
static QString formatWithCustomName(QString customName, const CAmount &amount, int unit=MAX_ASSET_UNITS, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with custom name)
Definition: ravenunits.cpp:151
static int decimals(int unit)
Number of decimals left.
Definition: ravenunits.cpp:90
RavenUnits::Unit RavenUnit
Definition: ravenunits.h:137
Raven unit definitions.
Definition: ravenunits.h:53
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
Definition: ravenunits.cpp:62
#define MAX_ASSET_UNITS
Definition: ravenunits.h:15
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
Definition: ravenunits.cpp:278
static QString description(int unit)
Longer description.
Definition: ravenunits.cpp:51