Refactor settings to be managed by singletons

This commit is contained in:
Dan Paulat 2023-10-05 21:55:43 -05:00
parent acc782b2bc
commit b66ca2cb09
21 changed files with 138 additions and 133 deletions

View file

@ -16,10 +16,10 @@ namespace settings
static const std::string logPrefix_ = "scwx::qt::settings::general_settings";
class GeneralSettingsImpl
class GeneralSettings::Impl
{
public:
explicit GeneralSettingsImpl()
explicit Impl()
{
std::string defaultDefaultAlertActionValue =
types::GetAlertActionName(types::AlertAction::Go);
@ -102,7 +102,7 @@ public:
{ return !value.empty(); });
}
~GeneralSettingsImpl() {}
~Impl() {}
SettingsVariable<bool> debugEnabled_ {"debug_enabled"};
SettingsVariable<std::string> defaultAlertAction_ {"default_alert_action"};
@ -120,7 +120,7 @@ public:
};
GeneralSettings::GeneralSettings() :
SettingsCategory("general"), p(std::make_unique<GeneralSettingsImpl>())
SettingsCategory("general"), p(std::make_unique<Impl>())
{
RegisterVariables({&p->debugEnabled_,
&p->defaultAlertAction_,
@ -221,6 +221,12 @@ bool GeneralSettings::Shutdown()
return dataChanged;
}
GeneralSettings& GeneralSettings::Instance()
{
static GeneralSettings generalSettings_;
return generalSettings_;
}
bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs)
{
return (lhs.p->debugEnabled_ == rhs.p->debugEnabled_ &&