forked from mirror/openmw-tes3mp
Fixed setting synchronization issue
Moved default settings to CSMSettings::UserSettings. Other minor code changes / cleanup
This commit is contained in:
parent
11178cc470
commit
6486f342b5
9 changed files with 126 additions and 32 deletions
|
@ -34,7 +34,7 @@ namespace CSMSettings
|
||||||
bool updateItem (const QString &value);
|
bool updateItem (const QString &value);
|
||||||
bool updateItem (int valueListIndex);
|
bool updateItem (int valueListIndex);
|
||||||
|
|
||||||
/// retroeve list of valid values for setting
|
/// retrieve list of valid values for setting
|
||||||
inline QStringList *getValueList() { return mValueList; }
|
inline QStringList *getValueList() { return mValueList; }
|
||||||
|
|
||||||
/// write list of valid values for setting
|
/// write list of valid values for setting
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace CSMSettings
|
||||||
|
|
||||||
typedef QList<SettingContainer *> SettingList;
|
typedef QList<SettingContainer *> SettingList;
|
||||||
typedef QMap<QString, SettingContainer *> SettingMap;
|
typedef QMap<QString, SettingContainer *> SettingMap;
|
||||||
typedef QMap<QString, SettingMap *> SectionMap;
|
typedef QMap<QString, SettingMap *> SectionMap;
|
||||||
|
|
||||||
struct QStringPair
|
struct QStringPair
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,33 @@ CSMSettings::UserSettings::UserSettings()
|
||||||
|
|
||||||
mReadOnlyMessage = QObject::tr("<br><b>Could not open file for reading</b><br><br> \
|
mReadOnlyMessage = QObject::tr("<br><b>Could not open file for reading</b><br><br> \
|
||||||
Please make sure you have the right permissions and try again.<br>");
|
Please make sure you have the right permissions and try again.<br>");
|
||||||
|
|
||||||
|
buildEditorSettingDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMSettings::UserSettings::buildEditorSettingDefaults()
|
||||||
|
{
|
||||||
|
SettingContainer *windowHeight = new SettingContainer("768", this);
|
||||||
|
SettingContainer *windowWidth = new SettingContainer("1024", this);
|
||||||
|
SettingContainer *rsDelegate = new SettingContainer("Icon and Text", this);
|
||||||
|
SettingContainer *refIdTypeDelegate = new SettingContainer("Icon and Text", this);
|
||||||
|
|
||||||
|
windowHeight->setObjectName ("Height");
|
||||||
|
windowWidth->setObjectName ("Width");
|
||||||
|
rsDelegate->setObjectName ("Record Status Display");
|
||||||
|
refIdTypeDelegate->setObjectName ("Referenceable ID Type Display");
|
||||||
|
|
||||||
|
SettingMap *displayFormatMap = new SettingMap;
|
||||||
|
SettingMap *windowSizeMap = new SettingMap;
|
||||||
|
|
||||||
|
displayFormatMap->insert (rsDelegate->objectName(), rsDelegate );
|
||||||
|
displayFormatMap->insert (refIdTypeDelegate->objectName(), refIdTypeDelegate);
|
||||||
|
|
||||||
|
windowSizeMap->insert (windowWidth->objectName(), windowWidth );
|
||||||
|
windowSizeMap->insert (windowHeight->objectName(), windowHeight );
|
||||||
|
|
||||||
|
mEditorSettingDefaults.insert ("Display Format", displayFormatMap);
|
||||||
|
mEditorSettingDefaults.insert ("Window Size", windowSizeMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMSettings::UserSettings::~UserSettings()
|
CSMSettings::UserSettings::~UserSettings()
|
||||||
|
@ -104,17 +131,22 @@ bool CSMSettings::UserSettings::writeSettings(QMap<QString, CSMSettings::Setting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const CSMSettings::SectionMap &CSMSettings::UserSettings::getSettings() const
|
const CSMSettings::SectionMap &CSMSettings::UserSettings::getSectionMap() const
|
||||||
{
|
{
|
||||||
return mSectionSettings;
|
return mSectionSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CSMSettings::SettingMap *CSMSettings::UserSettings::getSettings(const QString §ionName) const
|
||||||
|
{
|
||||||
|
return getValidSettings(sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
bool CSMSettings::UserSettings::loadFromFile(const QString &filePath)
|
bool CSMSettings::UserSettings::loadFromFile(const QString &filePath)
|
||||||
{
|
{
|
||||||
if (filePath.isEmpty())
|
if (filePath.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mSectionSettings.clear();
|
SectionMap loadedSettings;
|
||||||
|
|
||||||
QTextStream *stream = openFileStream (filePath, true);
|
QTextStream *stream = openFileStream (filePath, true);
|
||||||
|
|
||||||
|
@ -150,7 +182,7 @@ bool CSMSettings::UserSettings::loadFromFile(const QString &filePath)
|
||||||
{
|
{
|
||||||
//add the previous section's settings to the member map
|
//add the previous section's settings to the member map
|
||||||
if (settings)
|
if (settings)
|
||||||
mSectionSettings.insert(section, settings);
|
loadedSettings.insert(section, settings);
|
||||||
|
|
||||||
//save new section and create a new list
|
//save new section and create a new list
|
||||||
section = sectionRe.cap(1);
|
section = sectionRe.cap(1);
|
||||||
|
@ -167,18 +199,48 @@ bool CSMSettings::UserSettings::loadFromFile(const QString &filePath)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mSectionSettings.insert(section, settings);
|
loadedSettings.insert(section, settings);
|
||||||
|
|
||||||
stream->device()->close();
|
stream->device()->close();
|
||||||
delete stream;
|
delete stream;
|
||||||
stream = 0;
|
stream = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mergeMap (loadedSettings);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMSettings::UserSettings::mergeMap (const CSMSettings::SectionMap §ionSettings)
|
||||||
|
{
|
||||||
|
foreach (QString key, sectionSettings.uniqueKeys())
|
||||||
|
{
|
||||||
|
// insert entire section if it does not already exist in the loaded files
|
||||||
|
if (mSectionSettings.find(key) == mSectionSettings.end())
|
||||||
|
mSectionSettings.insert(key, sectionSettings.value(key));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SettingMap *passedSettings = sectionSettings.value(key);
|
||||||
|
SettingMap *settings = mSectionSettings.value(key);
|
||||||
|
|
||||||
|
foreach (QString key2, passedSettings->uniqueKeys())
|
||||||
|
{
|
||||||
|
//insert section settings individially if they do not already exist
|
||||||
|
if (settings->find(key2) == settings->end())
|
||||||
|
settings->insert(key2, passedSettings->value(key2));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settings->value(key2)->update(passedSettings->value(key2)->getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSMSettings::UserSettings::loadSettings (const QString &fileName)
|
void CSMSettings::UserSettings::loadSettings (const QString &fileName)
|
||||||
{
|
{
|
||||||
|
mSectionSettings.clear();
|
||||||
|
|
||||||
//global
|
//global
|
||||||
QString globalFilePath = QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName;
|
QString globalFilePath = QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName;
|
||||||
bool globalOk = loadFromFile(globalFilePath);
|
bool globalOk = loadFromFile(globalFilePath);
|
||||||
|
@ -207,10 +269,11 @@ void CSMSettings::UserSettings::loadSettings (const QString &fileName)
|
||||||
|
|
||||||
void CSMSettings::UserSettings::updateSettings (const QString §ionName, const QString &settingName)
|
void CSMSettings::UserSettings::updateSettings (const QString §ionName, const QString &settingName)
|
||||||
{
|
{
|
||||||
if (mSectionSettings.find(sectionName) == mSectionSettings.end())
|
|
||||||
return;
|
|
||||||
|
|
||||||
SettingMap *settings = mSectionSettings.value(sectionName);
|
SettingMap *settings = getValidSettings(sectionName);
|
||||||
|
|
||||||
|
if (!settings)
|
||||||
|
return;
|
||||||
|
|
||||||
if (settingName.isEmpty())
|
if (settingName.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -229,15 +292,12 @@ void CSMSettings::UserSettings::updateSettings (const QString §ionName, cons
|
||||||
|
|
||||||
QString CSMSettings::UserSettings::getSetting (const QString §ion, const QString &setting) const
|
QString CSMSettings::UserSettings::getSetting (const QString §ion, const QString &setting) const
|
||||||
{
|
{
|
||||||
|
SettingMap *settings = getValidSettings(section);
|
||||||
|
|
||||||
QString retVal = "";
|
QString retVal = "";
|
||||||
|
|
||||||
if (mSectionSettings.find(section) != mSectionSettings.end())
|
if (settings->find(setting) != settings->end())
|
||||||
{
|
retVal = settings->value(setting)->getValue();
|
||||||
CSMSettings::SettingMap *settings = mSectionSettings.value(section);
|
|
||||||
|
|
||||||
if (settings->find(setting) != settings->end())
|
|
||||||
retVal = settings->value(setting)->getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
@ -263,3 +323,33 @@ void CSMSettings::UserSettings::displayFileErrorMessage(const QString &message,
|
||||||
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSMSettings::SettingMap *
|
||||||
|
CSMSettings::UserSettings::getValidSettings (const QString §ionName) const
|
||||||
|
{
|
||||||
|
SettingMap *settings = 0;
|
||||||
|
|
||||||
|
//copy the default values for the entire section if it's not found
|
||||||
|
if (mSectionSettings.find(sectionName) == mSectionSettings.end())
|
||||||
|
{
|
||||||
|
if (mEditorSettingDefaults.find(sectionName) != mEditorSettingDefaults.end())
|
||||||
|
settings = mEditorSettingDefaults.value (sectionName);
|
||||||
|
}
|
||||||
|
//otherwise, iterate the section's settings, looking for missing values and replacing them with defaults.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SettingMap *loadedSettings = mSectionSettings[sectionName];
|
||||||
|
SettingMap *defaultSettings = mEditorSettingDefaults[sectionName];
|
||||||
|
|
||||||
|
foreach (QString key, defaultSettings->uniqueKeys())
|
||||||
|
{
|
||||||
|
//write the default value to the loaded settings
|
||||||
|
if (loadedSettings->find((key))==loadedSettings->end())
|
||||||
|
loadedSettings->insert(key, defaultSettings->value(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
settings = mSectionSettings.value (sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace CSMSettings {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
SectionMap mSectionSettings;
|
SectionMap mSectionSettings;
|
||||||
|
SectionMap mEditorSettingDefaults;
|
||||||
|
|
||||||
static UserSettings *mUserSettingsInstance;
|
static UserSettings *mUserSettingsInstance;
|
||||||
QString mUserFilePath;
|
QString mUserFilePath;
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
|
@ -58,7 +60,9 @@ namespace CSMSettings {
|
||||||
void loadSettings (const QString &fileName);
|
void loadSettings (const QString &fileName);
|
||||||
|
|
||||||
/// Returns the entire map of settings across all sections
|
/// Returns the entire map of settings across all sections
|
||||||
const SectionMap &getSettings () const;
|
const SectionMap &getSectionMap () const;
|
||||||
|
|
||||||
|
const SettingMap *getSettings (const QString §ionName) const;
|
||||||
|
|
||||||
/// Retrieves the value as a QString of the specified setting in the specified section
|
/// Retrieves the value as a QString of the specified setting in the specified section
|
||||||
QString getSetting(const QString §ion, const QString &setting) const;
|
QString getSetting(const QString §ion, const QString &setting) const;
|
||||||
|
@ -72,8 +76,15 @@ namespace CSMSettings {
|
||||||
/// Parses a setting file specified in filePath from the provided text stream.
|
/// Parses a setting file specified in filePath from the provided text stream.
|
||||||
bool loadFromFile (const QString &filePath = "");
|
bool loadFromFile (const QString &filePath = "");
|
||||||
|
|
||||||
|
/// merge the passed map into mSectionSettings
|
||||||
|
void mergeMap (const SectionMap &);
|
||||||
|
|
||||||
void displayFileErrorMessage(const QString &message, bool isReadOnly);
|
void displayFileErrorMessage(const QString &message, bool isReadOnly);
|
||||||
|
|
||||||
|
void buildEditorSettingDefaults();
|
||||||
|
|
||||||
|
SettingMap *getValidSettings (const QString §ionName) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
|
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||||
|
|
|
@ -182,10 +182,7 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
|
||||||
QString width = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Width"));
|
QString width = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Width"));
|
||||||
QString height = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Height"));
|
QString height = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Height"));
|
||||||
|
|
||||||
if(width==QString() || height==QString())
|
resize (width.toInt(), height.toInt());
|
||||||
resize(800, 600);
|
|
||||||
else
|
|
||||||
resize (width.toInt(), height.toInt());
|
|
||||||
|
|
||||||
mSubViewWindow.setDockOptions (QMainWindow::AllowNestedDocks);
|
mSubViewWindow.setDockOptions (QMainWindow::AllowNestedDocks);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ CSVSettings::GroupBlockDef *CSVSettings::DataDisplayFormatPage::setupDataDisplay
|
||||||
{
|
{
|
||||||
GroupBlockDef *statusBlock = new GroupBlockDef(QString(title));
|
GroupBlockDef *statusBlock = new GroupBlockDef(QString(title));
|
||||||
|
|
||||||
SettingsItemDef *statusItem = new SettingsItemDef (statusBlock->title, "Icon and Text");
|
SettingsItemDef *statusItem = new SettingsItemDef (statusBlock->title, "Icon Only");
|
||||||
*(statusItem->valueList) << QString("Icon and Text") << QString("Icon Only") << QString("Text Only");
|
*(statusItem->valueList) << QString("Icon and Text") << QString("Icon Only") << QString("Text Only");
|
||||||
|
|
||||||
WidgetDef statusWidget (Widget_RadioButton);
|
WidgetDef statusWidget (Widget_RadioButton);
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace CSVSettings
|
||||||
|
|
||||||
ItemBlock (QWidget* parent = 0);
|
ItemBlock (QWidget* parent = 0);
|
||||||
|
|
||||||
/// pure virtual function not implemneted
|
/// pure virtual function not implemented
|
||||||
bool updateSettings (const CSMSettings::SettingMap &settings) { return false; }
|
bool updateSettings (const CSMSettings::SettingMap &settings) { return false; }
|
||||||
|
|
||||||
CSMSettings::SettingList *getSettings ();
|
CSMSettings::SettingList *getSettings ();
|
||||||
|
|
|
@ -44,7 +44,6 @@ void CSVSettings::UserSettingsDialog::closeEvent (QCloseEvent *event)
|
||||||
void CSVSettings::UserSettingsDialog::setWidgetStates ()
|
void CSVSettings::UserSettingsDialog::setWidgetStates ()
|
||||||
{
|
{
|
||||||
CSMSettings::UserSettings::instance().loadSettings("opencs.cfg");
|
CSMSettings::UserSettings::instance().loadSettings("opencs.cfg");
|
||||||
const CSMSettings::SectionMap §ionSettings = CSMSettings::UserSettings::instance().getSettings();
|
|
||||||
|
|
||||||
//iterate the tabWidget's pages (sections)
|
//iterate the tabWidget's pages (sections)
|
||||||
for (int i = 0; i < mStackedWidget->count(); i++)
|
for (int i = 0; i < mStackedWidget->count(); i++)
|
||||||
|
@ -53,12 +52,9 @@ void CSVSettings::UserSettingsDialog::setWidgetStates ()
|
||||||
//and update widget
|
//and update widget
|
||||||
QString pageName = mStackedWidget->widget(i)->objectName();
|
QString pageName = mStackedWidget->widget(i)->objectName();
|
||||||
|
|
||||||
if (sectionSettings.find(pageName) != sectionSettings.end())
|
const CSMSettings::SettingMap *settings = CSMSettings::UserSettings::instance().getSettings(pageName);
|
||||||
{
|
AbstractPage &page = getAbstractPage (i);
|
||||||
CSMSettings::SettingMap *settings = sectionSettings.value(pageName);
|
page.initializeWidgets(*settings);
|
||||||
AbstractPage &page = getAbstractPage (i);
|
|
||||||
page.initializeWidgets(*settings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "../../view/settings/abstractblock.hpp"
|
#include "../../view/settings/abstractblock.hpp"
|
||||||
|
|
||||||
CSVSettings::WindowPage::WindowPage(QWidget *parent):
|
CSVSettings::WindowPage::WindowPage(QWidget *parent):
|
||||||
AbstractPage("Window", parent)
|
AbstractPage("Window Size", parent)
|
||||||
{
|
{
|
||||||
// Hacks to get the stylesheet look properly
|
// Hacks to get the stylesheet look properly
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
@ -82,7 +82,7 @@ CSVSettings::GroupBlockDef *CSVSettings::WindowPage::buildCustomWindowSize()
|
||||||
|
|
||||||
CSVSettings::GroupBlockDef *CSVSettings::WindowPage::buildWindowSizeToggle()
|
CSVSettings::GroupBlockDef *CSVSettings::WindowPage::buildWindowSizeToggle()
|
||||||
{
|
{
|
||||||
GroupBlockDef *block = new GroupBlockDef ("Window Size");
|
GroupBlockDef *block = new GroupBlockDef (objectName());
|
||||||
|
|
||||||
// window size toggle
|
// window size toggle
|
||||||
block->captions << "Pre-Defined" << "Custom";
|
block->captions << "Pre-Defined" << "Custom";
|
||||||
|
|
Loading…
Reference in a new issue