mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-12 05:34:57 +01:00
qt, refactor: Make BitcoinUnits::Unit a scoped enum
This commit is contained in:
committed by
William Casarin
parent
75832fdc37
commit
aa23960fdf
@@ -14,6 +14,9 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
#include <QVariant>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
/** QSpinBox that uses fixed-point numbers internally and uses our own
|
||||
* formatting/parsing functions.
|
||||
@@ -96,7 +99,7 @@ public:
|
||||
setValue(val);
|
||||
}
|
||||
|
||||
void setDisplayUnit(int unit)
|
||||
void setDisplayUnit(BitcoinUnit unit)
|
||||
{
|
||||
bool valid = false;
|
||||
CAmount val = value(&valid);
|
||||
@@ -122,7 +125,7 @@ public:
|
||||
|
||||
const QFontMetrics fm(fontMetrics());
|
||||
int h = lineEdit()->minimumSizeHint().height();
|
||||
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnits::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::SeparatorStyle::ALWAYS));
|
||||
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnit::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::SeparatorStyle::ALWAYS));
|
||||
w += 2; // cursor blinking space
|
||||
|
||||
QStyleOptionSpinBox opt;
|
||||
@@ -148,7 +151,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
int currentUnit{BitcoinUnits::BTC};
|
||||
BitcoinUnit currentUnit{BitcoinUnit::BTC};
|
||||
CAmount singleStep{CAmount(100000)}; // satoshis
|
||||
mutable QSize cachedMinimumSizeHint;
|
||||
bool m_allow_empty{true};
|
||||
@@ -326,14 +329,14 @@ void BitcoinAmountField::unitChanged(int idx)
|
||||
unit->setToolTip(unit->itemData(idx, Qt::ToolTipRole).toString());
|
||||
|
||||
// Determine new unit ID
|
||||
int newUnit = unit->itemData(idx, BitcoinUnits::UnitRole).toInt();
|
||||
|
||||
amount->setDisplayUnit(newUnit);
|
||||
QVariant new_unit = unit->currentData(BitcoinUnits::UnitRole);
|
||||
assert(new_unit.isValid());
|
||||
amount->setDisplayUnit(new_unit.value<BitcoinUnit>());
|
||||
}
|
||||
|
||||
void BitcoinAmountField::setDisplayUnit(int newUnit)
|
||||
void BitcoinAmountField::setDisplayUnit(BitcoinUnit new_unit)
|
||||
{
|
||||
unit->setValue(newUnit);
|
||||
unit->setValue(QVariant::fromValue(new_unit));
|
||||
}
|
||||
|
||||
void BitcoinAmountField::setSingleStep(const CAmount& step)
|
||||
|
||||
Reference in New Issue
Block a user