Skip to content

Commit 945e467

Browse files
committed
refactor: Remove SplashScreen::setNode method
Make m_node a reference instead of pointer, now that it can no longer be null, as suggested bitcoin/bitcoin#15936 (comment)
1 parent aa2817b commit 945e467

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

src/qt/bitcoin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
280280
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
281281
{
282282
assert(!m_splash);
283-
m_splash = new SplashScreen(networkStyle);
284-
m_splash->setNode(node());
283+
m_splash = new SplashScreen(node(), networkStyle);
285284
// We don't hold a direct pointer to the splash screen after creation, but the splash
286285
// screen will take care of deleting itself when finish() happens.
287286
m_splash->show();

src/qt/splashscreen.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <QScreen>
2828

2929

30-
SplashScreen::SplashScreen(const NetworkStyle* networkStyle)
31-
: QWidget(), curAlignment(0)
30+
SplashScreen::SplashScreen(interfaces::Node& node, const NetworkStyle* networkStyle)
31+
: QWidget(), curAlignment(0), m_node{node}
3232
{
3333
// set reference point, paddings
3434
int paddingRight = 50;
@@ -130,25 +130,19 @@ SplashScreen::SplashScreen(const NetworkStyle* networkStyle)
130130
installEventFilter(this);
131131

132132
GUIUtil::handleCloseWindowShortcut(this);
133-
}
134133

135-
SplashScreen::~SplashScreen()
136-
{
137-
if (m_node) unsubscribeFromCoreSignals();
134+
subscribeToCoreSignals();
138135
}
139136

140-
void SplashScreen::setNode(interfaces::Node& node)
137+
SplashScreen::~SplashScreen()
141138
{
142-
assert(!m_node);
143-
m_node = &node;
144-
subscribeToCoreSignals();
145-
if (m_shutdown) m_node->startShutdown();
139+
unsubscribeFromCoreSignals();
146140
}
147141

148142
void SplashScreen::shutdown()
149143
{
150144
m_shutdown = true;
151-
if (m_node) m_node->startShutdown();
145+
m_node.startShutdown();
152146
}
153147

154148
bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) {
@@ -192,16 +186,16 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
192186
void SplashScreen::subscribeToCoreSignals()
193187
{
194188
// Connect signals to client
195-
m_handler_init_message = m_node->handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
196-
m_handler_show_progress = m_node->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
197-
m_handler_init_wallet = m_node->handleInitWallet([this]() { handleLoadWallet(); });
189+
m_handler_init_message = m_node.handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
190+
m_handler_show_progress = m_node.handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
191+
m_handler_init_wallet = m_node.handleInitWallet([this]() { handleLoadWallet(); });
198192
}
199193

200194
void SplashScreen::handleLoadWallet()
201195
{
202196
#ifdef ENABLE_WALLET
203197
if (!WalletModel::isWalletEnabled()) return;
204-
m_handler_load_wallet = m_node->walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
198+
m_handler_load_wallet = m_node.walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
205199
m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, false)));
206200
m_connected_wallets.emplace_back(std::move(wallet));
207201
});

src/qt/splashscreen.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ class SplashScreen : public QWidget
2828
Q_OBJECT
2929

3030
public:
31-
explicit SplashScreen(const NetworkStyle *networkStyle);
31+
explicit SplashScreen(interfaces::Node& node, const NetworkStyle* networkStyle);
3232
~SplashScreen();
33-
void setNode(interfaces::Node& node);
3433

3534
protected:
3635
void paintEvent(QPaintEvent *event) override;
@@ -62,7 +61,7 @@ public Q_SLOTS:
6261
QColor curColor;
6362
int curAlignment;
6463

65-
interfaces::Node* m_node = nullptr;
64+
interfaces::Node& m_node;
6665
bool m_shutdown = false;
6766
std::unique_ptr<interfaces::Handler> m_handler_init_message;
6867
std::unique_ptr<interfaces::Handler> m_handler_show_progress;

0 commit comments

Comments
 (0)