1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00
OpenMW/apps/opencs/model/settings/settingmanager.cpp

94 lines
2.3 KiB
C++
Raw Normal View History

2014-04-22 22:17:19 -05:00
#include <QFile>
#include <QTextCodec>
#include <QMessageBox>
#include <QDebug>
#include <QList>
#include <QSettings>
2014-04-22 22:17:19 -05:00
#include "setting.hpp"
#include "settingmanager.hpp"
CSMSettings::SettingManager::SettingManager(QObject *parent) :
QObject(parent)
{}
2014-05-05 06:07:41 -05:00
2014-04-22 22:17:19 -05:00
CSMSettings::Setting *CSMSettings::SettingManager::createSetting
(CSMSettings::SettingType typ, const QString &page, const QString &name)
2014-04-22 22:17:19 -05:00
{
//get list of all settings for the current setting name
if (findSetting (page, name))
{
qWarning() << "Duplicate declaration encountered: "
<< (name + '/' + page);
2014-04-22 22:17:19 -05:00
return 0;
}
Setting *setting = new Setting (typ, name, page);
2014-04-22 22:17:19 -05:00
//add declaration to the model
mSettings.append (setting);
return setting;
}
void CSMSettings::SettingManager::addDefinitions (const QSettings *settings)
2014-04-22 22:17:19 -05:00
{
foreach (const QString &key, settings->allKeys())
2014-04-22 22:17:19 -05:00
{
QStringList names = key.split('/');
Setting *setting = findSetting (names.at(0), names.at(1));
2014-04-22 22:17:19 -05:00
if (!setting)
2014-04-22 22:17:19 -05:00
{
qWarning() << "Found definitions for undeclared setting "
<< names.at(0) << "." << names.at(1);
continue;
}
2014-04-22 22:17:19 -05:00
QStringList values = settings->value (key).toStringList();
2014-04-22 22:17:19 -05:00
if (values.isEmpty())
values.append (setting->defaultValues());
2014-04-22 22:17:19 -05:00
setting->setDefinedValues (values);
2014-04-22 22:17:19 -05:00
}
}
CSMSettings::Setting *CSMSettings::SettingManager::findSetting
(const QString &pageName, const QString &settingName)
{
foreach (Setting *setting, mSettings)
{
2014-05-05 06:07:41 -05:00
if (setting->name() == settingName)
2014-04-22 22:17:19 -05:00
{
if (setting->page() == pageName)
return setting;
}
}
return 0;
}
2014-05-05 06:07:41 -05:00
2014-04-22 22:17:19 -05:00
CSMSettings::SettingPageMap CSMSettings::SettingManager::settingPageMap() const
{
SettingPageMap pageMap;
foreach (Setting *setting, mSettings)
pageMap[setting->page()].append (setting);
return pageMap;
}
void CSMSettings::SettingManager::updateUserSetting(const QString &settingKey,
const QStringList &list)
{
QStringList names = settingKey.split('/');
Setting *setting = findSetting (names.at(0), names.at(1));
setting->setDefinedValues (list);
emit userSettingUpdated (settingKey, list);
}