forked from teamnwah/openmw-tes3coop
Incorporated SettingManager into UserSettings class. Other minor code
changes to support QSettings integrationopenmw-30
parent
5cba828cc9
commit
79b13a74a3
@ -1,93 +0,0 @@
|
||||
#include <QFile>
|
||||
#include <QTextCodec>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
#include <QSettings>
|
||||
|
||||
#include "setting.hpp"
|
||||
#include "settingmanager.hpp"
|
||||
|
||||
CSMSettings::SettingManager::SettingManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{}
|
||||
|
||||
CSMSettings::Setting *CSMSettings::SettingManager::createSetting
|
||||
(CSMSettings::SettingType typ, const QString &page, const QString &name)
|
||||
{
|
||||
//get list of all settings for the current setting name
|
||||
if (findSetting (page, name))
|
||||
{
|
||||
qWarning() << "Duplicate declaration encountered: "
|
||||
<< (name + '/' + page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Setting *setting = new Setting (typ, name, page);
|
||||
|
||||
|
||||
//add declaration to the model
|
||||
mSettings.append (setting);
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
void CSMSettings::SettingManager::addDefinitions (const QSettings *settings)
|
||||
{
|
||||
foreach (const QString &key, settings->allKeys())
|
||||
{
|
||||
QStringList names = key.split('/');
|
||||
|
||||
Setting *setting = findSetting (names.at(0), names.at(1));
|
||||
|
||||
if (!setting)
|
||||
{
|
||||
qWarning() << "Found definitions for undeclared setting "
|
||||
<< names.at(0) << "." << names.at(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
QStringList values = settings->value (key).toStringList();
|
||||
|
||||
if (values.isEmpty())
|
||||
values.append (setting->defaultValues());
|
||||
|
||||
setting->setDefinedValues (values);
|
||||
}
|
||||
}
|
||||
|
||||
CSMSettings::Setting *CSMSettings::SettingManager::findSetting
|
||||
(const QString &pageName, const QString &settingName)
|
||||
{
|
||||
foreach (Setting *setting, mSettings)
|
||||
{
|
||||
if (setting->name() == settingName)
|
||||
{
|
||||
if (setting->page() == pageName)
|
||||
return setting;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
#ifndef CSMSETTINGS_SETTINGMANAGER_HPP
|
||||
#define CSMSETTINGS_SETTINGMANAGER_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
#include <QSettings>
|
||||
|
||||
#include "support.hpp"
|
||||
#include "setting.hpp"
|
||||
|
||||
namespace CSMSettings
|
||||
{
|
||||
|
||||
typedef QMap <QString, QStringList *> DefinitionMap;
|
||||
typedef QMap <QString, DefinitionMap *> DefinitionPageMap;
|
||||
|
||||
typedef QMap <QString, QList <Setting *> > SettingPageMap;
|
||||
|
||||
class SettingManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QList <Setting *> mSettings;
|
||||
|
||||
public:
|
||||
explicit SettingManager(QObject *parent = 0);
|
||||
|
||||
///retrieve a setting object from a given page and setting name
|
||||
Setting *findSetting
|
||||
(const QString &pageName, const QString &settingName = QString());
|
||||
|
||||
///Retreive a map of the settings, keyed by page name
|
||||
SettingPageMap settingPageMap() const;
|
||||
|
||||
protected:
|
||||
|
||||
///add a new setting to the model and return it
|
||||
Setting *createSetting (CSMSettings::SettingType typ,
|
||||
const QString &page, const QString &name);
|
||||
|
||||
///add definitions to the settings specified in the page map
|
||||
void addDefinitions (const QSettings *settings);
|
||||
|
||||
signals:
|
||||
|
||||
void userSettingUpdated (const QString &, const QStringList &);
|
||||
|
||||
public slots:
|
||||
|
||||
void updateUserSetting (const QString &, const QStringList &);
|
||||
};
|
||||
}
|
||||
#endif // CSMSETTINGS_SETTINGMANAGER_HPP
|
Loading…
Reference in New Issue