Decoupled setting definitions from the Setting class. QSettings

implementation is now fully responsible for managing user settings.
openmw-30
graffy76 11 years ago
parent e47e3de3d2
commit cd7983adb5

@ -81,6 +81,7 @@ void CSMSettings::Connector::slotUpdateMaster() const
}
QString masterValue = mMasterView->value (masterColumn);
mMasterView->setSelectedValue (masterValue);
}

@ -77,16 +77,6 @@ QStringList CSMSettings::Setting::declaredValues() const
return property (Property_DeclaredValues);
}
void CSMSettings::Setting::setDefinedValues (QStringList list)
{
setProperty (Property_DefinedValues, list);
}
QStringList CSMSettings::Setting::definedValues() const
{
return property (Property_DefinedValues);
}
QStringList CSMSettings::Setting::property (SettingProperty prop) const
{
if (prop >= mProperties.size())

@ -44,9 +44,6 @@ namespace CSMSettings
void setDeclaredValues (QStringList list);
QStringList declaredValues() const;
void setDefinedValues (QStringList list);
QStringList definedValues() const;
void setDefaultValue (int value);
void setDefaultValue (double value);
void setDefaultValue (const QString &value);

@ -38,31 +38,6 @@ CSMSettings::UserSettings::UserSettings()
buildSettingModelDefaults();
}
void CSMSettings::UserSettings::addDefinitions ()
{
foreach (const QString &key, mSettingDefinitions->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);
removeSetting (names.at(0), names.at(1));
continue;
}
QStringList values = mSettingDefinitions->value (key).toStringList();
if (values.isEmpty())
values.append (setting->defaultValues());
setting->setDefinedValues (values);
}
}
void CSMSettings::UserSettings::buildSettingModelDefaults()
{
QString section = "Window Size";
@ -139,13 +114,14 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
* Defined values
*
* Values which represent the actual, current value of
* a setting. For settings with declared values, this must be one or
* several declared values, as appropriate.
* a setting. For settings with declared values, this must be one
* or several declared values, as appropriate.
*
* Proxy values - values the proxy master updates the proxy slave when
* it's own definition is set / changed. These are definitions for
* proxy slave settings, but must match any declared values the proxy
* slave has, if any.
* Proxy values
* Values the proxy master updates the proxy slave when
* it's own definition is set / changed. These are definitions for
* proxy slave settings, but must match any declared values the
* proxy slave has, if any.
*******************************************************************/
/*
//create setting objects, specifying the basic widget type,
@ -328,31 +304,36 @@ void CSMSettings::UserSettings::loadSettings (const QString &fileName)
mSettingDefinitions = new QSettings
(QSettings::IniFormat, QSettings::UserScope, "opencs", QString(), this);
}
addDefinitions();
bool CSMSettings::UserSettings::hasSettingDefinitions
(const QString &viewKey) const
{
return (mSettingDefinitions->contains (viewKey));
}
void CSMSettings::UserSettings::saveSettings
(const QMap <QString, QStringList> &settingMap)
void CSMSettings::UserSettings::setDefinitions
(const QString &key, const QStringList &list)
{
foreach (const QString &key, settingMap.keys())
mSettingDefinitions->setValue (key, settingMap.value (key));
mSettingDefinitions->setValue (key, list);
}
void CSMSettings::UserSettings::saveDefinitions() const
{
mSettingDefinitions->sync();
}
QString CSMSettings::UserSettings::settingValue (const QString &settingKey)
{
QStringList names = settingKey.split('/');
if (!mSettingDefinitions->contains (settingKey))
return QString();
Setting *setting = findSetting(names.at(0), names.at(1));
QStringList defs = mSettingDefinitions->value (settingKey).toStringList();
if (setting)
{
if (!setting->definedValues().isEmpty())
return setting->definedValues().at(0);
}
return "";
if (defs.isEmpty())
return QString();
return defs.at(0);
}
CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
@ -364,11 +345,7 @@ CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
void CSMSettings::UserSettings::updateUserSetting(const QString &settingKey,
const QStringList &list)
{
QStringList names = settingKey.split('/');
Setting *setting = findSetting (names.at(0), names.at(1));
setting->setDefinedValues (list);
mSettingDefinitions->setValue (settingKey ,list);
emit userSettingUpdated (settingKey, list);
}
@ -439,3 +416,11 @@ CSMSettings::Setting *CSMSettings::UserSettings::createSetting
return setting;
}
QStringList CSMSettings::UserSettings::definitions (const QString &viewKey) const
{
if (mSettingDefinitions->contains (viewKey))
return mSettingDefinitions->value (viewKey).toStringList();
return QStringList();
}

@ -49,8 +49,8 @@ namespace CSMSettings {
/// Retrieves the settings file at all three levels (global, local and user).
void loadSettings (const QString &fileName);
/// Writes settings to the user's config file path
void saveSettings (const QMap <QString, QStringList > &settingMap);
/// Updates QSettings and syncs with the ini file
void setDefinitions (const QString &key, const QStringList &defs);
QString settingValue (const QString &settingKey);
@ -65,10 +65,17 @@ namespace CSMSettings {
///Retreive a map of the settings, keyed by page name
SettingPageMap settingPageMap() const;
private:
///Returns a string list of defined vlaues for the specified setting
///in "page/name" format.
QStringList definitions (const QString &viewKey) const;
///Test to indicate whether or not a setting has any definitions
bool hasSettingDefinitions (const QString &viewKey) const;
///add definitions to the settings specified in the page map
void addDefinitions();
///Save any unsaved changes in the QSettings object
void saveDefinitions() const;
private:
void buildSettingModelDefaults();

@ -109,7 +109,10 @@ void CSVSettings::Dialog::closeEvent (QCloseEvent *event)
void CSVSettings::Dialog::show()
{
if (pages().isEmpty())
{
buildPages();
setViewValues();
}
QPoint screenCenter = QApplication::desktop()->screenGeometry().center();

@ -82,6 +82,25 @@ void CSVSettings::SettingWindow::createConnections
}
}
void CSVSettings::SettingWindow::setViewValues()
{
//iterate each page and view, setting their definintions
//if they exist in the model
foreach (const Page *page, mPages)
{
foreach (const View *view, page->views())
{
//testing beforehand prevents overwriting a proxy setting
if (!mModel->hasSettingDefinitions (view->viewKey()))
continue;
QStringList defs = mModel->definitions (view->viewKey());
view->setSelectedValues(defs);
}
}
}
CSVSettings::View *CSVSettings::SettingWindow::findView
(const QString &pageName, const QString &setting)
{
@ -95,17 +114,19 @@ CSVSettings::View *CSVSettings::SettingWindow::findView
void CSVSettings::SettingWindow::saveSettings()
{
QMap <QString, QStringList> settingMap;
//setting the definition in the model automatically syncs with the file
foreach (const Page *page, mPages)
{
foreach (const View *view, page->views())
{
if (view->serializable())
settingMap[view->viewKey()] = view->selectedValues();
if (!view->serializable())
continue;
mModel->setDefinitions (view->viewKey(), view->selectedValues());
}
}
CSMSettings::UserSettings::instance().saveSettings (settingMap);
mModel->saveDefinitions();
}
void CSVSettings::SettingWindow::closeEvent (QCloseEvent *event)

@ -47,6 +47,9 @@ namespace CSVSettings {
///save settings from the GUI to file
void saveSettings();
///sets the defined values for the views that have been created
void setViewValues();
private:
///create connections between settings (used for proxy settings)

@ -26,10 +26,7 @@ CSVSettings::View::View(CSMSettings::Setting *setting,
void CSVSettings::View::buildModel (const CSMSettings::Setting *setting)
{
QStringList values = setting->definedValues();
if (values.isEmpty())
values.append (setting->defaultValues());
QStringList values = setting->defaultValues();
if (mHasFixedValues)
buildFixedValueModel (setting->declaredValues());
@ -116,7 +113,7 @@ void CSVSettings::View::setSelectedValue (const QString &value,
}
void CSVSettings::View::setSelectedValues (const QStringList &list,
bool doViewUpdate, bool signalUpdate)
bool doViewUpdate, bool signalUpdate) const
{
QItemSelection selection;

@ -71,7 +71,7 @@ namespace CSVSettings
///or signaling the view was updatedto avoid viscious cylcing.
void setSelectedValues (const QStringList &values,
bool updateView = true,
bool signalUpdate = true);
bool signalUpdate = true) const;
void setSelectedValue (const QString &value,
bool updateView = true,

Loading…
Cancel
Save