Skip to content

Commit

Permalink
gui: Fix multiple dialogs for same tx in TransactionView
Browse files Browse the repository at this point in the history
Limit to one the transaction details dialogs that a user can open.
  • Loading branch information
pablomartin4btc committed Apr 12, 2024
1 parent e319569 commit b26d2e8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/qt/transactiondescdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa
ui(new Ui::TransactionDescDialog)
{
ui->setupUi(this);
setWindowTitle(tr("Details for %1").arg(idx.data(TransactionTableModel::TxHashRole).toString()));
m_transaction_id = idx.data(TransactionTableModel::TxHashRole).toString();
setWindowTitle(tr("Details for %1").arg(m_transaction_id));
QString desc = idx.data(TransactionTableModel::LongDescriptionRole).toString();
ui->detailText->setHtml(desc);

Expand Down
4 changes: 4 additions & 0 deletions src/qt/transactiondescdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ class TransactionDescDialog : public QDialog
explicit TransactionDescDialog(const QModelIndex &idx, QWidget *parent = nullptr);
~TransactionDescDialog();

QString getTransactionId() {return m_transaction_id;};

private:
Ui::TransactionDescDialog *ui;
QString m_transaction_id;

};

#endif // BITCOIN_QT_TRANSACTIONDESCDIALOG_H
27 changes: 20 additions & 7 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,15 @@ void TransactionView::showDetails()
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
if(!selection.isEmpty())
{
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0));
dlg->setAttribute(Qt::WA_DeleteOnClose);
m_opened_dialogs.append(dlg);
connect(dlg, &QObject::destroyed, [this, dlg] {
m_opened_dialogs.removeOne(dlg);
});
dlg->show();
if(!detailsAlreadyShown(selection.at(0))) {
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0));
dlg->setAttribute(Qt::WA_DeleteOnClose);
m_opened_dialogs.append(dlg);
connect(dlg, &QObject::destroyed, [this, dlg] {
m_opened_dialogs.removeOne(dlg);
});
dlg->show();
}
}
}

Expand Down Expand Up @@ -663,3 +665,14 @@ void TransactionView::closeOpenedDialogs()
}
m_opened_dialogs.clear();
}

bool TransactionView::detailsAlreadyShown(const QModelIndex &idx)
{
for (TransactionDescDialog* dlg : m_opened_dialogs) {
if (dlg->getTransactionId() == idx.data(TransactionTableModel::TxHashRole).toString()) {
dlg->activateWindow();
return true;
}
}
return false;
}
1 change: 1 addition & 0 deletions src/qt/transactionview.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private Q_SLOTS:
void updateWatchOnlyColumn(bool fHaveWatchOnly);
void abandonTx();
void bumpFee(bool checked);
bool detailsAlreadyShown(const QModelIndex &idx);

Q_SIGNALS:
void doubleClicked(const QModelIndex&);
Expand Down

0 comments on commit b26d2e8

Please sign in to comment.