Merge bitcoin-core/gui#3: scripted-diff: Make SeparatorStyle a scoped enum
25f3554351
scripted-diff: Make SeparatorStyle a scoped enum (Hennadii Stepanov) Pull request description: This PR is [split](https://github.com/bitcoin/bitcoin/pull/17877#issuecomment-644751515) from https://github.com/bitcoin/bitcoin/pull/17877 and makes `BitcoinUnits::SeparatorStyle` a scoped enum. ACKs for top commit: MarcoFalke: review ACK25f3554351
🚐 Tree-SHA512: 578f1340a476cf79faa109a83815d3c75e26d9c18873e653d7624b52428ccb2677293116db0a60ae14c949d63b64988fc5a39c7184c2352b87b00e8ddaaaf474
This commit is contained in:
commit
0865a8881d
9 changed files with 37 additions and 37 deletions
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
if (valid) {
|
||||
val = qBound(m_min_amount, val, m_max_amount);
|
||||
input = BitcoinUnits::format(currentUnit, val, false, BitcoinUnits::separatorAlways);
|
||||
input = BitcoinUnits::format(currentUnit, val, false, BitcoinUnits::SeparatorStyle::ALWAYS);
|
||||
lineEdit()->setText(input);
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
void setValue(const CAmount& value)
|
||||
{
|
||||
lineEdit()->setText(BitcoinUnits::format(currentUnit, value, false, BitcoinUnits::separatorAlways));
|
||||
lineEdit()->setText(BitcoinUnits::format(currentUnit, value, false, BitcoinUnits::SeparatorStyle::ALWAYS));
|
||||
Q_EMIT valueChanged();
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
CAmount val = value(&valid);
|
||||
|
||||
currentUnit = unit;
|
||||
lineEdit()->setPlaceholderText(BitcoinUnits::format(currentUnit, m_min_amount, false, BitcoinUnits::separatorAlways));
|
||||
lineEdit()->setPlaceholderText(BitcoinUnits::format(currentUnit, m_min_amount, false, BitcoinUnits::SeparatorStyle::ALWAYS));
|
||||
if(valid)
|
||||
setValue(val);
|
||||
else
|
||||
|
@ -122,7 +122,7 @@ public:
|
|||
|
||||
const QFontMetrics fm(fontMetrics());
|
||||
int h = lineEdit()->minimumSizeHint().height();
|
||||
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnits::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::separatorAlways));
|
||||
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnits::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::SeparatorStyle::ALWAYS));
|
||||
w += 2; // cursor blinking space
|
||||
|
||||
QStyleOptionSpinBox opt;
|
||||
|
|
|
@ -114,7 +114,7 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
|
|||
// confused with the decimal marker.
|
||||
QChar thin_sp(THIN_SP_CP);
|
||||
int q_size = quotient_str.size();
|
||||
if (separators == separatorAlways || (separators == separatorStandard && q_size > 4))
|
||||
if (separators == SeparatorStyle::ALWAYS || (separators == SeparatorStyle::STANDARD && q_size > 4))
|
||||
for (int i = 3; i < q_size; i += 3)
|
||||
quotient_str.insert(q_size - i, thin_sp);
|
||||
|
||||
|
|
|
@ -46,11 +46,11 @@ public:
|
|||
SAT
|
||||
};
|
||||
|
||||
enum SeparatorStyle
|
||||
enum class SeparatorStyle
|
||||
{
|
||||
separatorNever,
|
||||
separatorStandard,
|
||||
separatorAlways
|
||||
NEVER,
|
||||
STANDARD,
|
||||
ALWAYS
|
||||
};
|
||||
|
||||
//! @name Static API
|
||||
|
@ -72,11 +72,11 @@ public:
|
|||
//! Number of decimals left
|
||||
static int decimals(int unit);
|
||||
//! Format as string
|
||||
static QString format(int unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = separatorStandard, bool justify = false);
|
||||
static QString format(int unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = SeparatorStyle::STANDARD, bool justify = false);
|
||||
//! Format as string (with unit)
|
||||
static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
|
||||
static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD);
|
||||
//! Format as HTML string (with unit)
|
||||
static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
|
||||
static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD);
|
||||
//! Format as string (with unit) of fixed length to preserve privacy, if it is set.
|
||||
static QString formatWithPrivacy(int unit, const CAmount& amount, SeparatorStyle separators, bool privacy);
|
||||
//! Parse string to coin amount
|
||||
|
|
|
@ -188,7 +188,7 @@ QString formatBitcoinURI(const SendCoinsRecipient &info)
|
|||
|
||||
if (info.amount)
|
||||
{
|
||||
ret += QString("?amount=%1").arg(BitcoinUnits::format(BitcoinUnits::BTC, info.amount, false, BitcoinUnits::separatorNever));
|
||||
ret += QString("?amount=%1").arg(BitcoinUnits::format(BitcoinUnits::BTC, info.amount, false, BitcoinUnits::SeparatorStyle::NEVER));
|
||||
paramCount++;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public:
|
|||
foreground = option.palette.color(QPalette::Text);
|
||||
}
|
||||
painter->setPen(foreground);
|
||||
QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true, BitcoinUnits::separatorAlways);
|
||||
QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true, BitcoinUnits::SeparatorStyle::ALWAYS);
|
||||
if(!confirmed)
|
||||
{
|
||||
amountText = QString("[") + amountText + QString("]");
|
||||
|
@ -180,25 +180,25 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
|
|||
m_balances = balances;
|
||||
if (walletModel->wallet().isLegacy()) {
|
||||
if (walletModel->wallet().privateKeysDisabled()) {
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
} else {
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelWatchPending->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelWatchImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelWatchTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelWatchPending->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelWatchImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelWatchTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
}
|
||||
} else {
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, BitcoinUnits::separatorAlways, m_privacy));
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithPrivacy(unit, balances.unconfirmed_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithPrivacy(unit, balances.immature_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithPrivacy(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, BitcoinUnits::SeparatorStyle::ALWAYS, m_privacy));
|
||||
}
|
||||
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
|
||||
// for the non-mining users
|
||||
|
|
|
@ -82,7 +82,7 @@ QVariant RecentRequestsTableModel::data(const QModelIndex &index, int role) cons
|
|||
if (rec->recipient.amount == 0 && role == Qt::DisplayRole)
|
||||
return tr("(no amount requested)");
|
||||
else if (role == Qt::EditRole)
|
||||
return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), rec->recipient.amount, false, BitcoinUnits::separatorNever);
|
||||
return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), rec->recipient.amount, false, BitcoinUnits::SeparatorStyle::NEVER);
|
||||
else
|
||||
return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), rec->recipient.amount);
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ void TestGUI(interfaces::Node& node)
|
|||
QString balanceText = balanceLabel->text();
|
||||
int unit = walletModel.getOptionsModel()->getDisplayUnit();
|
||||
CAmount balance = walletModel.wallet().getBalance();
|
||||
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways);
|
||||
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::SeparatorStyle::ALWAYS);
|
||||
QCOMPARE(balanceText, balanceComparison);
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ void TestGUI(interfaces::Node& node)
|
|||
QString balanceText = balanceLabel->text().trimmed();
|
||||
int unit = walletModel.getOptionsModel()->getDisplayUnit();
|
||||
CAmount balance = walletModel.wallet().getBalance();
|
||||
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways);
|
||||
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::SeparatorStyle::ALWAYS);
|
||||
QCOMPARE(balanceText, balanceComparison);
|
||||
|
||||
// Check Request Payment button
|
||||
|
|
|
@ -524,7 +524,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
|
|||
case ToAddress:
|
||||
return formatTxToAddress(rec, false);
|
||||
case Amount:
|
||||
return formatTxAmount(rec, true, BitcoinUnits::separatorAlways);
|
||||
return formatTxAmount(rec, true, BitcoinUnits::SeparatorStyle::ALWAYS);
|
||||
}
|
||||
break;
|
||||
case Qt::EditRole:
|
||||
|
@ -614,14 +614,14 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
|
|||
details.append(QString::fromStdString(rec->address));
|
||||
details.append(" ");
|
||||
}
|
||||
details.append(formatTxAmount(rec, false, BitcoinUnits::separatorNever));
|
||||
details.append(formatTxAmount(rec, false, BitcoinUnits::SeparatorStyle::NEVER));
|
||||
return details;
|
||||
}
|
||||
case ConfirmedRole:
|
||||
return rec->status.status == TransactionStatus::Status::Confirming || rec->status.status == TransactionStatus::Status::Confirmed;
|
||||
case FormattedAmountRole:
|
||||
// Used for copy/export, so don't include separators
|
||||
return formatTxAmount(rec, false, BitcoinUnits::separatorNever);
|
||||
return formatTxAmount(rec, false, BitcoinUnits::SeparatorStyle::NEVER);
|
||||
case StatusRole:
|
||||
return rec->status.status;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ private:
|
|||
QString formatTxDate(const TransactionRecord *wtx) const;
|
||||
QString formatTxType(const TransactionRecord *wtx) const;
|
||||
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const;
|
||||
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::separatorStandard) const;
|
||||
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::SeparatorStyle::STANDARD) const;
|
||||
QString formatTooltip(const TransactionRecord *rec) const;
|
||||
QVariant txStatusDecoration(const TransactionRecord *wtx) const;
|
||||
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const;
|
||||
|
|
Loading…
Reference in a new issue