Merge bitcoin-core/gui#29: refactor: Optimize signal-slot connections logic

62cb8d98d2 qt: Drop BitcoinGUI* WalletFrame data member (Hennadii Stepanov)
f73e5c972a qt: Move CreateWalletActivity connection from WalletFrame to BitcoinGUI (Hennadii Stepanov)
20e2e24e90 qt: Move WalletView connections from WalletFrame to BitcoinGUI (Hennadii Stepanov)

Pull request description:

  This PR:
  - implements an idea from https://github.com/bitcoin/bitcoin/pull/17937#issuecomment-575991765
  - simplifies `WalletFrame` class interface
  - as a side effect, removes `bitcoingui` -> `walletframe` -> `bitcoingui` circular dependency
  - is an alternative to https://github.com/bitcoin/bitcoin/pull/17500

ACKs for top commit:
  promag:
    Tested ACK 62cb8d98d2 on macos 11.2.3 with depends build.
  jarolrod:
    ACK 62cb8d98d2

Tree-SHA512: 633b526a8499ba9ab4b16928daf4de4f6d610284bb9fa51891cad35300a03bde740df3466a71b46e87a62121330fcc9e606eac7666ea5e45fa6d5785b60dcbbd
This commit is contained in:
Hennadii Stepanov 2021-06-06 01:00:39 +03:00
commit e033ca1379
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
4 changed files with 30 additions and 32 deletions

View File

@ -105,6 +105,11 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
{ {
/** Create wallet frame and make it the central widget */ /** Create wallet frame and make it the central widget */
walletFrame = new WalletFrame(_platformStyle, this); walletFrame = new WalletFrame(_platformStyle, this);
connect(walletFrame, &WalletFrame::createWalletButtonClicked, [this] {
auto activity = new CreateWalletActivity(getWalletController(), this);
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
activity->create();
});
setCentralWidget(walletFrame); setCentralWidget(walletFrame);
} else } else
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
@ -671,7 +676,10 @@ WalletController* BitcoinGUI::getWalletController()
void BitcoinGUI::addWallet(WalletModel* walletModel) void BitcoinGUI::addWallet(WalletModel* walletModel)
{ {
if (!walletFrame) return; if (!walletFrame) return;
if (!walletFrame->addWallet(walletModel)) return;
WalletView* wallet_view = new WalletView(platformStyle, walletFrame);
if (!walletFrame->addWallet(walletModel, wallet_view)) return;
rpcConsole->addWallet(walletModel); rpcConsole->addWallet(walletModel);
if (m_wallet_selector->count() == 0) { if (m_wallet_selector->count() == 0) {
setWalletActionsEnabled(true); setWalletActionsEnabled(true);
@ -681,6 +689,18 @@ void BitcoinGUI::addWallet(WalletModel* walletModel)
} }
const QString display_name = walletModel->getDisplayName(); const QString display_name = walletModel->getDisplayName();
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel)); m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
connect(wallet_view, &WalletView::outOfSyncWarningClicked, walletFrame, &WalletFrame::outOfSyncWarningClicked);
connect(wallet_view, &WalletView::transactionClicked, this, &BitcoinGUI::gotoHistoryPage);
connect(wallet_view, &WalletView::coinsSent, this, &BitcoinGUI::gotoHistoryPage);
connect(wallet_view, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
this->message(title, message, style);
});
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());
} }
void BitcoinGUI::removeWallet(WalletModel* walletModel) void BitcoinGUI::removeWallet(WalletModel* walletModel)

View File

