mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge #18894: gui: Fix manual coin control with multiple wallets loaded
a8b5f1b133gui: Fix manual coin control with multiple wallets loaded (João Barbosa) Pull request description: This PR ensures each loaded wallet has a dedicated coin control in the send view which is manipulated by the coin control dialog. This is an alternative to #17457. Two main differences are: - scope reduced - no unnecessary changes unrelated to the fix; - approach taken - coin control instance now belongs to the send view. All problems raised in #17457 reviews no longer apply due to the approach taken - https://github.com/bitcoin/bitcoin/pull/17457#pullrequestreview-319297589 and https://github.com/bitcoin/bitcoin/pull/17457#issuecomment-555920829) No change in behavior if only one wallet is loaded. Closes #15725. ACKs for top commit: jonasschnelli: utACKa8b5f1b133ryanofsky: Code review ACKa8b5f1b133. Code changes are very straightforward, just replacing global CCoinControl object with SendCoinsDialog member. Not sure if this means coin control settings are reset between payments. It would be good to note in the PR description or release notes if single wallet behavior is affected hebasto: ACKa8b5f1b133Sjors: tACKa8b5f1b133Tree-SHA512: 3ad9c51bab6f28ec0e90efbd6f43fa510c81dafb2eff0b8c3724efcee3e030054a10be013e27cefe35763374c5f6d7af8c02658736964f733d7e38b646b5df65
This commit is contained in:
@@ -41,10 +41,11 @@ bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
|
||||
return QTreeWidgetItem::operator<(other);
|
||||
}
|
||||
|
||||
CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
|
||||
CoinControlDialog::CoinControlDialog(CCoinControl& coin_control, WalletModel* _model, const PlatformStyle *_platformStyle, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::CoinControlDialog),
|
||||
model(nullptr),
|
||||
m_coin_control(coin_control),
|
||||
model(_model),
|
||||
platformStyle(_platformStyle)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@@ -136,6 +137,13 @@ CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidge
|
||||
sortView(settings.value("nCoinControlSortColumn").toInt(), (static_cast<Qt::SortOrder>(settings.value("nCoinControlSortOrder").toInt())));
|
||||
|
||||
GUIUtil::handleCloseWindowShortcut(this);
|
||||
|
||||
if(_model->getOptionsModel() && _model->getAddressTableModel())
|
||||
{
|
||||
updateView();
|
||||
updateLabelLocked();
|
||||
CoinControlDialog::updateLabels(m_coin_control, _model, this);
|
||||
}
|
||||
}
|
||||
|
||||
CoinControlDialog::~CoinControlDialog()
|
||||
@@ -148,18 +156,6 @@ CoinControlDialog::~CoinControlDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CoinControlDialog::setModel(WalletModel *_model)
|
||||
{
|
||||
this->model = _model;
|
||||
|
||||
if(_model && _model->getOptionsModel() && _model->getAddressTableModel())
|
||||
{
|
||||
updateView();
|
||||
updateLabelLocked();
|
||||
CoinControlDialog::updateLabels(_model, this);
|
||||
}
|
||||
}
|
||||
|
||||
// ok button
|
||||
void CoinControlDialog::buttonBoxClicked(QAbstractButton* button)
|
||||
{
|
||||
@@ -185,8 +181,8 @@ void CoinControlDialog::buttonSelectAllClicked()
|
||||
ui->treeWidget->topLevelItem(i)->setCheckState(COLUMN_CHECKBOX, state);
|
||||
ui->treeWidget->setEnabled(true);
|
||||
if (state == Qt::Unchecked)
|
||||
coinControl()->UnSelectAll(); // just to be sure
|
||||
CoinControlDialog::updateLabels(model, this);
|
||||
m_coin_control.UnSelectAll(); // just to be sure
|
||||
CoinControlDialog::updateLabels(m_coin_control, model, this);
|
||||
}
|
||||
|
||||
// context menu
|
||||
@@ -371,15 +367,15 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)
|
||||
COutPoint outpt(uint256S(item->data(COLUMN_ADDRESS, TxHashRole).toString().toStdString()), item->data(COLUMN_ADDRESS, VOutRole).toUInt());
|
||||
|
||||
if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked)
|
||||
coinControl()->UnSelect(outpt);
|
||||
m_coin_control.UnSelect(outpt);
|
||||
else if (item->isDisabled()) // locked (this happens if "check all" through parent node)
|
||||
item->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
|
||||
else
|
||||
coinControl()->Select(outpt);
|
||||
m_coin_control.Select(outpt);
|
||||
|
||||
// selection changed -> update labels
|
||||
if (ui->treeWidget->isEnabled()) // do not update on every click for (un)select all
|
||||
CoinControlDialog::updateLabels(model, this);
|
||||
CoinControlDialog::updateLabels(m_coin_control, model, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +392,7 @@ void CoinControlDialog::updateLabelLocked()
|
||||
else ui->labelLocked->setVisible(false);
|
||||
}
|
||||
|
||||
void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *model, QDialog* dialog)
|
||||
{
|
||||
if (!model)
|
||||
return;
|
||||
@@ -428,7 +424,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
bool fWitness = false;
|
||||
|
||||
std::vector<COutPoint> vCoinControl;
|
||||
coinControl()->ListSelected(vCoinControl);
|
||||
m_coin_control.ListSelected(vCoinControl);
|
||||
|
||||
size_t i = 0;
|
||||
for (const auto& out : model->wallet().getCoins(vCoinControl)) {
|
||||
@@ -439,7 +435,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
const COutPoint& outpt = vCoinControl[i++];
|
||||
if (out.is_spent)
|
||||
{
|
||||
coinControl()->UnSelect(outpt);
|
||||
m_coin_control.UnSelect(outpt);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -492,7 +488,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
nBytes -= 34;
|
||||
|
||||
// Fee
|
||||
nPayFee = model->wallet().getMinimumFee(nBytes, *coinControl(), nullptr /* returned_target */, nullptr /* reason */);
|
||||
nPayFee = model->wallet().getMinimumFee(nBytes, m_coin_control, nullptr /* returned_target */, nullptr /* reason */);
|
||||
|
||||
if (nPayAmount > 0)
|
||||
{
|
||||
@@ -584,12 +580,6 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
label->setVisible(nChange < 0);
|
||||
}
|
||||
|
||||
CCoinControl* CoinControlDialog::coinControl()
|
||||
{
|
||||
static CCoinControl coin_control;
|
||||
return &coin_control;
|
||||
}
|
||||
|
||||
void CoinControlDialog::updateView()
|
||||
{
|
||||
if (!model || !model->getOptionsModel() || !model->getAddressTableModel())
|
||||
@@ -689,13 +679,13 @@ void CoinControlDialog::updateView()
|
||||
// disable locked coins
|
||||
if (model->wallet().isLockedCoin(output))
|
||||
{
|
||||
coinControl()->UnSelect(output); // just to be sure
|
||||
m_coin_control.UnSelect(output); // just to be sure
|
||||
itemOutput->setDisabled(true);
|
||||
itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
|
||||
}
|
||||
|
||||
// set checkbox
|
||||
if (coinControl()->IsSelected(output))
|
||||
if (m_coin_control.IsSelected(output))
|
||||
itemOutput->setCheckState(COLUMN_CHECKBOX, Qt::Checked);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user