1
1
Fork 0
forked from suyu/suyu

config(qt): Fix generic read setting

Previously was not respecting whether the setting was default.
This commit is contained in:
lat9nq 2023-07-29 13:23:06 -04:00
parent 397333b2d5
commit 05c8063ac1

View file

@ -1256,23 +1256,27 @@ void Config::WriteCategory(Settings::Category category) {
} }
void Config::ReadSettingGeneric(Settings::BasicSetting* const setting) { void Config::ReadSettingGeneric(Settings::BasicSetting* const setting) {
if (!setting->Save()) { if (!setting->Save() || (!setting->Switchable() && !global)) {
return; return;
} }
const QString name = QString::fromStdString(setting->GetLabel()); const QString name = QString::fromStdString(setting->GetLabel());
const auto default_value = const auto default_value =
QVariant::fromValue<QString>(QString::fromStdString(setting->DefaultToString())); QVariant::fromValue<QString>(QString::fromStdString(setting->DefaultToString()));
if (setting->Switchable()) { bool use_global = true;
const bool use_global = if (setting->Switchable() && !global) {
qt_config->value(name + QStringLiteral("/use_global"), true).value<bool>(); use_global = qt_config->value(name + QStringLiteral("/use_global"), true).value<bool>();
setting->SetGlobal(use_global); setting->SetGlobal(use_global);
}
if (global || !use_global) { if (global || !use_global) {
const bool is_default = ReadSetting(name + QStringLiteral("/default"), true).value<bool>();
if (!is_default) {
setting->LoadString(ReadSetting(name, default_value).value<QString>().toStdString()); setting->LoadString(ReadSetting(name, default_value).value<QString>().toStdString());
} else {
// Empty string resets the Setting to default
setting->LoadString("");
} }
} else if (global) {
setting->LoadString(ReadSetting(name, default_value).value<QString>().toStdString());
} }
} }