Skip to content

Commit 1368634

Browse files
committed
Merge #601: refactor: Pass interfaces::Node references to OptionsModel constructor
31122aa refactor: Pass interfaces::Node references to OptionsModel constructor (Ryan Ofsky) Pull request description: Giving OptionsModel access to the node interface is needed as part of #602 to get bitcoind and bitcoin-qt to use the same settings instead of different settings. It has been split off from #602 to simplify that PR. Previously these commits were part of bitcoin/bitcoin#15936 and also had some review discussion there. ACKs for top commit: promag: Code review ACK 31122aa. furszy: Code ACK 31122aa jarolrod: ACK 31122aa Tree-SHA512: b8529322fd7ba97e19864129e6cf5f9acc58c124f2e5a7c50aca15772c8549de3c24e8b0c27e8cf2c06fd26529e9cdb898b0788a1de3cbfdfbdd3f85c9f0fe69
2 parents aa5cd3c + 31122aa commit 1368634

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

src/qt/bitcoin.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void BitcoinApplication::createPaymentServer()
261261

262262
void BitcoinApplication::createOptionsModel(bool resetSettings)
263263
{
264-
optionsModel = new OptionsModel(this, resetSettings);
264+
optionsModel = new OptionsModel(node(), this, resetSettings);
265265
}
266266

267267
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
@@ -292,7 +292,6 @@ void BitcoinApplication::createNode(interfaces::Init& init)
292292
{
293293
assert(!m_node);
294294
m_node = init.makeNode();
295-
if (optionsModel) optionsModel->setNode(*m_node);
296295
if (m_splash) m_splash->setNode(*m_node);
297296
}
298297

@@ -635,6 +634,12 @@ int GuiMain(int argc, char* argv[])
635634
// Allow parameter interaction before we create the options model
636635
app.parameterSetup();
637636
GUIUtil::LogQtInfo();
637+
638+
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
639+
app.createSplashScreen(networkStyle.data());
640+
641+
app.createNode(*init);
642+
638643
// Load GUI settings from QSettings
639644
app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));
640645

@@ -643,11 +648,6 @@ int GuiMain(int argc, char* argv[])
643648
app.InitPruneSetting(prune_MiB);
644649
}
645650

646-
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
647-
app.createSplashScreen(networkStyle.data());
648-
649-
app.createNode(*init);
650-
651651
int rv = EXIT_SUCCESS;
652652
try
653653
{

src/qt/optionsmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
3030

3131
static const QString GetDefaultProxyAddress();
3232

33-
OptionsModel::OptionsModel(QObject *parent, bool resetSettings) :
34-
QAbstractListModel(parent)
33+
OptionsModel::OptionsModel(interfaces::Node& node, QObject *parent, bool resetSettings) :
34+
QAbstractListModel(parent), m_node{node}
3535
{
3636
Init(resetSettings);
3737
}

src/qt/optionsmodel.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class OptionsModel : public QAbstractListModel
4141
Q_OBJECT
4242

4343
public:
44-
explicit OptionsModel(QObject *parent = nullptr, bool resetSettings = false);
44+
explicit OptionsModel(interfaces::Node& node, QObject *parent = nullptr, bool resetSettings = false);
4545

4646
enum OptionID {
4747
StartAtStartup, // bool
@@ -105,11 +105,10 @@ class OptionsModel : public QAbstractListModel
105105
void setRestartRequired(bool fRequired);
106106
bool isRestartRequired() const;
107107

108-
interfaces::Node& node() const { assert(m_node); return *m_node; }
109-
void setNode(interfaces::Node& node) { assert(!m_node); m_node = &node; }
108+
interfaces::Node& node() const { return m_node; }
110109

111110
private:
112-
interfaces::Node* m_node = nullptr;
111+
interfaces::Node& m_node;
113112
/* Qt-only settings */
114113
bool m_show_tray_icon;
115114
bool fMinimizeToTray;

src/qt/test/addressbooktests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
124124

125125
// Initialize relevant QT models.
126126
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
127-
OptionsModel optionsModel;
127+
OptionsModel optionsModel(node);
128128
ClientModel clientModel(node, &optionsModel);
129129
WalletContext& context = *node.walletLoader().context();
130130
AddWallet(context, wallet);

src/qt/test/optiontests.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
#include <univalue.h>
1515

16-
//! Entry point for BitcoinApplication tests.
17-
void OptionTests::optionTests()
16+
void OptionTests::integerGetArgBug()
1817
{
1918
// Test regression https://github.com/bitcoin/bitcoin/issues/24457. Ensure
2019
// that setting integer prune value doesn't cause an exception to be thrown
@@ -24,7 +23,7 @@ void OptionTests::optionTests()
2423
settings.rw_settings["prune"] = 3814;
2524
});
2625
gArgs.WriteSettingsFile();
27-
OptionsModel{};
26+
OptionsModel{m_node};
2827
gArgs.LockSettings([&](util::Settings& settings) {
2928
settings.rw_settings.erase("prune");
3029
});
@@ -49,7 +48,7 @@ void OptionTests::parametersInteraction()
4948
QSettings settings;
5049
settings.setValue("fListen", false);
5150

52-
OptionsModel{};
51+
OptionsModel{m_node};
5352

5453
const bool expected{false};
5554

src/qt/test/optiontests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class OptionTests : public QObject
1616
explicit OptionTests(interfaces::Node& node) : m_node(node) {}
1717

1818
private Q_SLOTS:
19-
void optionTests();
19+
void integerGetArgBug();
2020
void parametersInteraction();
2121

2222
private:

src/qt/test/wallettests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void TestGUI(interfaces::Node& node)
184184
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
185185
SendCoinsDialog sendCoinsDialog(platformStyle.get());
186186
TransactionView transactionView(platformStyle.get());
187-
OptionsModel optionsModel;
187+
OptionsModel optionsModel(node);
188188
ClientModel clientModel(node, &optionsModel);
189189
WalletContext& context = *node.walletLoader().context();
190190
AddWallet(context, wallet);

0 commit comments

Comments
 (0)