Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Optimize signal-slot connections logic #29

Merged
merged 3 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
{
/** Create wallet frame and make it the central widget */
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);
} else
#endif // ENABLE_WALLET
Expand Down Expand Up @@ -670,7 +675,10 @@ WalletController* BitcoinGUI::getWalletController()
void BitcoinGUI::addWallet(WalletModel* walletModel)
{
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);
if (m_wallet_selector->count() == 0) {
setWalletActionsEnabled(true);
Expand All @@ -680,6 +688,18 @@ void BitcoinGUI::addWallet(WalletModel* walletModel)
}
const QString display_name = walletModel->getDisplayName();
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));

connect(wallet_view, &WalletView::outOfSyncWarningClicked, walletFrame, &WalletFrame::outOfSyncWarningClicked);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, maybe this should stay in WalletFrame?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing in this way keeps compatibility with #333.

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)
Expand Down
31 changes: 5 additions & 26 deletions src/qt/walletframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

#include <qt/walletframe.h>

#include <qt/bitcoingui.h>
#include <qt/createwalletdialog.h>
#include <qt/overviewpage.h>
#include <qt/walletcontroller.h>
#include <qt/walletmodel.h>
#include <qt/walletview.h>

Expand All @@ -19,9 +16,8 @@
#include <QPushButton>
#include <QVBoxLayout>

WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, BitcoinGUI* _gui)
: QFrame(_gui),
gui(_gui),
WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, QWidget* parent)
: QFrame(parent),
platformStyle(_platformStyle),
m_size_hint(OverviewPage{platformStyle, nullptr}.sizeHint())
{
Expand All @@ -42,11 +38,7 @@ WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, BitcoinGUI* _gui)

// A button for create wallet dialog
QPushButton* create_wallet_button = new QPushButton(tr("Create a new wallet"), walletStack);
connect(create_wallet_button, &QPushButton::clicked, [this] {
auto activity = new CreateWalletActivity(gui->getWalletController(), this);
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
activity->create();
});
connect(create_wallet_button, &QPushButton::clicked, this, &WalletFrame::createWalletButtonClicked);
no_wallet_layout->addWidget(create_wallet_button, 0, Qt::AlignHCenter | Qt::AlignTop);
no_wallet_group->setLayout(no_wallet_layout);

Expand All @@ -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;

WalletView *walletView = new WalletView(platformStyle, this);
walletView->setClientModel(clientModel);
walletView->setWalletModel(walletModel);
walletView->showOutOfSyncWarning(bOutOfSync);
walletView->setPrivacy(gui->isPrivacyModeActivated());

WalletView* current_wallet_view = currentWalletView();
if (current_wallet_view) {
Expand All @@ -88,17 +78,6 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
walletStack->addWidget(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;
}

Expand Down
8 changes: 4 additions & 4 deletions src/qt/walletframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <QFrame>
#include <QMap>

class BitcoinGUI;
class ClientModel;
class PlatformStyle;
class SendCoinsRecipient;
Expand All @@ -31,12 +30,12 @@ class WalletFrame : public QFrame
Q_OBJECT

public:
explicit WalletFrame(const PlatformStyle *platformStyle, BitcoinGUI *_gui = nullptr);
explicit WalletFrame(const PlatformStyle* platformStyle, QWidget* parent);
~WalletFrame();

void setClientModel(ClientModel *clientModel);

bool addWallet(WalletModel *walletModel);
bool addWallet(WalletModel* walletModel, WalletView* walletView);
void setCurrentWallet(WalletModel* wallet_model);
void removeWallet(WalletModel* wallet_model);
void removeAllWallets();
Expand All @@ -51,9 +50,10 @@ class WalletFrame : public QFrame
/** Notify that the user has requested more information about the out-of-sync warning */
void requestedSyncWarningInfo();

void createWalletButtonClicked();

private:
QStackedWidget *walletStack;
BitcoinGUI *gui;
ClientModel *clientModel;
QMap<WalletModel*, WalletView*> mapWalletViews;

Expand Down
1 change: 0 additions & 1 deletion test/lint/lint-circular-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"index/coinstatsindex -> node/coinstats -> index/coinstatsindex"
"policy/fees -> txmempool -> policy/fees"
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel"
"qt/bitcoingui -> qt/walletframe -> qt/bitcoingui"
"qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel"
"qt/sendcoinsdialog -> qt/walletmodel -> qt/sendcoinsdialog"
"qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel"
Expand Down