Merge bitcoin-core/gui#601: refactor: Pass interfaces::Node references to OptionsModel constructor

31122aa979 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 31122aa979.
  furszy:
    Code ACK 31122aa9
  jarolrod:
    ACK 31122aa979

Tree-SHA512: b8529322fd7ba97e19864129e6cf5f9acc58c124f2e5a7c50aca15772c8549de3c24e8b0c27e8cf2c06fd26529e9cdb898b0788a1de3cbfdfbdd3f85c9f0fe69
This commit is contained in:
Hennadii Stepanov 2022-05-24 10:36:52 +02:00
commit 1368634433
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
7 changed files with 18 additions and 20 deletions

View file

@ -261,7 +261,7 @@ void BitcoinApplication::createPaymentServer()
void BitcoinApplication::createOptionsModel(bool resetSettings) void BitcoinApplication::createOptionsModel(bool resetSettings)
{ {
optionsModel = new OptionsModel(this, resetSettings); optionsModel = new OptionsModel(node(), this, resetSettings);
} }
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
@ -292,7 +292,6 @@ void BitcoinApplication::createNode(interfaces::Init& init)
{ {
assert(!m_node); assert(!m_node);
m_node = init.makeNode(); m_node = init.makeNode();
if (optionsModel) optionsModel->setNode(*m_node);
if (m_splash) m_splash->setNode(*m_node); if (m_splash) m_splash->setNode(*m_node);
} }
@ -635,6 +634,12 @@ int GuiMain(int argc, char* argv[])
// Allow parameter interaction before we create the options model // Allow parameter interaction before we create the options model
app.parameterSetup(); app.parameterSetup();
GUIUtil::LogQtInfo(); GUIUtil::LogQtInfo();
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
app.createSplashScreen(networkStyle.data());
app.createNode(*init);
// Load GUI settings from QSettings // Load GUI settings from QSettings
app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false)); app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));
@ -643,11 +648,6 @@ int GuiMain(int argc, char* argv[])
app.InitPruneSetting(prune_MiB); app.InitPruneSetting(prune_MiB);
} }
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
app.createSplashScreen(networkStyle.data());
app.createNode(*init);
int rv = EXIT_SUCCESS; int rv = EXIT_SUCCESS;
try try
{ {

View file

@ -30,8 +30,8 @@ const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
static const QString GetDefaultProxyAddress(); static const QString GetDefaultProxyAddress();
OptionsModel::OptionsModel(QObject *parent, bool resetSettings) : OptionsModel::OptionsModel(interfaces::Node& node, QObject *parent, bool resetSettings) :
QAbstractListModel(parent) QAbstractListModel(parent), m_node{node}
{ {
Init(resetSettings); Init(resetSettings);
} }

View file

@ -41,7 +41,7 @@ class OptionsModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
public: public:
explicit OptionsModel(QObject *parent = nullptr, bool resetSettings = false); explicit OptionsModel(interfaces::Node& node, QObject *parent = nullptr, bool resetSettings = false);
enum OptionID { enum OptionID {
StartAtStartup, // bool StartAtStartup, // bool
@ -105,11 +105,10 @@ public:
void setRestartRequired(bool fRequired); void setRestartRequired(bool fRequired);
bool isRestartRequired() const; bool isRestartRequired() const;
interfaces::Node& node() const { assert(m_node); return *m_node; } interfaces::Node& node() const { return m_node; }
void setNode(interfaces::Node& node) { assert(!m_node); m_node = &node; }
private: private:
interfaces::Node* m_node = nullptr; interfaces::Node& m_node;
/* Qt-only settings */ /* Qt-only settings */
bool m_show_tray_icon; bool m_show_tray_icon;
bool fMinimizeToTray; bool fMinimizeToTray;

View file

@ -124,7 +124,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
// Initialize relevant QT models. // Initialize relevant QT models.
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other")); std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
OptionsModel optionsModel; OptionsModel optionsModel(node);
ClientModel clientModel(node, &optionsModel); ClientModel clientModel(node, &optionsModel);
WalletContext& context = *node.walletLoader().context(); WalletContext& context = *node.walletLoader().context();
AddWallet(context, wallet); AddWallet(context, wallet);

View file

@ -13,8 +13,7 @@
#include <univalue.h> #include <univalue.h>
//! Entry point for BitcoinApplication tests. void OptionTests::integerGetArgBug()
void OptionTests::optionTests()
{ {
// Test regression https://github.com/bitcoin/bitcoin/issues/24457. Ensure // Test regression https://github.com/bitcoin/bitcoin/issues/24457. Ensure
// that setting integer prune value doesn't cause an exception to be thrown // that setting integer prune value doesn't cause an exception to be thrown
@ -24,7 +23,7 @@ void OptionTests::optionTests()
settings.rw_settings["prune"] = 3814; settings.rw_settings["prune"] = 3814;
}); });
gArgs.WriteSettingsFile(); gArgs.WriteSettingsFile();
OptionsModel{}; OptionsModel{m_node};
gArgs.LockSettings([&](util::Settings& settings) { gArgs.LockSettings([&](util::Settings& settings) {
settings.rw_settings.erase("prune"); settings.rw_settings.erase("prune");
}); });
@ -49,7 +48,7 @@ void OptionTests::parametersInteraction()
QSettings settings; QSettings settings;
settings.setValue("fListen", false); settings.setValue("fListen", false);
OptionsModel{}; OptionsModel{m_node};
const bool expected{false}; const bool expected{false};

View file

@ -16,7 +16,7 @@ public:
explicit OptionTests(interfaces::Node& node) : m_node(node) {} explicit OptionTests(interfaces::Node& node) : m_node(node) {}
private Q_SLOTS: private Q_SLOTS:
void optionTests(); void integerGetArgBug();
void parametersInteraction(); void parametersInteraction();
private: private:

View file

@ -184,7 +184,7 @@ void TestGUI(interfaces::Node& node)
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other")); std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
SendCoinsDialog sendCoinsDialog(platformStyle.get()); SendCoinsDialog sendCoinsDialog(platformStyle.get());
TransactionView transactionView(platformStyle.get()); TransactionView transactionView(platformStyle.get());
OptionsModel optionsModel; OptionsModel optionsModel(node);
ClientModel clientModel(node, &optionsModel); ClientModel clientModel(node, &optionsModel);
WalletContext& context = *node.walletLoader().context(); WalletContext& context = *node.walletLoader().context();
AddWallet(context, wallet); AddWallet(context, wallet);