10 #include <QStringList> 13 QAbstractListModel(parent),
14 unitlist(availableUnits())
22 unitlist.append(
mRVN);
23 unitlist.append(
uRVN);
44 case RVN:
return QString(
"RVN");
45 case mRVN:
return QString(
"mRVN");
46 case uRVN:
return QString::fromUtf8(
"μRVN");
47 default:
return QString(
"???");
55 case RVN:
return QString(
"Ravens");
58 default:
return QString(
"???");
66 case RVN:
return 100000000;
67 case mRVN:
return 100000;
68 case uRVN:
return 100;
69 default:
return 100000000;
82 case 5:
return 100000;
83 case 6:
return 1000000;
84 case 7:
return 10000000;
85 case 8:
return 100000000;
86 default:
return 100000000;
105 if((nAssetUnit < 0 || nAssetUnit > 8) && !
valid(unit))
107 qint64 n = (qint64)nIn;
109 int num_decimals = nAssetUnit >= 0 ? nAssetUnit :
decimals(unit);
110 qint64 n_abs = (n > 0 ? n : -n);
111 qint64 quotient = n_abs / coin;
112 qint64 remainder = n_abs % coin;
113 QString quotient_str = QString::number(quotient);
114 QString remainder_str = QString::number(remainder).rightJustified(num_decimals,
'0');
120 int q_size = quotient_str.size();
122 for (
int i = 3; i < q_size; i += 3)
123 quotient_str.insert(q_size - i, thin_sp);
126 quotient_str.insert(0,
'-');
127 else if (fPlus && n > 0)
128 quotient_str.insert(0,
'+');
134 return quotient_str + QString(
".") + remainder_str;
148 return format(unit, amount, plussign, separators) + QString(
" ") +
name(unit);
160 return QString(
"<span style='white-space: nowrap;'>%1</span>").arg(str);
166 if(!
valid(unit) || value.isEmpty())
177 QString whole = parts[0];
184 if(decimals.size() > num_decimals)
189 QString str = whole + decimals.leftJustified(num_decimals,
'0');
195 CAmount retvalue(str.toLongLong(&ok));
205 if(!(assetUnit >= 0 && assetUnit <= 8) || value.isEmpty())
207 int num_decimals = assetUnit;
216 QString whole = parts[0];
223 if(decimals.size() > num_decimals)
228 QString str = whole + decimals.leftJustified(num_decimals,
'0');
234 CAmount retvalue(str.toLongLong(&ok));
244 QString amountTitle = QObject::tr(
"Amount");
260 int row = index.row();
261 if(row >= 0 && row <
unitlist.size())
267 case Qt::DisplayRole:
268 return QVariant(
name(unit));
269 case Qt::ToolTipRole:
272 return QVariant(static_cast<int>(unit));
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, const int nAssetUnit=MIN_ASSET_UNITS - 1)
Format as string.
static bool assetParse(int assetUnit, const QString &value, CAmount *val_out)
static bool valid(int unit)
Is unit ID valid?
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */...
QList< RavenUnits::Unit > unitlist
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
int64_t CAmount
Amount in corbies (Can be negative)
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
int rowCount(const QModelIndex &parent) const
static QString removeSpaces(QString text)
QVariant data(const QModelIndex &index, int role) const
RavenUnits(QObject *parent)
static qint64 factorAsset(int unit)
Number of Satoshis (1e-8) per unit for assets.
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
static QString name(int unit)
Short name.
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)
static int decimals(int unit)
Number of decimals left.
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
static QString description(int unit)
Longer description.