Skip to content

Commit f9b633e

Browse files
committed
qt, wallet: Move activity progress dialog from data member to local
1 parent d2dd169 commit f9b633e

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

src/qt/walletcontroller.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -193,31 +193,20 @@ WalletControllerActivity::WalletControllerActivity(WalletController* wallet_cont
193193
{
194194
}
195195

196-
WalletControllerActivity::~WalletControllerActivity()
197-
{
198-
delete m_progress_dialog;
199-
}
200-
201196
void WalletControllerActivity::showProgressDialog(const QString& label_text)
202197
{
203-
assert(!m_progress_dialog);
204-
m_progress_dialog = new QProgressDialog(m_parent_widget);
205-
206-
m_progress_dialog->setLabelText(label_text);
207-
m_progress_dialog->setRange(0, 0);
208-
m_progress_dialog->setCancelButton(nullptr);
209-
m_progress_dialog->setWindowModality(Qt::ApplicationModal);
210-
GUIUtil::PolishProgressDialog(m_progress_dialog);
198+
auto progress_dialog = new QProgressDialog(m_parent_widget);
199+
progress_dialog->setAttribute(Qt::WA_DeleteOnClose);
200+
connect(this, &WalletControllerActivity::finished, progress_dialog, &QWidget::close);
201+
202+
progress_dialog->setLabelText(label_text);
203+
progress_dialog->setRange(0, 0);
204+
progress_dialog->setCancelButton(nullptr);
205+
progress_dialog->setWindowModality(Qt::ApplicationModal);
206+
GUIUtil::PolishProgressDialog(progress_dialog);
211207
// The setValue call forces QProgressDialog to start the internal duration estimation.
212208
// See details in https://bugreports.qt.io/browse/QTBUG-47042.
213-
m_progress_dialog->setValue(0);
214-
}
215-
216-
void WalletControllerActivity::destroyProgressDialog()
217-
{
218-
assert(m_progress_dialog);
219-
delete m_progress_dialog;
220-
m_progress_dialog = nullptr;
209+
progress_dialog->setValue(0);
221210
}
222211

223212
CreateWalletActivity::CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget)
@@ -279,8 +268,6 @@ void CreateWalletActivity::createWallet()
279268

280269
void CreateWalletActivity::finish()
281270
{
282-
destroyProgressDialog();
283-
284271
if (!m_error_message.empty()) {
285272
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message.translated));
286273
} else if (!m_warning_message.empty()) {
@@ -329,8 +316,6 @@ OpenWalletActivity::OpenWalletActivity(WalletController* wallet_controller, QWid
329316

330317
void OpenWalletActivity::finish()
331318
{
332-
destroyProgressDialog();
333-
334319
if (!m_error_message.empty()) {
335320
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message.translated));
336321
} else if (!m_warning_message.empty()) {

src/qt/walletcontroller.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class WalletControllerActivity : public QObject
9090

9191
public:
9292
WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
93-
virtual ~WalletControllerActivity();
93+
virtual ~WalletControllerActivity() = default;
9494

9595
Q_SIGNALS:
9696
void finished();
@@ -100,11 +100,9 @@ class WalletControllerActivity : public QObject
100100
QObject* worker() const { return m_wallet_controller->m_activity_worker; }
101101

102102
void showProgressDialog(const QString& label_text);
103-
void destroyProgressDialog();
104103

105104
WalletController* const m_wallet_controller;
106105
QWidget* const m_parent_widget;
107-
QProgressDialog* m_progress_dialog{nullptr};
108106
WalletModel* m_wallet_model{nullptr};
109107
bilingual_str m_error_message;
110108
std::vector<bilingual_str> m_warning_message;

0 commit comments

Comments
 (0)