From 5248d3d676d8ea50a74930935abac5cf26716c25 Mon Sep 17 00:00:00 2001 From: Iwbnwif Yiw Date: Tue, 6 Feb 2024 20:48:34 +0000 Subject: [PATCH] Allow aliases to be used in order to support legacy setting key names. --- qucs/main.cpp | 10 +++++----- qucs/settings.cpp | 6 ++++++ qucs/settings.h | 26 ++++++++++++++++++-------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/qucs/main.cpp b/qucs/main.cpp index c4d22d45..1d080cc3 100644 --- a/qucs/main.cpp +++ b/qucs/main.cpp @@ -229,11 +229,11 @@ bool loadSettings() QucsSettings.QucsHomeDir.setPath(_settings::Get().item("QucsHomeDir")); QucsSettings.QucsWorkDir = QucsSettings.QucsHomeDir; - // TODO: - if (settings.contains("IgnoreVersion")) QucsSettings.IgnoreFutureVersion = settings.value("IgnoreVersion").toBool(); - // check also for old setting name with typo... - else if (settings.contains("IngnoreVersion")) QucsSettings.IgnoreFutureVersion = settings.value("IngnoreVersion").toBool(); - else QucsSettings.IgnoreFutureVersion = false; + // if (settings.contains("IgnoreVersion")) QucsSettings.IgnoreFutureVersion = settings.value("IgnoreVersion").toBool(); + // // check also for old setting name with typo... + // else if (settings.contains("IngnoreVersion")) QucsSettings.IgnoreFutureVersion = settings.value("IngnoreVersion").toBool(); + // else QucsSettings.IgnoreFutureVersion = false; + QucsSettings.IgnoreFutureVersion = _settings::Get().item("IgnoreVersion"); // if (settings.contains("GraphAntiAliasing")) QucsSettings.GraphAntiAliasing = settings.value("GraphAntiAliasing").toBool(); // else QucsSettings.GraphAntiAliasing = false; diff --git a/qucs/settings.cpp b/qucs/settings.cpp index c85f9d8a..37b6b9be 100644 --- a/qucs/settings.cpp +++ b/qucs/settings.cpp @@ -9,6 +9,7 @@ settingsManager::settingsManager() { // qDebug() << this << " created " << organizationName() << " " << applicationName(); + initAliases(); initDefaults(); } @@ -67,3 +68,8 @@ void settingsManager::initDefaults() m_Defaults["TextAntiAliasing"] = false; m_Defaults["fullTraceName"] = false; } + +void settingsManager::initAliases() +{ + m_Aliases["IgnoreVersion"] = QStringList({"IngnoreVersion"}); +} diff --git a/qucs/settings.h b/qucs/settings.h index 44dd884e..a4b76c26 100644 --- a/qucs/settings.h +++ b/qucs/settings.h @@ -17,10 +17,6 @@ public: */ void resetDefaults(const QString& group = "All"); - /** \brief Initialise all settings to their (hard coded) default value. - */ - void initDefaults(); - /** \brief Get the default value for a given setting. */ template @@ -43,16 +39,30 @@ public: T item(const QString& key) { if (contains(key)) { - return value(key).value(); + return value(key).value(); } - - else { - return m_Defaults[key].value(); + + for (auto alias : m_Aliases[key]) { + if (contains(alias)) { + // qDebug() << "Found alias: " << alias; + return value(alias).value(); + } } + return m_Defaults[key].value(); } private: std::map m_Defaults; + std::map m_Aliases; + + /** \brief Populate the list of items that have a (hard coded) default value. + */ + void initDefaults(); + + /** \brief Populate the list of aliases. + * (legacy names for settings that have been used in the past). + */ + void initAliases(); }; typedef QucsSingleton _settings;