mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
Fixed code conventions in user settings, changed top-level page names
This commit is contained in:
parent
f0f895ad10
commit
6deddf7229
3 changed files with 38 additions and 41 deletions
|
@ -52,15 +52,14 @@ CSMSettings::UserSettings::~UserSettings()
|
||||||
|
|
||||||
QTextStream *CSMSettings::UserSettings::openFileStream (const QString &filePath, bool isReadOnly) const
|
QTextStream *CSMSettings::UserSettings::openFileStream (const QString &filePath, bool isReadOnly) const
|
||||||
{
|
{
|
||||||
QFile *file = new QFile(filePath);
|
QIODevice::OpenMode openFlags = QIODevice::Text;
|
||||||
|
|
||||||
QIODevice::OpenMode openFlags;
|
|
||||||
|
|
||||||
if (isReadOnly)
|
if (isReadOnly)
|
||||||
openFlags = QIODevice::ReadOnly | QIODevice::Text;
|
openFlags = QIODevice::ReadOnly | openFlags;
|
||||||
else
|
else
|
||||||
openFlags = QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate;
|
openFlags = QIODevice::ReadWrite | QIODevice::Truncate | openFlags;
|
||||||
|
|
||||||
|
QFile *file = new QFile(filePath);
|
||||||
QTextStream *stream = 0;
|
QTextStream *stream = 0;
|
||||||
|
|
||||||
if (file->open(openFlags))
|
if (file->open(openFlags))
|
||||||
|
@ -69,12 +68,6 @@ QTextStream *CSMSettings::UserSettings::openFileStream (const QString &filePath,
|
||||||
stream->setCodec(QTextCodec::codecForName("UTF-8"));
|
stream->setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stream)
|
|
||||||
{
|
|
||||||
delete file;
|
|
||||||
file = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,10 +76,9 @@ bool CSMSettings::UserSettings::writeSettings(QMap<QString, CSMSettings::Setting
|
||||||
{
|
{
|
||||||
QTextStream *stream = openFileStream(mUserFilePath);
|
QTextStream *stream = openFileStream(mUserFilePath);
|
||||||
|
|
||||||
if (!stream)
|
bool success = (stream);
|
||||||
displayFileErrorMessage(mReadWriteMessage, false);
|
|
||||||
|
|
||||||
if (stream)
|
if (success)
|
||||||
{
|
{
|
||||||
QList<QString> keyList = settings.keys();
|
QList<QString> keyList = settings.keys();
|
||||||
|
|
||||||
|
@ -101,9 +93,15 @@ bool CSMSettings::UserSettings::writeSettings(QMap<QString, CSMSettings::Setting
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->device()->close();
|
stream->device()->close();
|
||||||
|
delete stream;
|
||||||
|
stream = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
displayFileErrorMessage(mReadWriteMessage, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (stream);
|
return (success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,7 +119,9 @@ bool CSMSettings::UserSettings::loadFromFile(const QString &filePath)
|
||||||
|
|
||||||
QTextStream *stream = openFileStream (filePath, true);
|
QTextStream *stream = openFileStream (filePath, true);
|
||||||
|
|
||||||
if (stream)
|
bool success = (stream);
|
||||||
|
|
||||||
|
if (success)
|
||||||
{
|
{
|
||||||
//looks for a square bracket, "'\\["
|
//looks for a square bracket, "'\\["
|
||||||
//that has one or more "not nothing" in it, "([^]]+)"
|
//that has one or more "not nothing" in it, "([^]]+)"
|
||||||
|
@ -171,24 +171,23 @@ bool CSMSettings::UserSettings::loadFromFile(const QString &filePath)
|
||||||
mSectionSettings.insert(section, settings);
|
mSectionSettings.insert(section, settings);
|
||||||
|
|
||||||
stream->device()->close();
|
stream->device()->close();
|
||||||
|
delete stream;
|
||||||
|
stream = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (stream);
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMSettings::UserSettings::loadSettings (const QString &fileName)
|
void CSMSettings::UserSettings::loadSettings (const QString &fileName)
|
||||||
{
|
{
|
||||||
bool globalOk;
|
|
||||||
bool localOk;
|
|
||||||
|
|
||||||
//global
|
//global
|
||||||
QString globalFilePath = QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName;
|
QString globalFilePath = QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName;
|
||||||
globalOk = loadFromFile(globalFilePath);
|
bool globalOk = loadFromFile(globalFilePath);
|
||||||
|
|
||||||
|
|
||||||
//local
|
//local
|
||||||
QString localFilePath = QString::fromStdString(mCfgMgr.getLocalPath().string()) + fileName;
|
QString localFilePath = QString::fromStdString(mCfgMgr.getLocalPath().string()) + fileName;
|
||||||
localOk = loadFromFile(localFilePath);
|
bool localOk = loadFromFile(localFilePath);
|
||||||
|
|
||||||
//user
|
//user
|
||||||
mUserFilePath = QString::fromStdString(mCfgMgr.getUserPath().string()) + fileName;
|
mUserFilePath = QString::fromStdString(mCfgMgr.getUserPath().string()) + fileName;
|
||||||
|
@ -209,23 +208,21 @@ 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)
|
||||||
{
|
{
|
||||||
SettingMap *settings = mSectionSettings[sectionName];
|
if (mSectionSettings.find(sectionName) == mSectionSettings.end())
|
||||||
|
|
||||||
if (!settings)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SettingContainer *setting = 0;
|
SettingMap *settings = mSectionSettings.value(sectionName);
|
||||||
|
|
||||||
if (settingName.isEmpty())
|
if (settingName.isEmpty())
|
||||||
{
|
{
|
||||||
foreach (setting, *settings)
|
foreach (const SettingContainer *setting, *settings)
|
||||||
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
|
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (settings->find(settingName)!=settings->end())
|
if (settings->find(settingName) != settings->end())
|
||||||
{
|
{
|
||||||
setting = settings->value(settingName);
|
const SettingContainer *setting = settings->value(settingName);
|
||||||
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
|
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,23 +230,23 @@ 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
|
||||||
{
|
{
|
||||||
if(mSectionSettings.find(section) == mSectionSettings.end())
|
QString retVal = "";
|
||||||
return QString();
|
|
||||||
|
|
||||||
CSMSettings::SettingMap *settings = mSectionSettings.value(section);
|
if (mSectionSettings.find(section) != mSectionSettings.end())
|
||||||
|
{
|
||||||
|
CSMSettings::SettingMap *settings = mSectionSettings.value(section);
|
||||||
|
|
||||||
if(settings->find(setting) == settings->end())
|
if (settings->find(setting) != settings->end())
|
||||||
return QString();
|
retVal = settings->value(setting)->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
CSMSettings::SettingContainer *settingContainer = settings->value(setting);
|
return retVal;
|
||||||
|
|
||||||
return settingContainer->getValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
|
CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
|
||||||
{
|
{
|
||||||
assert(mUserSettingsInstance);
|
assert(mUserSettingsInstance);
|
||||||
return *mUserSettingsInstance;
|
return *mUserSettingsInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMSettings::UserSettings::displayFileErrorMessage(const QString &message, bool isReadOnly)
|
void CSMSettings::UserSettings::displayFileErrorMessage(const QString &message, bool isReadOnly)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "../../model/settings/usersettings.hpp"
|
#include "../../model/settings/usersettings.hpp"
|
||||||
|
|
||||||
CSVSettings::EditorPage::EditorPage(QWidget* parent) :
|
CSVSettings::EditorPage::EditorPage(QWidget* parent) :
|
||||||
AbstractPage("Editor", parent)
|
AbstractPage("Display Format", parent)
|
||||||
{
|
{
|
||||||
setupUi();
|
setupUi();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 Size", parent)
|
AbstractPage("Window", parent)
|
||||||
{
|
{
|
||||||
// Hacks to get the stylesheet look properly
|
// Hacks to get the stylesheet look properly
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
|
Loading…
Reference in a new issue