Allow aliases to be used in order to support legacy setting key names.

This commit is contained in:
Iwbnwif Yiw 2024-02-06 20:48:34 +00:00
parent c48e0f91ba
commit 5248d3d676
3 changed files with 29 additions and 13 deletions

View File

@ -229,11 +229,11 @@ bool loadSettings()
QucsSettings.QucsHomeDir.setPath(_settings::Get().item<QString>("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<bool>("IgnoreVersion");
// if (settings.contains("GraphAntiAliasing")) QucsSettings.GraphAntiAliasing = settings.value("GraphAntiAliasing").toBool();
// else QucsSettings.GraphAntiAliasing = false;

View File

@ -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"});
}

View File

@ -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<class T>
@ -43,16 +39,30 @@ public:
T item(const QString& key)
{
if (contains(key)) {
return value(key).value<T>();
return value(key).value<T>();
}
else {
return m_Defaults[key].value<T>();
for (auto alias : m_Aliases[key]) {
if (contains(alias)) {
// qDebug() << "Found alias: " << alias;
return value(alias).value<T>();
}
}
return m_Defaults[key].value<T>();
}
private:
std::map<QString, QVariant> m_Defaults;
std::map<QString, QStringList> 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<settingsManager> _settings;