mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Merge #12327: [gui] Defer coin control instancing
6558f8acc
[gui] Defer coin control instancing (João Barbosa)
Pull request description:
Defer the GUI coin control instancing so that argument processing
is taken into account for the default coin control values.
Fixes #12312
Tree-SHA512: ecda28b94f4709319e9484b01afe763c7c3569097d2afb89db79da8a195c46d20ea77166df7edce0c8ab77627b295def01c072148714503436d27675d5e75d99
This commit is contained in:
commit
41363fe11d
@ -31,7 +31,6 @@
|
||||
#include <QTreeWidget>
|
||||
|
||||
QList<CAmount> CoinControlDialog::payAmounts;
|
||||
CCoinControl* CoinControlDialog::coinControl = new CCoinControl();
|
||||
bool CoinControlDialog::fSubtractFeeFromAmount = false;
|
||||
|
||||
bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
|
||||
@ -193,7 +192,7 @@ 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
|
||||
coinControl()->UnSelectAll(); // just to be sure
|
||||
CoinControlDialog::updateLabels(model, this);
|
||||
}
|
||||
|
||||
@ -379,11 +378,11 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)
|
||||
COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt());
|
||||
|
||||
if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked)
|
||||
coinControl->UnSelect(outpt);
|
||||
coinControl()->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);
|
||||
coinControl()->Select(outpt);
|
||||
|
||||
// selection changed -> update labels
|
||||
if (ui->treeWidget->isEnabled()) // do not update on every click for (un)select all
|
||||
@ -446,7 +445,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
|
||||
std::vector<COutPoint> vCoinControl;
|
||||
std::vector<COutput> vOutputs;
|
||||
coinControl->ListSelected(vCoinControl);
|
||||
coinControl()->ListSelected(vCoinControl);
|
||||
model->getOutputs(vCoinControl, vOutputs);
|
||||
|
||||
for (const COutput& out : vOutputs) {
|
||||
@ -456,7 +455,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
COutPoint outpt(txhash, out.i);
|
||||
if (model->isSpent(outpt))
|
||||
{
|
||||
coinControl->UnSelect(outpt);
|
||||
coinControl()->UnSelect(outpt);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -509,7 +508,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
nBytes -= 34;
|
||||
|
||||
// Fee
|
||||
nPayFee = GetMinimumFee(nBytes, *coinControl, ::mempool, ::feeEstimator, nullptr /* FeeCalculation */);
|
||||
nPayFee = GetMinimumFee(nBytes, *coinControl(), ::mempool, ::feeEstimator, nullptr /* FeeCalculation */);
|
||||
|
||||
if (nPayAmount > 0)
|
||||
{
|
||||
@ -600,6 +599,12 @@ 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())
|
||||
@ -703,13 +708,13 @@ void CoinControlDialog::updateView()
|
||||
if (model->isLockedCoin(txhash, out.i))
|
||||
{
|
||||
COutPoint outpt(txhash, out.i);
|
||||
coinControl->UnSelect(outpt); // just to be sure
|
||||
coinControl()->UnSelect(outpt); // just to be sure
|
||||
itemOutput->setDisabled(true);
|
||||
itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
|
||||
}
|
||||
|
||||
// set checkbox
|
||||
if (coinControl->IsSelected(COutPoint(txhash, out.i)))
|
||||
if (coinControl()->IsSelected(COutPoint(txhash, out.i)))
|
||||
itemOutput->setCheckState(COLUMN_CHECKBOX, Qt::Checked);
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
static void updateLabels(WalletModel*, QDialog*);
|
||||
|
||||
static QList<CAmount> payAmounts;
|
||||
static CCoinControl *coinControl;
|
||||
static CCoinControl *coinControl();
|
||||
static bool fSubtractFeeFromAmount;
|
||||
|
||||
private:
|
||||
|
@ -256,7 +256,7 @@ void SendCoinsDialog::on_sendButton_clicked()
|
||||
// Always use a CCoinControl instance, use the CoinControlDialog instance if CoinControl has been enabled
|
||||
CCoinControl ctrl;
|
||||
if (model->getOptionsModel()->getCoinControlFeatures())
|
||||
ctrl = *CoinControlDialog::coinControl;
|
||||
ctrl = *CoinControlDialog::coinControl();
|
||||
|
||||
updateCoinControlState(ctrl);
|
||||
|
||||
@ -367,7 +367,7 @@ void SendCoinsDialog::on_sendButton_clicked()
|
||||
if (sendStatus.status == WalletModel::OK)
|
||||
{
|
||||
accept();
|
||||
CoinControlDialog::coinControl->UnSelectAll();
|
||||
CoinControlDialog::coinControl()->UnSelectAll();
|
||||
coinControlUpdateLabels();
|
||||
}
|
||||
fNewRecipientAllowed = true;
|
||||
@ -604,7 +604,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
|
||||
// Get CCoinControl instance if CoinControl is enabled or create a new one.
|
||||
CCoinControl coin_control;
|
||||
if (model->getOptionsModel()->getCoinControlFeatures()) {
|
||||
coin_control = *CoinControlDialog::coinControl;
|
||||
coin_control = *CoinControlDialog::coinControl();
|
||||
}
|
||||
|
||||
// Calculate available amount to send.
|
||||
@ -754,7 +754,7 @@ void SendCoinsDialog::coinControlFeatureChanged(bool checked)
|
||||
ui->frameCoinControl->setVisible(checked);
|
||||
|
||||
if (!checked && model) // coin control features disabled
|
||||
CoinControlDialog::coinControl->SetNull();
|
||||
CoinControlDialog::coinControl()->SetNull();
|
||||
|
||||
coinControlUpdateLabels();
|
||||
}
|
||||
@ -773,7 +773,7 @@ void SendCoinsDialog::coinControlChangeChecked(int state)
|
||||
{
|
||||
if (state == Qt::Unchecked)
|
||||
{
|
||||
CoinControlDialog::coinControl->destChange = CNoDestination();
|
||||
CoinControlDialog::coinControl()->destChange = CNoDestination();
|
||||
ui->labelCoinControlChangeLabel->clear();
|
||||
}
|
||||
else
|
||||
@ -789,7 +789,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
|
||||
if (model && model->getAddressTableModel())
|
||||
{
|
||||
// Default to no change address until verified
|
||||
CoinControlDialog::coinControl->destChange = CNoDestination();
|
||||
CoinControlDialog::coinControl()->destChange = CNoDestination();
|
||||
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
|
||||
|
||||
const CTxDestination dest = DecodeDestination(text.toStdString());
|
||||
@ -812,7 +812,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
|
||||
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
|
||||
|
||||
if(btnRetVal == QMessageBox::Yes)
|
||||
CoinControlDialog::coinControl->destChange = dest;
|
||||
CoinControlDialog::coinControl()->destChange = dest;
|
||||
else
|
||||
{
|
||||
ui->lineEditCoinControlChange->setText("");
|
||||
@ -831,7 +831,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
|
||||
else
|
||||
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
|
||||
|
||||
CoinControlDialog::coinControl->destChange = dest;
|
||||
CoinControlDialog::coinControl()->destChange = dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -843,7 +843,7 @@ void SendCoinsDialog::coinControlUpdateLabels()
|
||||
if (!model || !model->getOptionsModel())
|
||||
return;
|
||||
|
||||
updateCoinControlState(*CoinControlDialog::coinControl);
|
||||
updateCoinControlState(*CoinControlDialog::coinControl());
|
||||
|
||||
// set pay amounts
|
||||
CoinControlDialog::payAmounts.clear();
|
||||
@ -861,7 +861,7 @@ void SendCoinsDialog::coinControlUpdateLabels()
|
||||
}
|
||||
}
|
||||
|
||||
if (CoinControlDialog::coinControl->HasSelected())
|
||||
if (CoinControlDialog::coinControl()->HasSelected())
|
||||
{
|
||||
// actual coin control calculation
|
||||
CoinControlDialog::updateLabels(model, this);
|
||||
|
Loading…
Reference in New Issue
Block a user