You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.5 KiB
105 lines
3.5 KiB
From 9d16882177a832fa855416c69bc817cee2903622 Mon Sep 17 00:00:00 2001
|
|
From: Antonio Larrosa <larrosa@kde.org>
|
|
Date: Wed, 11 Nov 2015 19:05:08 +0100
|
|
Subject: [PATCH 21/34] Refactored ConfigReader::(is|matches)Default()
|
|
|
|
Previously, ConfigReader::isDefault didn't return if the value is
|
|
the default value but if it matches the default value. So I renamed the
|
|
method to matchesDefault() and created a new isDefault() method
|
|
that really returns if the value comes from the default value or
|
|
it was read from the config file or set.
|
|
|
|
So if the user sets a variable in the config file with the same value
|
|
as the default value, then matchesDefault() returns true, but
|
|
isDefault() returns false
|
|
---
|
|
src/common/ConfigReader.cpp | 6 +++---
|
|
src/common/ConfigReader.h | 12 +++++++++++-
|
|
2 files changed, 14 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/common/ConfigReader.cpp b/src/common/ConfigReader.cpp
|
|
index bdfd22a..cfc9940 100644
|
|
--- a/src/common/ConfigReader.cpp
|
|
+++ b/src/common/ConfigReader.cpp
|
|
@@ -186,17 +186,17 @@ namespace SDDM {
|
|
* Initialization of the map of nondefault values to be saved
|
|
*/
|
|
if (section) {
|
|
- if (entry && !entry->isDefault())
|
|
+ if (entry && !entry->matchesDefault())
|
|
remainingEntries.insert(section, entry);
|
|
else
|
|
for (const ConfigEntryBase *b : section->entries().values())
|
|
- if (!b->isDefault())
|
|
+ if (!b->matchesDefault())
|
|
remainingEntries.insert(section, b);
|
|
}
|
|
else {
|
|
for (const ConfigSection *s : m_sections)
|
|
for (const ConfigEntryBase *b : s->entries().values())
|
|
- if (!b->isDefault())
|
|
+ if (!b->matchesDefault())
|
|
remainingEntries.insert(s, b);
|
|
}
|
|
|
|
diff --git a/src/common/ConfigReader.h b/src/common/ConfigReader.h
|
|
index 29782be..1fb7fd2 100644
|
|
--- a/src/common/ConfigReader.h
|
|
+++ b/src/common/ConfigReader.h
|
|
@@ -77,6 +77,7 @@ namespace SDDM {
|
|
virtual void setValue(const QString &str) = 0;
|
|
virtual QString toConfigShort() const = 0;
|
|
virtual QString toConfigFull() const = 0;
|
|
+ virtual bool matchesDefault() const = 0;
|
|
virtual bool isDefault() const = 0;
|
|
};
|
|
|
|
@@ -107,6 +108,7 @@ namespace SDDM {
|
|
m_description(description),
|
|
m_default(value),
|
|
m_value(value),
|
|
+ m_isDefault(true),
|
|
m_parent(parent) {
|
|
m_parent->m_entries[name] = this;
|
|
}
|
|
@@ -117,13 +119,19 @@ namespace SDDM {
|
|
|
|
void set(const T val) {
|
|
m_value = val;
|
|
+ m_isDefault = false;
|
|
}
|
|
|
|
- bool isDefault() const {
|
|
+ bool matchesDefault() const {
|
|
return m_value == m_default;
|
|
}
|
|
|
|
+ bool isDefault() const {
|
|
+ return m_isDefault;
|
|
+ }
|
|
+
|
|
bool setDefault() {
|
|
+ m_isDefault = true;
|
|
if (m_value == m_default)
|
|
return false;
|
|
m_value = m_default;
|
|
@@ -147,6 +155,7 @@ namespace SDDM {
|
|
|
|
// specialised for QString
|
|
void setValue(const QString &str) {
|
|
+ m_isDefault = false;
|
|
QTextStream in(qPrintable(str));
|
|
in >> m_value;
|
|
}
|
|
@@ -167,6 +176,7 @@ namespace SDDM {
|
|
const QString m_description;
|
|
T m_default;
|
|
T m_value;
|
|
+ bool m_isDefault;
|
|
ConfigSection *m_parent;
|
|
};
|
|
|
|
--
|
|
2.5.0
|
|
|