To-Do: save the settings only if they've been "apply"d

The colors don't play very well with the theme support. We want to
switch the colors according to the current theme if the user doesn't
care for them. Not saving the default colors achieves that.

Change-Id: Idafc13e561d33736eb21b26944756291449594b5
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Ulf Hermann
2017-01-06 17:44:51 +01:00
parent b872a38040
commit 58f754bb66
3 changed files with 13 additions and 1 deletions

View File

@@ -70,6 +70,9 @@ void OptionsPage::apply()
{
Settings newSettings = m_widget->settings();
// "apply" itself is interpreted as "use these keywords, also for other themes".
newSettings.keywordsEdited = true;
if (newSettings != m_settings) {
m_settings = newSettings;
emit settingsChanged(m_settings);

View File

@@ -36,6 +36,9 @@ namespace Internal {
void Settings::save(QSettings *settings) const
{
if (!keywordsEdited)
return;
settings->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
settings->setValue(QLatin1String(Constants::SCANNING_SCOPE), scanningScope);
@@ -97,6 +100,7 @@ void Settings::load(QSettings *settings)
newKeywords << keyword;
}
keywords = newKeywords;
keywordsEdited = true; // Otherwise they wouldn't have been saved
}
settings->endArray();
@@ -135,12 +139,15 @@ void Settings::setDefault()
keyword.iconType = IconType::Warning;
keyword.color = QColor(QLatin1String(Constants::COLOR_WARNING_BG));
keywords.append(keyword);
keywordsEdited = false;
}
bool Settings::equals(const Settings &other) const
{
return (keywords == other.keywords)
&& (scanningScope == other.scanningScope);
&& (scanningScope == other.scanningScope)
&& (keywordsEdited == other.keywordsEdited);
}
bool operator ==(Settings &s1, Settings &s2)

View File

@@ -44,6 +44,8 @@ class Settings {
public:
KeywordList keywords;
ScanningScope scanningScope = ScanningScopeCurrentFile;
bool keywordsEdited = false;
void save(QSettings *settings) const;
void load(QSettings *settings);
void setDefault();