From 7d0d4c04903cafade32be3bf2bf1cad3f33c6c03 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 11 Aug 2021 19:50:12 +0300 Subject: [PATCH 1/4] qt: Add WalletFrame::currentWalletSet signal The connection of the WalletFrame::currentWalletSet signal to the BitcoinGUI::updateWalletStatus is a shorter and more descriptive way to call both the setHDStatus and setEncryptionStatus member functions of the BitcoinGUI class in comparison to using of the WalletView::updateEncryptionStatus slot. --- src/qt/bitcoingui.cpp | 1 + src/qt/walletframe.cpp | 3 ++- src/qt/walletframe.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index fe606519afe..61d8be62d7b 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -113,6 +113,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) { this->message(title, message, style); }); + connect(walletFrame, &WalletFrame::currentWalletSet, [this] { updateWalletStatus(); }); setCentralWidget(walletFrame); } else #endif // ENABLE_WALLET diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 3d8bc0c7c59..30c29eb3565 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -109,7 +109,8 @@ void WalletFrame::setCurrentWallet(WalletModel* wallet_model) walletView->updateGeometry(); walletStack->setCurrentWidget(walletView); - walletView->updateEncryptionStatus(); + + Q_EMIT currentWalletSet(); } void WalletFrame::removeWallet(WalletModel* wallet_model) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index fe42293abc1..cbf6af95ec0 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -49,6 +49,7 @@ class WalletFrame : public QFrame Q_SIGNALS: void createWalletButtonClicked(); void message(const QString& title, const QString& message, unsigned int style); + void currentWalletSet(); private: QStackedWidget *walletStack; From 37dcf161d3dd1f7862a67bec1e8f2887cbd6de90 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 11 Aug 2021 19:57:10 +0300 Subject: [PATCH 2/4] qt, refactor: Emit WalletView::encryptionStatusChanged signal directly --- src/qt/walletview.cpp | 9 ++------- src/qt/walletview.h | 3 --- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 2326af80b6e..725015a4478 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -118,7 +118,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) // Handle changes in encryption status connect(_walletModel, &WalletModel::encryptionStatusChanged, this, &WalletView::encryptionStatusChanged); - updateEncryptionStatus(); + Q_EMIT encryptionStatusChanged(); // update HD status Q_EMIT hdEnabledStatusChanged(); @@ -211,11 +211,6 @@ void WalletView::showOutOfSyncWarning(bool fShow) overviewPage->showOutOfSyncWarning(fShow); } -void WalletView::updateEncryptionStatus() -{ - Q_EMIT encryptionStatusChanged(); -} - void WalletView::encryptWallet() { if(!walletModel) @@ -224,7 +219,7 @@ void WalletView::encryptWallet() dlg.setModel(walletModel); dlg.exec(); - updateEncryptionStatus(); + Q_EMIT encryptionStatusChanged(); } void WalletView::backupWallet() diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 5c42a9ffc08..5d2fac425e0 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -103,9 +103,6 @@ public Q_SLOTS: /** Show used receiving addresses */ void usedReceivingAddresses(); - /** Re-emit encryption status signal */ - void updateEncryptionStatus(); - /** Show progress dialog e.g. for rescan */ void showProgress(const QString &title, int nProgress); From fcdc8b0fcb9dc81b76289abc57a4203671f748eb Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 11 Aug 2021 20:08:39 +0300 Subject: [PATCH 3/4] qt, refactor: Drop redundant signalling in WalletView::setWalletModel This job will be done by WalletFrame::currentWalletSet signal being emitted in the WalletFrame::setCurrentWallet function. --- src/qt/bitcoingui.cpp | 1 - src/qt/walletview.cpp | 4 ---- src/qt/walletview.h | 2 -- 3 files changed, 7 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 61d8be62d7b..21bbe791825 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -695,7 +695,6 @@ void BitcoinGUI::addWallet(WalletModel* walletModel) }); connect(wallet_view, &WalletView::encryptionStatusChanged, this, &BitcoinGUI::updateWalletStatus); connect(wallet_view, &WalletView::incomingTransaction, this, &BitcoinGUI::incomingTransaction); - connect(wallet_view, &WalletView::hdEnabledStatusChanged, this, &BitcoinGUI::updateWalletStatus); connect(this, &BitcoinGUI::setPrivacy, wallet_view, &WalletView::setPrivacy); wallet_view->setPrivacy(isPrivacyModeActivated()); const QString display_name = walletModel->getDisplayName(); diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 725015a4478..7e96e85c0c3 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -118,10 +118,6 @@ void WalletView::setWalletModel(WalletModel *_walletModel) // Handle changes in encryption status connect(_walletModel, &WalletModel::encryptionStatusChanged, this, &WalletView::encryptionStatusChanged); - Q_EMIT encryptionStatusChanged(); - - // update HD status - Q_EMIT hdEnabledStatusChanged(); // Balloon pop-up for new transaction connect(_walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction); diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 5d2fac425e0..bb6ad0f69ef 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -114,8 +114,6 @@ public Q_SLOTS: void message(const QString &title, const QString &message, unsigned int style); /** Encryption status of wallet changed */ void encryptionStatusChanged(); - /** HD-Enabled status of wallet changed (only possible during startup) */ - void hdEnabledStatusChanged(); /** Notify that a new transaction appeared */ void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName); /** Notify that the out of sync warning icon has been pressed */ From b8aa84b1a116599a6dd3b9ddb4e6c178a6688b1b Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 11 Aug 2021 20:30:49 +0300 Subject: [PATCH 4/4] qt, refactor: Replace `if` check with `assert` There are no ways BitcoinGUI::updateWalletStatus being called without an instance of the WalletFrame class. --- src/qt/bitcoingui.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 21bbe791825..f30dd92e615 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1340,9 +1340,8 @@ void BitcoinGUI::setEncryptionStatus(int status) void BitcoinGUI::updateWalletStatus() { - if (!walletFrame) { - return; - } + assert(walletFrame); + WalletView * const walletView = walletFrame->currentWalletView(); if (!walletView) { return;