@ -4,10 +4,7 @@
#include <qt/walletframe.h> #include <qt/walletframe.h>
#include <qt/bitcoingui.h>
#include <qt/createwalletdialog.h>
#include <qt/overviewpage.h> #include <qt/overviewpage.h>
#include <qt/walletcontroller.h>
#include <qt/walletmodel.h> #include <qt/walletmodel.h>
#include <qt/walletview.h> #include <qt/walletview.h>
@ -19,9 +16,8 @@
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, BitcoinGUI* _gui) WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, QWidget* parent)
: QFrame(_gui), : QFrame(parent),
gui(_gui),
platformStyle(_platformStyle), platformStyle(_platformStyle),
m_size_hint(OverviewPage{platformStyle, nullptr}.sizeHint()) m_size_hint(OverviewPage{platformStyle, nullptr}.sizeHint())
{ {
@ -42,11 +38,7 @@ WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, BitcoinGUI* _gui)
// A button for create wallet dialog // A button for create wallet dialog
QPushButton* create_wallet_button = new QPushButton(tr("Create a new wallet"), walletStack); QPushButton* create_wallet_button = new QPushButton(tr("Create a new wallet"), walletStack);
connect(create_wallet_button, &QPushButton::clicked, [this] { connect(create_wallet_button, &QPushButton::clicked, this, &WalletFrame::createWalletButtonClicked);
auto activity = new CreateWalletActivity(gui->getWalletController(), this);
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
activity->create();
});
no_wallet_layout->addWidget(create_wallet_button, 0, Qt::AlignHCenter | Qt::AlignTop); no_wallet_layout->addWidget(create_wallet_button, 0, Qt::AlignHCenter | Qt::AlignTop);
no_wallet_group->setLayout(no_wallet_layout); no_wallet_group->setLayout(no_wallet_layout);
@ -66,17 +58,15 @@ void WalletFrame::setClientModel(ClientModel *_clientModel)
} }
} }
bool WalletFrame::addWallet(WalletModel *walletModel) bool WalletFrame::addWallet(WalletModel* walletModel, WalletView* walletView)
{ {
if (!gui || !clientModel || !walletModel) return false; if (!clientModel || !walletModel) return false;
if (mapWalletViews.count(walletModel) > 0) return false; if (mapWalletViews.count(walletModel) > 0) return false;
WalletView *walletView = new WalletView(platformStyle, this);
walletView->setClientModel(clientModel); walletView->setClientModel(clientModel);
walletView->setWalletModel(walletModel); walletView->setWalletModel(walletModel);
walletView->showOutOfSyncWarning(bOutOfSync); walletView->showOutOfSyncWarning(bOutOfSync);
walletView->setPrivacy(gui->isPrivacyModeActivated());
WalletView* current_wallet_view = currentWalletView(); WalletView* current_wallet_view = currentWalletView();
if (current_wallet_view) { if (current_wallet_view) {
@ -88,17 +78,6 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
walletStack->addWidget(walletView); walletStack->addWidget(walletView);
mapWalletViews[walletModel] = walletView; mapWalletViews[walletModel] = walletView;
connect(walletView, &WalletView::outOfSyncWarningClicked, this, &WalletFrame::outOfSyncWarningClicked);
connect(walletView, &WalletView::transactionClicked, gui, &BitcoinGUI::gotoHistoryPage);
connect(walletView, &WalletView::coinsSent, gui, &BitcoinGUI::gotoHistoryPage);
connect(walletView, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
gui->message(title, message, style);
});
connect(walletView, &WalletView::encryptionStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
connect(walletView, &WalletView::incomingTransaction, gui, &BitcoinGUI::incomingTransaction);
connect(walletView, &WalletView::hdEnabledStatusChanged, gui, &BitcoinGUI::updateWalletStatus);
connect(gui, &BitcoinGUI::setPrivacy, walletView, &WalletView::setPrivacy);
return true; return true;
} }

View File

@ -8,7 +8,6 @@
#include <QFrame> #include <QFrame>
#include <QMap> #include <QMap>
class BitcoinGUI;
class ClientModel; class ClientModel;
class PlatformStyle; class PlatformStyle;
class SendCoinsRecipient; class SendCoinsRecipient;
@ -31,12 +30,12 @@ class WalletFrame : public QFrame
Q_OBJECT Q_OBJECT
public: public:
explicit WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui = nullptr); explicit WalletFrame(const PlatformStyle* platformStyle, QWidget* parent);
~WalletFrame(); ~WalletFrame();
void setClientModel(ClientModel *clientModel); void setClientModel(ClientModel *clientModel);
bool addWallet(WalletModel *walletModel); bool addWallet(WalletModel* walletModel, WalletView* walletView);
void setCurrentWallet(WalletModel* wallet_model); void setCurrentWallet(WalletModel* wallet_model);
void removeWallet(WalletModel* wallet_model); void removeWallet(WalletModel* wallet_model);
void removeAllWallets(); void removeAllWallets();
@ -51,9 +50,10 @@ Q_SIGNALS:
/** Notify that the user has requested more information about the out-of-sync warning */ /** Notify that the user has requested more information about the out-of-sync warning */
void requestedSyncWarningInfo(); void requestedSyncWarningInfo();
void createWalletButtonClicked();
private: private:
QStackedWidget *walletStack; QStackedWidget *walletStack;
BitcoinGUI *gui;
ClientModel *clientModel; ClientModel *clientModel;
QMap<WalletModel*, WalletView*> mapWalletViews; QMap<WalletModel*, WalletView*> mapWalletViews;

View File

@ -17,7 +17,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"index/coinstatsindex -> node/coinstats -> index/coinstatsindex" "index/coinstatsindex -> node/coinstats -> index/coinstatsindex"
"policy/fees -> txmempool -> policy/fees" "policy/fees -> txmempool -> policy/fees"
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel" "qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel"
"qt/bitcoingui -> qt/walletframe -> qt/bitcoingui"
"qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel" "qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel"
"qt/sendcoinsdialog -> qt/walletmodel -> qt/sendcoinsdialog" "qt/sendcoinsdialog -> qt/walletmodel -> qt/sendcoinsdialog"
"qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel" "qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel"