Utils: Make PagedSettings::readSettings() calls shorter

Ideally, this would not be needed on the user code side at all, but
there's no way to ensure the settings are read timing before sibling
constructors might need it. So keep the 'poor man's two-phase
initialization', but make it less intrusive.

Change-Id: Ica7f6510cd05072d7286f4e85cd72c494e8f10f8
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-05-16 13:06:18 +02:00
parent 824de3046c
commit 6c5fb656d6
10 changed files with 16 additions and 15 deletions

View File

@@ -14,7 +14,6 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
@@ -112,7 +111,7 @@ public:
connect(EditorManager::instance(), &EditorManager::aboutToSave, connect(EditorManager::instance(), &EditorManager::aboutToSave,
this, &CMakeFormatterPrivate::applyIfNecessary); this, &CMakeFormatterPrivate::applyIfNecessary);
readSettings(ICore::settings()); readSettings();
} }
bool isApplicable(const IDocument *document) const; bool isApplicable(const IDocument *document) const;

View File

@@ -95,7 +95,7 @@ CMakeSpecificSettings::CMakeSpecificSettings()
showAdvancedOptionsByDefault.setLabelText( showAdvancedOptionsByDefault.setLabelText(
::CMakeProjectManager::Tr::tr("Show advanced options by default")); ::CMakeProjectManager::Tr::tr("Show advanced options by default"));
readSettings(Core::ICore::settings()); readSettings();
} }
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -309,4 +309,9 @@ PagedSettings::PagedSettings()
setAutoApply(false); setAutoApply(false);
} }
void PagedSettings::readSettings()
{
return AspectContainer::readSettings(Core::ICore::settings());
}
} // Core } // Core

View File

@@ -132,6 +132,9 @@ class CORE_EXPORT PagedSettings : public Utils::AspectContainer, public IOptions
{ {
public: public:
PagedSettings(); PagedSettings();
using AspectContainer::readSettings; // FIXME: Remove.
void readSettings(); // Intentionally hides AspectContainer::readSettings()
}; };
} // namespace Core } // namespace Core

View File

@@ -121,7 +121,7 @@ CppcheckOptions::CppcheckOptions()
setLayouter(layouter()); setLayouter(layouter());
readSettings(Core::ICore::settings()); readSettings();
} }
std::function<void(QWidget *widget)> CppcheckOptions::layouter() std::function<void(QWidget *widget)> CppcheckOptions::layouter()

View File

@@ -6,8 +6,6 @@
#include "dockerconstants.h" #include "dockerconstants.h"
#include "dockertr.h" #include "dockertr.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <utils/filepath.h> #include <utils/filepath.h>
@@ -55,7 +53,7 @@ DockerSettings::DockerSettings()
dockerBinaryPath.setLabelText(Tr::tr("Command:")); dockerBinaryPath.setLabelText(Tr::tr("Command:"));
dockerBinaryPath.setSettingsKey("cli"); dockerBinaryPath.setSettingsKey("cli");
readSettings(Core::ICore::settings()); readSettings();
} }
} // Docker::Internal } // Docker::Internal

View File

@@ -92,7 +92,7 @@ NimSettings::NimSettings()
nimSuggestPath.setExpectedKind(PathChooser::ExistingCommand); nimSuggestPath.setExpectedKind(PathChooser::ExistingCommand);
nimSuggestPath.setLabelText(Tr::tr("Path:")); nimSuggestPath.setLabelText(Tr::tr("Path:"));
readSettings(Core::ICore::settings()); readSettings();
} }
NimSettings::~NimSettings() NimSettings::~NimSettings()

View File

@@ -4,8 +4,6 @@
#include "qmakesettings.h" #include "qmakesettings.h"
#include "qmakeprojectmanagertr.h" #include "qmakeprojectmanagertr.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
@@ -63,7 +61,7 @@ QmakeSettings::QmakeSettings()
}.attachTo(widget); }.attachTo(widget);
}); });
readSettings(Core::ICore::settings()); readSettings();
} }
} // QmakeProjectManager::Internal } // QmakeProjectManager::Internal

View File

@@ -5,8 +5,6 @@
#include "vcpkgconstants.h" #include "vcpkgconstants.h"
#include <coreplugin/icore.h>
#include <cmakeprojectmanager/cmakeprojectconstants.h> #include <cmakeprojectmanager/cmakeprojectconstants.h>
#include <utils/aspects.h> #include <utils/aspects.h>
@@ -67,7 +65,7 @@ VcpkgSettings::VcpkgSettings()
vcpkgRoot.setExpectedKind(Utils::PathChooser::ExistingDirectory); vcpkgRoot.setExpectedKind(Utils::PathChooser::ExistingDirectory);
vcpkgRoot.setDefaultValue(Utils::qtcEnvironmentVariable(Constants::ENVVAR_VCPKG_ROOT)); vcpkgRoot.setDefaultValue(Utils::qtcEnvironmentVariable(Constants::ENVVAR_VCPKG_ROOT));
readSettings(Core::ICore::settings()); readSettings();
} }
bool VcpkgSettings::vcpkgRootValid() const bool VcpkgSettings::vcpkgRootValid() const

View File

@@ -57,7 +57,7 @@ namespace VcsBase {
VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseSettings *baseSettings) VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseSettings *baseSettings)
: m_baseSettings(baseSettings) : m_baseSettings(baseSettings)
{ {
m_baseSettings->readSettings(ICore::settings()); m_baseSettings->readSettings();
connect(ICore::instance(), &ICore::saveSettingsRequested, connect(ICore::instance(), &ICore::saveSettingsRequested,
this, &VcsBaseClientImpl::saveSettings); this, &VcsBaseClientImpl::saveSettings);
} }