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
Only one tx details dialog that a user can open per tx id is enough.
  • Loading branch information
pablomartin4btc committed Aug 2, 2024
1 parent e319569 commit 5aec5d2
Show file tree
Hide file tree
Showing 4 changed files with 29 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
5 changes: 5 additions & 0 deletions src/qt/transactiondescdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BITCOIN_QT_TRANSACTIONDESCDIALOG_H

#include <QDialog>
#include <QString>

namespace Ui {
class TransactionDescDialog;
Expand All @@ -24,8 +25,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
28 changes: 21 additions & 7 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QPoint>
#include <QScrollBar>
#include <QSettings>
#include <QString>
#include <QTableView>
#include <QTimer>
#include <QUrl>
Expand Down Expand Up @@ -528,13 +529,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 +666,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()) {
GUIUtil::bringToFront(dlg);
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 5aec5d2

Please sign in to comment.