It turns out that now this is the only place where the constructor of SplashScreen is called and it is immediately followed by an unconditional call to setNode(). So it would be better to pass the node to the constructor and ditch the setNode() method. This also allows to make the SplashSceen::m_node member a reference, so that it is obvious that it will always be initialized.
Here is a diff to amend into f384d4d9350f94043518d1cba98f4054cd54b325 refactor: Pass interfaces::Node references to OptionsModel constructor or maybe that deserves a separate commit or maybe even a followup PR:
<details>
<summary>diff</summary>
diff --git i/src/qt/bitcoin.cpp w/src/qt/bitcoin.cpp
index 324f1c7ce0..ad6a7a129d 100644
--- i/src/qt/bitcoin.cpp
+++ w/src/qt/bitcoin.cpp
@@ -292,14 +292,13 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
});
}
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
assert(!m_splash);
- m_splash = new SplashScreen(networkStyle);
- m_splash->setNode(node());
+ m_splash = new SplashScreen(node(), networkStyle);
// We don't hold a direct pointer to the splash screen after creation, but the splash
// screen will take care of deleting itself when finish() happens.
m_splash->show();
connect(this, &BitcoinApplication::splashFinished, m_splash, &SplashScreen::finish);
connect(this, &BitcoinApplication::requestedShutdown, m_splash, &QWidget::close);
}
diff --git i/src/qt/splashscreen.cpp w/src/qt/splashscreen.cpp
index a4dfffa387..de99e36ad0 100644
--- i/src/qt/splashscreen.cpp
+++ w/src/qt/splashscreen.cpp
@@ -24,14 +24,14 @@
#include <QCloseEvent>
#include <QPainter>
#include <QRadialGradient>
#include <QScreen>
-SplashScreen::SplashScreen(const NetworkStyle* networkStyle)
- : QWidget(), curAlignment(0)
+SplashScreen::SplashScreen(interfaces::Node& node, const NetworkStyle* networkStyle)
+ : QWidget(), curAlignment(0), m_node{node}
{
// set reference point, paddings
int paddingRight = 50;
int paddingTop = 50;
int titleVersionVSpace = 17;
int titleCopyrightVSpace = 40;
@@ -127,31 +127,25 @@ SplashScreen::SplashScreen(const NetworkStyle* networkStyle)
setFixedSize(r.size());
move(QGuiApplication::primaryScreen()->geometry().center() - r.center());
installEventFilter(this);
GUIUtil::handleCloseWindowShortcut(this);
-}
-SplashScreen::~SplashScreen()
-{
- if (m_node) unsubscribeFromCoreSignals();
+ subscribeToCoreSignals();
}
-void SplashScreen::setNode(interfaces::Node& node)
+SplashScreen::~SplashScreen()
{
- assert(!m_node);
- m_node = &node;
- subscribeToCoreSignals();
- if (m_shutdown) m_node->startShutdown();
+ unsubscribeFromCoreSignals();
}
void SplashScreen::shutdown()
{
m_shutdown = true;
- if (m_node) m_node->startShutdown();
+ m_node.startShutdown();
}
bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) {
if (ev->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
if (keyEvent->key() == Qt::Key_Q) {
@@ -189,22 +183,22 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
strprintf("\n%d", nProgress) + "%");
}
void SplashScreen::subscribeToCoreSignals()
{
// Connect signals to client
- m_handler_init_message = m_node->handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
- m_handler_show_progress = m_node->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
- m_handler_init_wallet = m_node->handleInitWallet([this]() { handleLoadWallet(); });
+ m_handler_init_message = m_node.handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
+ m_handler_show_progress = m_node.handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
+ m_handler_init_wallet = m_node.handleInitWallet([this]() { handleLoadWallet(); });
}
void SplashScreen::handleLoadWallet()
{
#ifdef ENABLE_WALLET
if (!WalletModel::isWalletEnabled()) return;
- m_handler_load_wallet = m_node->walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
+ m_handler_load_wallet = m_node.walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, false)));
m_connected_wallets.emplace_back(std::move(wallet));
});
#endif
}
diff --git i/src/qt/splashscreen.h w/src/qt/splashscreen.h
index c14fc521a7..e9879e835b 100644
--- i/src/qt/splashscreen.h
+++ w/src/qt/splashscreen.h
@@ -25,15 +25,14 @@ class Wallet;
*/
class SplashScreen : public QWidget
{
Q_OBJECT
public:
- explicit SplashScreen(const NetworkStyle *networkStyle);
+ explicit SplashScreen(interfaces::Node& node, const NetworkStyle* networkStyle);
~SplashScreen();
- void setNode(interfaces::Node& node);
protected:
void paintEvent(QPaintEvent *event) override;
void closeEvent(QCloseEvent *event) override;
public Q_SLOTS:
@@ -59,13 +58,13 @@ private:
QPixmap pixmap;
QString curMessage;
QColor curColor;
int curAlignment;
- interfaces::Node* m_node = nullptr;
+ interfaces::Node& m_node;
bool m_shutdown = false;
std::unique_ptr<interfaces::Handler> m_handler_init_message;
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
std::unique_ptr<interfaces::Handler> m_handler_init_wallet;
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
std::list<std::unique_ptr<interfaces::Wallet>> m_connected_wallets;
</details>