Skip to content

Commit

Permalink
qt, wallet: Move activity progress dialog from data member to local
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 9, 2021
1 parent d2dd169 commit f9b633e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
35 changes: 10 additions & 25 deletions src/qt/walletcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,31 +193,20 @@ WalletControllerActivity::WalletControllerActivity(WalletController* wallet_cont
{
}

WalletControllerActivity::~WalletControllerActivity()
{
delete m_progress_dialog;
}

void WalletControllerActivity::showProgressDialog(const QString& label_text)
{
assert(!m_progress_dialog);
m_progress_dialog = new QProgressDialog(m_parent_widget);

m_progress_dialog->setLabelText(label_text);
m_progress_dialog->setRange(0, 0);
m_progress_dialog->setCancelButton(nullptr);
m_progress_dialog->setWindowModality(Qt::ApplicationModal);
GUIUtil::PolishProgressDialog(m_progress_dialog);
auto progress_dialog = new QProgressDialog(m_parent_widget);
progress_dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(this, &WalletControllerActivity::finished, progress_dialog, &QWidget::close);

progress_dialog->setLabelText(label_text);
progress_dialog->setRange(0, 0);
progress_dialog->setCancelButton(nullptr);
progress_dialog->setWindowModality(Qt::ApplicationModal);
GUIUtil::PolishProgressDialog(progress_dialog);
// The setValue call forces QProgressDialog to start the internal duration estimation.
// See details in https://bugreports.qt.io/browse/QTBUG-47042.
m_progress_dialog->setValue(0);
}

void WalletControllerActivity::destroyProgressDialog()
{
assert(m_progress_dialog);
delete m_progress_dialog;
m_progress_dialog = nullptr;
progress_dialog->setValue(0);
}

CreateWalletActivity::CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget)
Expand Down Expand Up @@ -279,8 +268,6 @@ void CreateWalletActivity::createWallet()

void CreateWalletActivity::finish()
{
destroyProgressDialog();

if (!m_error_message.empty()) {
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message.translated));
} else if (!m_warning_message.empty()) {
Expand Down Expand Up @@ -329,8 +316,6 @@ OpenWalletActivity::OpenWalletActivity(WalletController* wallet_controller, QWid

void OpenWalletActivity::finish()
{
destroyProgressDialog();

if (!m_error_message.empty()) {
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message.translated));
} else if (!m_warning_message.empty()) {
Expand Down
4 changes: 1 addition & 3 deletions src/qt/walletcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class WalletControllerActivity : public QObject

public:
WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
virtual ~WalletControllerActivity();
virtual ~WalletControllerActivity() = default;

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

void showProgressDialog(const QString& label_text);
void destroyProgressDialog();

WalletController* const m_wallet_controller;
QWidget* const m_parent_widget;
QProgressDialog* m_progress_dialog{nullptr};
WalletModel* m_wallet_model{nullptr};
bilingual_str m_error_message;
std::vector<bilingual_str> m_warning_message;
Expand Down

0 comments on commit f9b633e

Please sign in to comment.