mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
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 (int valueListIndex);
|
||||
|
||||
/// retroeve list of valid values for setting
|
||||
/// retrieve list of valid values for setting
|
||||
inline QStringList *getValueList() { return mValueList; }
|
||||
|
||||
/// write list of valid values for setting
|
||||
|
|
|
@ -42,6 +42,33 @@ CSMSettings::UserSettings::UserSettings()
|
|||
|
||||
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>");
|
||||
|
||||
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()
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
const CSMSettings::SettingMap *CSMSettings::UserSettings::getSettings(const QString §ionName) const
|
||||
{
|
||||
return getValidSettings(sectionName);
|
||||
}
|
||||
|
||||
bool CSMSettings::UserSettings::loadFromFile(const QString &filePath)
|
||||
{
|
||||
if (filePath.isEmpty())
|
||||
return false;
|
||||
|
||||
mSectionSettings.clear();
|
||||
SectionMap loadedSettings;
|
||||
|
||||
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
|
||||
if (settings)
|
||||
mSectionSettings.insert(section, settings);
|
||||
loadedSettings.insert(section, settings);
|
||||
|
||||
//save new section and create a new list
|
||||
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();
|
||||
delete stream;
|
||||
stream = 0;
|
||||
}
|
||||
|
||||
mergeMap (loadedSettings);
|
||||
|
||||
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)
|
||||
{
|
||||
mSectionSettings.clear();
|
||||
|
||||
//global
|
||||
QString globalFilePath = QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName;
|
||||
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)
|
||||
{
|
||||
if (mSectionSettings.find(sectionName) == mSectionSettings.end())
|
||||
return;
|
||||
|
||||
SettingMap *settings = mSectionSettings.value(sectionName);
|
||||
SettingMap *settings = getValidSettings(sectionName);
|
||||
|
||||
if (!settings)
|
||||
return;
|
||||
|
||||
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 retVal = "";
|
||||
SettingMap *settings = getValidSettings(section);
|
||||
|
||||
if (mSectionSettings.find(section) != mSectionSettings.end())
|
||||
{
|
||||
CSMSettings::SettingMap *settings = mSectionSettings.value(section);
|
||||
QString retVal = "";
|
||||
|
||||
if (settings->find(setting) != settings->end())
|
||||
retVal = settings->value(setting)->getValue();
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
@ -263,3 +323,33 @@ void CSMSettings::UserSettings::displayFileErrorMessage(const QString &message,
|
|||
|
||||
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
|
||||
|
||||
SectionMap mSectionSettings;
|
||||
SectionMap mEditorSettingDefaults;
|
||||
|
||||
static UserSettings *mUserSettingsInstance;
|
||||
QString mUserFilePath;
|
||||
Files::ConfigurationManager mCfgMgr;
|
||||
|
@ -58,7 +60,9 @@ namespace CSMSettings {
|
|||
void loadSettings (const QString &fileName);
|
||||
|
||||
/// 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
|
||||
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.
|
||||
bool loadFromFile (const QString &filePath = "");
|
||||
|
||||
/// merge the passed map into mSectionSettings
|
||||
void mergeMap (const SectionMap &);
|
||||
|
||||
void displayFileErrorMessage(const QString &message, bool isReadOnly);
|
||||
|
||||
void buildEditorSettingDefaults();
|
||||
|
||||
SettingMap *getValidSettings (const QString §ionName) const;
|
||||
|
||||
signals:
|
||||
|
||||
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
|
|
|
@ -182,9 +182,6 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
|
|||
QString width = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Width"));
|
||||
QString height = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Height"));
|
||||
|
||||
if(width==QString() || height==QString())
|
||||
resize(800, 600);
|
||||
else
|
||||
resize (width.toInt(), height.toInt());
|
||||
|
||||
mSubViewWindow.setDockOptions (QMainWindow::AllowNestedDocks);
|
||||
|
|
|
@ -12,7 +12,7 @@ CSVSettings::GroupBlockDef *CSVSettings::DataDisplayFormatPage::setupDataDisplay
|
|||
{
|
||||
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");
|
||||
|
||||
WidgetDef statusWidget (Widget_RadioButton);
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace CSVSettings
|
|||
|
||||
ItemBlock (QWidget* parent = 0);
|
||||
|
||||
/// pure virtual function not implemneted
|
||||
/// pure virtual function not implemented
|
||||
bool updateSettings (const CSMSettings::SettingMap &settings) { return false; }
|
||||
|
||||
CSMSettings::SettingList *getSettings ();
|
||||
|
|
|
@ -44,7 +44,6 @@ void CSVSettings::UserSettingsDialog::closeEvent (QCloseEvent *event)
|
|||
void CSVSettings::UserSettingsDialog::setWidgetStates ()
|
||||
{
|
||||
CSMSettings::UserSettings::instance().loadSettings("opencs.cfg");
|
||||
const CSMSettings::SectionMap §ionSettings = CSMSettings::UserSettings::instance().getSettings();
|
||||
|
||||
//iterate the tabWidget's pages (sections)
|
||||
for (int i = 0; i < mStackedWidget->count(); i++)
|
||||
|
@ -53,14 +52,11 @@ void CSVSettings::UserSettingsDialog::setWidgetStates ()
|
|||
//and update widget
|
||||
QString pageName = mStackedWidget->widget(i)->objectName();
|
||||
|
||||
if (sectionSettings.find(pageName) != sectionSettings.end())
|
||||
{
|
||||
CSMSettings::SettingMap *settings = sectionSettings.value(pageName);
|
||||
const CSMSettings::SettingMap *settings = CSMSettings::UserSettings::instance().getSettings(pageName);
|
||||
AbstractPage &page = getAbstractPage (i);
|
||||
page.initializeWidgets(*settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVSettings::UserSettingsDialog::buildPages()
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "../../view/settings/abstractblock.hpp"
|
||||
|
||||
CSVSettings::WindowPage::WindowPage(QWidget *parent):
|
||||
AbstractPage("Window", parent)
|
||||
AbstractPage("Window Size", parent)
|
||||
{
|
||||
// Hacks to get the stylesheet look properly
|
||||
#ifdef Q_OS_MAC
|
||||
|
@ -82,7 +82,7 @@ CSVSettings::GroupBlockDef *CSVSettings::WindowPage::buildCustomWindowSize()
|
|||
|
||||
CSVSettings::GroupBlockDef *CSVSettings::WindowPage::buildWindowSizeToggle()
|
||||
{
|
||||
GroupBlockDef *block = new GroupBlockDef ("Window Size");
|
||||
GroupBlockDef *block = new GroupBlockDef (objectName());
|
||||
|
||||
// window size toggle
|
||||
block->captions << "Pre-Defined" << "Custom";
|
||||
|
|
Loading…
Reference in a new issue