mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 11:09:43 +00:00
Re-link user settings to editor main application
This commit is contained in:
parent
e3384e3999
commit
4b607d658f
18 changed files with 290 additions and 371 deletions
|
@ -28,6 +28,7 @@ CS::Editor::Editor (OgreInit::OgreInit& ogreInit)
|
|||
setupDataFiles (config.first);
|
||||
|
||||
CSMSettings::UserSettings::instance().loadSettings ("opencs.cfg");
|
||||
mSettings.setModel (CSMSettings::UserSettings::instance());
|
||||
|
||||
ogreInit.init ((mCfgMgr.getUserConfigPath() / "opencsOgre.log").string());
|
||||
|
||||
|
@ -117,6 +118,18 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
|
|||
|
||||
dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end());
|
||||
|
||||
//iterate the data directories and add them to the file dialog for loading
|
||||
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
||||
{
|
||||
QString path = QString::fromStdString(iter->string());
|
||||
mFileDialog.addFiles(path);
|
||||
}
|
||||
/*
|
||||
//load the settings into the userSettings instance.
|
||||
const QString settingFileName = "opencs.cfg";
|
||||
CSMSettings::UserSettings::instance().loadSettings(settingFileName);
|
||||
*/
|
||||
|
||||
return std::make_pair (dataDirs, variables["fallback-archive"].as<std::vector<std::string> >());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "view/doc/filedialog.hpp"
|
||||
#include "view/doc/newgame.hpp"
|
||||
|
||||
#include "view/settings/usersettingsdialog.hpp"
|
||||
#include "view/settings/dialog.hpp"
|
||||
|
||||
namespace OgreInit
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ namespace CS
|
|||
CSVDoc::ViewManager mViewManager;
|
||||
CSVDoc::StartupDialogue mStartup;
|
||||
CSVDoc::NewGameDialogue mNewGame;
|
||||
CSVSettings::UserSettingsDialog mSettings;
|
||||
CSVSettings::Dialog mSettings;
|
||||
CSVDoc::FileDialog mFileDialog;
|
||||
boost::filesystem::path mLocal;
|
||||
boost::filesystem::path mResources;
|
||||
|
|
|
@ -9,11 +9,16 @@
|
|||
#include <QTextCodec>
|
||||
|
||||
#include <QFile>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include "settingcontainer.hpp"
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include "setting.hpp"
|
||||
#include "support.hpp"
|
||||
|
||||
/**
|
||||
* Workaround for problems with whitespaces in paths in older versions of Boost library
|
||||
*/
|
||||
|
@ -37,38 +42,151 @@ CSMSettings::UserSettings::UserSettings()
|
|||
assert(!mUserSettingsInstance);
|
||||
mUserSettingsInstance = this;
|
||||
|
||||
mReadWriteMessage = QObject::tr("<br><b>Could not open or create file for writing</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<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>");
|
||||
|
||||
buildEditorSettingDefaults();
|
||||
buildSettingModelDefaults();
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::buildEditorSettingDefaults()
|
||||
void CSMSettings::UserSettings::buildSettingModelDefaults()
|
||||
{
|
||||
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);
|
||||
QString section = "Window Size";
|
||||
{
|
||||
Setting *width = createSetting (Type_SingleText, section, "Width");
|
||||
Setting *height = createSetting (Type_SingleText, section, "Height");
|
||||
|
||||
windowHeight->setObjectName ("Height");
|
||||
windowWidth->setObjectName ("Width");
|
||||
rsDelegate->setObjectName ("Record Status Display");
|
||||
refIdTypeDelegate->setObjectName ("Referenceable ID Type Display");
|
||||
width->setWidgetWidth (5);
|
||||
height->setWidgetWidth (5);
|
||||
|
||||
SettingMap *displayFormatMap = new SettingMap;
|
||||
SettingMap *windowSizeMap = new SettingMap;
|
||||
width->setDefaultValues (QStringList() << "1024");
|
||||
height->setDefaultValues (QStringList() << "768");
|
||||
|
||||
displayFormatMap->insert (rsDelegate->objectName(), rsDelegate );
|
||||
displayFormatMap->insert (refIdTypeDelegate->objectName(), refIdTypeDelegate);
|
||||
width->setEditorSetting (true);
|
||||
height->setEditorSetting (true);
|
||||
|
||||
windowSizeMap->insert (windowWidth->objectName(), windowWidth );
|
||||
windowSizeMap->insert (windowHeight->objectName(), windowHeight );
|
||||
height->setViewLocation (2,2);
|
||||
width->setViewLocation (2,1);
|
||||
|
||||
mEditorSettingDefaults.insert ("Display Format", displayFormatMap);
|
||||
mEditorSettingDefaults.insert ("Window Size", windowSizeMap);
|
||||
/*
|
||||
*Create the proxy setting for predefined values
|
||||
*/
|
||||
Setting *preDefined = createSetting (Type_SingleList, section,
|
||||
"Pre-Defined",
|
||||
QStringList()
|
||||
<< "640 x 480"
|
||||
<< "800 x 600"
|
||||
<< "1024 x 768"
|
||||
<< "1440 x 900"
|
||||
);
|
||||
|
||||
preDefined->setViewLocation (1, 1);
|
||||
preDefined->setWidgetWidth (10);
|
||||
preDefined->setColumnSpan (2);
|
||||
|
||||
preDefined->addProxy (width,
|
||||
QStringList() << "640" << "800" << "1024" << "1440"
|
||||
);
|
||||
|
||||
preDefined->addProxy (height,
|
||||
QStringList() << "480" << "600" << "768" << "900"
|
||||
);
|
||||
}
|
||||
|
||||
section = "Display Format";
|
||||
{
|
||||
QString defaultValue = "Icon and Text";
|
||||
|
||||
QStringList values = QStringList()
|
||||
<< defaultValue << "Icon Only" << "Text Only";
|
||||
|
||||
Setting *rsd = createSetting (Type_SingleBool,
|
||||
section, "Record Status Display",
|
||||
values);
|
||||
|
||||
Setting *ritd = createSetting (Type_SingleBool,
|
||||
section, "Referenceable ID Type Display",
|
||||
values);
|
||||
|
||||
rsd->setEditorSetting (true);
|
||||
ritd->setEditorSetting (true);
|
||||
}
|
||||
|
||||
section = "Proxy Selection Test";
|
||||
{
|
||||
//create three setting objects, specifying the basic widget type,
|
||||
//the setting view name, the page name, and the default value
|
||||
Setting *masterBoolean = createSetting (Type_SingleBool, section,
|
||||
"Master Proxy",
|
||||
QStringList()
|
||||
<< "Profile One" << "Profile Two"
|
||||
<< "Profile Three" << "Profile Four"
|
||||
);
|
||||
|
||||
Setting *slaveBoolean = createSetting (Type_MultiBool, section,
|
||||
"Proxy Checkboxes",
|
||||
QStringList() << "One" << "Two"
|
||||
<< "Three" << "Four" << "Five"
|
||||
);
|
||||
|
||||
Setting *slaveSingleText = createSetting (Type_SingleText, section,
|
||||
"Proxy TextBox 1"
|
||||
);
|
||||
|
||||
Setting *slaveMultiText = createSetting (Type_SingleText, section,
|
||||
"ProxyTextBox 2"
|
||||
);
|
||||
|
||||
// There are three types of values:
|
||||
//
|
||||
// Declared values - Pre-determined values, typically for
|
||||
// combobox drop downs and boolean (radiobutton / checkbox) labels.
|
||||
// These values represent the total possible list of values that may
|
||||
// define a setting. No other values are allowed.
|
||||
//
|
||||
// Defined values - Values which represent the atual, current value of
|
||||
// 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.
|
||||
|
||||
masterBoolean->addProxy (slaveBoolean, QList <QStringList>()
|
||||
<< (QStringList() << "One" << "Three")
|
||||
<< (QStringList() << "One" << "Three")
|
||||
<< (QStringList() << "One" << "Three" << "Five")
|
||||
<< (QStringList() << "Two" << "Four")
|
||||
);
|
||||
|
||||
masterBoolean->addProxy (slaveSingleText, QList <QStringList>()
|
||||
<< (QStringList() << "Text A")
|
||||
<< (QStringList() << "Text B")
|
||||
<< (QStringList() << "Text A")
|
||||
<< (QStringList() << "Text C")
|
||||
);
|
||||
|
||||
masterBoolean->addProxy (slaveMultiText, QList <QStringList>()
|
||||
<< (QStringList() << "One" << "Three")
|
||||
<< (QStringList() << "One" << "Three")
|
||||
<< (QStringList() << "One" << "Three" << "Five")
|
||||
<< (QStringList() << "Two" << "Four")
|
||||
);
|
||||
|
||||
//settings with proxies are not serialized by default
|
||||
//other settings non-serialized for demo purposes
|
||||
slaveBoolean->setSerializable (false);
|
||||
slaveSingleText->setSerializable (false);
|
||||
slaveMultiText->setSerializable (false);
|
||||
|
||||
slaveBoolean->setDefaultValues (QStringList()
|
||||
<< "One" << "Three" << "Five");
|
||||
|
||||
slaveSingleText->setDefaultValue ("Text A");
|
||||
|
||||
slaveMultiText->setDefaultValues (QStringList()
|
||||
<< "One" << "Three" << "Five");
|
||||
|
||||
slaveSingleText->setWidgetWidth (24);
|
||||
slaveMultiText->setWidgetWidth (24);
|
||||
}
|
||||
}
|
||||
|
||||
CSMSettings::UserSettings::~UserSettings()
|
||||
|
@ -76,230 +194,83 @@ CSMSettings::UserSettings::~UserSettings()
|
|||
mUserSettingsInstance = 0;
|
||||
}
|
||||
|
||||
QTextStream *CSMSettings::UserSettings::openFileStream (const QString &filePath, bool isReadOnly) const
|
||||
{
|
||||
QIODevice::OpenMode openFlags = QIODevice::Text;
|
||||
|
||||
if (isReadOnly)
|
||||
openFlags = QIODevice::ReadOnly | openFlags;
|
||||
else
|
||||
openFlags = QIODevice::ReadWrite | QIODevice::Truncate | openFlags;
|
||||
|
||||
QFile *file = new QFile(filePath);
|
||||
QTextStream *stream = 0;
|
||||
|
||||
if (file->open(openFlags))
|
||||
{
|
||||
stream = new QTextStream(file);
|
||||
stream->setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
}
|
||||
|
||||
return stream;
|
||||
|
||||
}
|
||||
|
||||
bool CSMSettings::UserSettings::writeSettings(QMap<QString, CSMSettings::SettingList *> &settings)
|
||||
{
|
||||
QTextStream *stream = openFileStream(mUserFilePath);
|
||||
|
||||
bool success = (stream);
|
||||
|
||||
if (success)
|
||||
{
|
||||
QList<QString> keyList = settings.keys();
|
||||
|
||||
foreach (QString key, keyList)
|
||||
{
|
||||
SettingList *sectionSettings = settings[key];
|
||||
|
||||
*stream << "[" << key << "]" << '\n';
|
||||
|
||||
foreach (SettingContainer *item, *sectionSettings)
|
||||
*stream << item->objectName() << " = " << item->getValue() << '\n';
|
||||
}
|
||||
|
||||
stream->device()->close();
|
||||
delete stream;
|
||||
stream = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
displayFileErrorMessage(mReadWriteMessage, false);
|
||||
}
|
||||
|
||||
return (success);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
SectionMap loadedSettings;
|
||||
|
||||
QTextStream *stream = openFileStream (filePath, true);
|
||||
|
||||
bool success = (stream);
|
||||
|
||||
if (success)
|
||||
{
|
||||
//looks for a square bracket, "'\\["
|
||||
//that has one or more "not nothing" in it, "([^]]+)"
|
||||
//and is closed with a square bracket, "\\]"
|
||||
|
||||
QRegExp sectionRe("^\\[([^]]+)\\]");
|
||||
|
||||
//Find any character(s) that is/are not equal sign(s), "[^=]+"
|
||||
//followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*"
|
||||
//and one or more periods, "(.+)"
|
||||
|
||||
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
|
||||
|
||||
CSMSettings::SettingMap *settings = 0;
|
||||
QString section = "none";
|
||||
|
||||
while (!stream->atEnd())
|
||||
{
|
||||
QString line = stream->readLine().simplified();
|
||||
|
||||
if (line.isEmpty() || line.startsWith("#"))
|
||||
continue;
|
||||
|
||||
//if a section is found, push it onto a new QStringList
|
||||
//and push the QStringList onto
|
||||
if (sectionRe.exactMatch(line))
|
||||
{
|
||||
//add the previous section's settings to the member map
|
||||
if (settings)
|
||||
loadedSettings.insert(section, settings);
|
||||
|
||||
//save new section and create a new list
|
||||
section = sectionRe.cap(1);
|
||||
settings = new SettingMap;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (keyRe.indexIn(line) != -1)
|
||||
{
|
||||
SettingContainer *sc = new SettingContainer (keyRe.cap(2).simplified());
|
||||
sc->setObjectName(keyRe.cap(1).simplified());
|
||||
(*settings)[keyRe.cap(1).simplified()] = sc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
mUserFilePath = QString::fromUtf8
|
||||
(mCfgMgr.getUserConfigPath().c_str()) + fileName.toUtf8();
|
||||
|
||||
//global
|
||||
QString globalFilePath = QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName;
|
||||
bool globalOk = loadFromFile(globalFilePath);
|
||||
QString global = QString::fromUtf8
|
||||
(mCfgMgr.getGlobalPath().c_str()) + fileName.toUtf8();
|
||||
|
||||
QString local = QString::fromUtf8
|
||||
(mCfgMgr.getLocalPath().c_str()) + fileName.toUtf8();
|
||||
|
||||
//local
|
||||
QString localFilePath = QString::fromStdString(mCfgMgr.getLocalPath().string()) + fileName;
|
||||
bool localOk = loadFromFile(localFilePath);
|
||||
//open user and global streams
|
||||
QTextStream *userStream = openFilestream (mUserFilePath, true);
|
||||
QTextStream *otherStream = openFilestream (global, true);
|
||||
|
||||
//user
|
||||
mUserFilePath = QString::fromStdString(mCfgMgr.getUserConfigPath().string()) + fileName;
|
||||
loadFromFile(mUserFilePath);
|
||||
//failed stream, try for local
|
||||
if (!otherStream)
|
||||
otherStream = openFilestream (local, true);
|
||||
|
||||
if (!(localOk || globalOk))
|
||||
//error condition - notify and return
|
||||
if (!otherStream || !userStream)
|
||||
{
|
||||
QString message = QObject::tr("<br><b>Could not open user settings files for reading</b><br><br> \
|
||||
Global and local settings files could not be read.\
|
||||
You may have incorrect file permissions or the OpenCS installation may be corrupted.<br>");
|
||||
QString message = QObject::tr("<br><b>An error was encountered loading \
|
||||
user settings files.</b><br><br> One or several files could not \
|
||||
be read. This may be caused by a missing configuration file, \
|
||||
incorrect file permissions or a corrupted installation of \
|
||||
OpenCS.<br>");
|
||||
|
||||
message += QObject::tr("<br>Global filepath: ") + globalFilePath;
|
||||
message += QObject::tr("<br>Local filepath: ") + localFilePath;
|
||||
message += QObject::tr("<br>Global filepath: ") + global;
|
||||
message += QObject::tr("<br>Local filepath: ") + local;
|
||||
message += QObject::tr("<br>User filepath: ") + mUserFilePath;
|
||||
|
||||
displayFileErrorMessage ( message, true);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::updateSettings (const QString §ionName, const QString &settingName)
|
||||
{
|
||||
|
||||
SettingMap *settings = getValidSettings(sectionName);
|
||||
|
||||
if (!settings)
|
||||
return;
|
||||
}
|
||||
|
||||
if (settingName.isEmpty())
|
||||
{
|
||||
foreach (const SettingContainer *setting, *settings)
|
||||
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (settings->find(settingName) != settings->end())
|
||||
{
|
||||
const SettingContainer *setting = settings->value(settingName);
|
||||
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
|
||||
}
|
||||
}
|
||||
//success condition - merge the two streams into a single map and save
|
||||
DefinitionPageMap totalMap = readFilestream (userStream);
|
||||
DefinitionPageMap otherMap = readFilestream(otherStream);
|
||||
|
||||
//merging other settings file in and ignore duplicate settings to
|
||||
//avoid overwriting user-level settings
|
||||
mergeSettings (totalMap, otherMap);
|
||||
|
||||
if (!totalMap.isEmpty())
|
||||
addDefinitions (totalMap);
|
||||
}
|
||||
|
||||
QString CSMSettings::UserSettings::getSetting (const QString §ion, const QString &setting) const
|
||||
void CSMSettings::UserSettings::saveSettings
|
||||
(const QMap <QString, QStringList> &settingMap)
|
||||
{
|
||||
SettingMap *settings = getValidSettings(section);
|
||||
for (int i = 0; i < settings().size(); i++)
|
||||
{
|
||||
Setting* setting = settings().at(i);
|
||||
|
||||
QString retVal = "";
|
||||
QString key = setting->page() + '.' + setting->name();
|
||||
|
||||
if (settings->find(setting) != settings->end())
|
||||
retVal = settings->value(setting)->getValue();
|
||||
if (!settingMap.keys().contains(key))
|
||||
continue;
|
||||
|
||||
return retVal;
|
||||
setting->setDefinedValues (settingMap.value(key));
|
||||
}
|
||||
|
||||
writeFilestream (openFilestream (mUserFilePath, false), settingMap);
|
||||
}
|
||||
|
||||
QString CSMSettings::UserSettings::settingValue (const QString §ion,
|
||||
const QString &name)
|
||||
{
|
||||
Setting *setting = findSetting(section, name);
|
||||
|
||||
if (setting)
|
||||
{
|
||||
if (!setting->definedValues().isEmpty())
|
||||
return setting->definedValues().at(0);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
|
||||
|
@ -307,49 +278,3 @@ CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
|
|||
assert(mUserSettingsInstance);
|
||||
return *mUserSettingsInstance;
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::displayFileErrorMessage(const QString &message, bool isReadOnly)
|
||||
{
|
||||
// File cannot be opened or created
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle(QObject::tr("OpenCS configuration file I/O error"));
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
|
||||
if (!isReadOnly)
|
||||
msgBox.setText (mReadWriteMessage + message);
|
||||
else
|
||||
msgBox.setText (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;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "support.hpp"
|
||||
#include "settingmanager.hpp"
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
|
@ -21,17 +21,15 @@ class QFile;
|
|||
|
||||
namespace CSMSettings {
|
||||
|
||||
struct UserSettings: public QObject
|
||||
class UserSettings: public SettingManager
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
SectionMap mSectionSettings;
|
||||
SectionMap mEditorSettingDefaults;
|
||||
|
||||
static UserSettings *mUserSettingsInstance;
|
||||
QString mUserFilePath;
|
||||
Files::ConfigurationManager mCfgMgr;
|
||||
|
||||
QString mReadOnlyMessage;
|
||||
QString mReadWriteMessage;
|
||||
|
||||
|
@ -47,48 +45,23 @@ namespace CSMSettings {
|
|||
void operator= (UserSettings const &); //not implemented
|
||||
|
||||
/// Writes settings to the last loaded settings file
|
||||
bool writeSettings(QMap<QString, SettingList *> §ions);
|
||||
|
||||
/// Called from editor to trigger signal to update the specified setting.
|
||||
/// If no setting name is specified, all settings found in the specified section are updated.
|
||||
void updateSettings (const QString §ionName, const QString &settingName = "");
|
||||
bool writeSettings();
|
||||
|
||||
/// Retrieves the settings file at all three levels (global, local and user).
|
||||
|
||||
/// \todo Multi-valued settings are not fully implemented. Setting values
|
||||
/// \todo loaded in later files will always overwrite previously loaded values.
|
||||
void loadSettings (const QString &fileName);
|
||||
|
||||
/// Returns the entire map of settings across all sections
|
||||
const SectionMap &getSectionMap () const;
|
||||
/// Writes settings to the user's config file path
|
||||
void saveSettings (const QMap <QString, QStringList > &settingMap);
|
||||
|
||||
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;
|
||||
QString settingValue (const QString §ion, const QString &name);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/// Opens a QTextStream from the provided path as read-only or read-write.
|
||||
QTextStream *openFileStream (const QString &filePath, bool isReadOnly = false) const;
|
||||
|
||||
/// 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;
|
||||
void buildSettingModelDefaults();
|
||||
|
||||
signals:
|
||||
|
||||
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
|
||||
void userSettingUpdated(const QString &, const QStringList &);
|
||||
};
|
||||
}
|
||||
#endif // USERSETTINGS_HPP
|
||||
|
|
|
@ -12,16 +12,15 @@ CSMWorld::UniversalId CSVDoc::SubView::getUniversalId() const
|
|||
return mUniversalId;
|
||||
}
|
||||
|
||||
void CSVDoc::SubView::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
{
|
||||
}
|
||||
|
||||
void CSVDoc::SubView::setStatusBar (bool show) {}
|
||||
|
||||
void CSVDoc::SubView::useHint (const std::string& hint) {}
|
||||
|
||||
void CSVDoc::SubView::updateUserSetting (const QString &, const QStringList &)
|
||||
{}
|
||||
|
||||
void CSVDoc::SubView::setUniversalId (const CSMWorld::UniversalId& id)
|
||||
{
|
||||
mUniversalId = id;
|
||||
setWindowTitle (mUniversalId.toString().c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,9 @@ namespace CSVDoc
|
|||
CSMWorld::UniversalId getUniversalId() const;
|
||||
|
||||
virtual void setEditLock (bool locked) = 0;
|
||||
virtual void updateEditorSetting (const QString &, const QString &);
|
||||
|
||||
virtual void updateUserSetting
|
||||
(const QString &, const QStringList &);
|
||||
|
||||
virtual void setStatusBar (bool show);
|
||||
///< Default implementation: ignored
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "../../model/doc/document.hpp"
|
||||
#include "../world/subviews.hpp"
|
||||
#include "../tools/subviews.hpp"
|
||||
#include "../settings/usersettingsdialog.hpp"
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
#include "viewmanager.hpp"
|
||||
#include "operations.hpp"
|
||||
#include "subview.hpp"
|
||||
|
@ -235,8 +235,11 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
|
|||
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1),
|
||||
mViewTotal (totalViews)
|
||||
{
|
||||
QString width = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Width"));
|
||||
QString height = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Height"));
|
||||
QString width = CSMSettings::UserSettings::instance().settingValue
|
||||
(QString("Window Size"), QString("Width"));
|
||||
|
||||
QString height = CSMSettings::UserSettings::instance().settingValue
|
||||
(QString("Window Size"), QString("Height"));
|
||||
|
||||
resize (width.toInt(), height.toInt());
|
||||
|
||||
|
@ -336,7 +339,10 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin
|
|||
connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&, const std::string&)), this,
|
||||
SLOT (addSubView (const CSMWorld::UniversalId&, const std::string&)));
|
||||
|
||||
CSMSettings::UserSettings::instance().updateSettings("Display Format");
|
||||
connect (&CSMSettings::UserSettings::instance(),
|
||||
SIGNAL (userSettingUpdated (const QString &, const QStringList &)),
|
||||
view,
|
||||
SLOT (updateUserSetting (const QString &, const QStringList &)));
|
||||
|
||||
view->show();
|
||||
}
|
||||
|
@ -484,24 +490,19 @@ void CSVDoc::View::resizeViewHeight (int height)
|
|||
resize (geometry().width(), height);
|
||||
}
|
||||
|
||||
void CSVDoc::View::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
void CSVDoc::View::updateUserSetting
|
||||
(const QString &name, const QStringList &list)
|
||||
{
|
||||
if ( (settingName == "Record Status Display") || (settingName == "Referenceable ID Type Display") )
|
||||
{
|
||||
foreach (QObject *view, mSubViewWindow.children())
|
||||
{
|
||||
// not all mSubviewWindow children are CSVDoc::Subview objects
|
||||
CSVDoc::SubView *subview = dynamic_cast<CSVDoc::SubView *>(view);
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (subview)
|
||||
subview->updateEditorSetting (settingName, settingValue);
|
||||
}
|
||||
}
|
||||
else if (settingName == "Width")
|
||||
resizeViewWidth (settingValue.toInt());
|
||||
int value = list.at(0).toInt();
|
||||
|
||||
else if (settingName == "Height")
|
||||
resizeViewHeight (settingValue.toInt());
|
||||
if (name == "Width")
|
||||
resizeViewWidth (value);
|
||||
|
||||
else if (name == "Height")
|
||||
resizeViewHeight (value);
|
||||
}
|
||||
|
||||
void CSVDoc::View::toggleShowStatusBar (bool show)
|
||||
|
|
|
@ -126,6 +126,8 @@ namespace CSVDoc
|
|||
|
||||
void abortOperation (int type);
|
||||
|
||||
void updateUserSetting (const QString &, const QStringList &);
|
||||
|
||||
private slots:
|
||||
|
||||
void newView();
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
#include "../world/vartypedelegate.hpp"
|
||||
#include "../world/recordstatusdelegate.hpp"
|
||||
#include "../world/idtypedelegate.hpp"
|
||||
#include "../settings/usersettingsdialog.hpp"
|
||||
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
|
||||
#include "view.hpp"
|
||||
|
||||
|
@ -83,9 +84,6 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
|||
for (std::size_t i=0; i<sizeof (sMapping)/sizeof (Mapping); ++i)
|
||||
mDelegateFactories->add (sMapping[i].mDisplay, new CSVWorld::EnumDelegateFactory (
|
||||
CSMWorld::Columns::getEnums (sMapping[i].mColumnId), sMapping[i].mAllowNone));
|
||||
|
||||
connect (&CSMSettings::UserSettings::instance(), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)),
|
||||
this, SLOT (slotUpdateEditorSetting (const QString &, const QString &)));
|
||||
}
|
||||
|
||||
CSVDoc::ViewManager::~ViewManager()
|
||||
|
@ -119,6 +117,11 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
|||
connect (view, SIGNAL (loadDocumentRequest ()), this, SIGNAL (loadDocumentRequest()));
|
||||
connect (view, SIGNAL (editSettingsRequest()), this, SIGNAL (editSettingsRequest()));
|
||||
|
||||
connect (&CSMSettings::UserSettings::instance(),
|
||||
SIGNAL (userSettingUpdated(const QString &, const QStringList &)),
|
||||
view,
|
||||
SLOT (updateUserSetting (const QString &, const QStringList &)));
|
||||
|
||||
updateIndices();
|
||||
|
||||
return view;
|
||||
|
@ -313,9 +316,3 @@ void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view)
|
|||
if (notifySaveOnClose (view))
|
||||
QApplication::instance()->exit();
|
||||
}
|
||||
|
||||
void CSVDoc::ViewManager::slotUpdateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
{
|
||||
foreach (CSVDoc::View *view, mViews)
|
||||
view->updateEditorSetting (settingName, settingValue);
|
||||
}
|
||||
|
|
|
@ -76,9 +76,6 @@ namespace CSVDoc
|
|||
void progress (int current, int max, int type, int threads, CSMDoc::Document *document);
|
||||
|
||||
void onExitWarningHandler(int state, CSMDoc::Document* document);
|
||||
|
||||
/// connected to update signal in UserSettings
|
||||
void slotUpdateEditorSetting (const QString &, const QString &);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -33,12 +33,13 @@ void CSVTools::ReportSubView::setEditLock (bool locked)
|
|||
// ignored. We don't change document state anyway.
|
||||
}
|
||||
|
||||
void CSVTools::ReportSubView::updateEditorSetting (const QString& key, const QString& value)
|
||||
void CSVTools::ReportSubView::updateUserSetting
|
||||
(const QString &name, const QStringList &list)
|
||||
{
|
||||
mIdTypeDelegate->updateEditorSetting (key, value);
|
||||
mIdTypeDelegate->updateUserSetting (name, list);
|
||||
}
|
||||
|
||||
void CSVTools::ReportSubView::show (const QModelIndex& index)
|
||||
{
|
||||
focusId (mModel->getUniversalId (index.row()), "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ namespace CSVTools
|
|||
|
||||
virtual void setEditLock (bool locked);
|
||||
|
||||
virtual void updateEditorSetting (const QString&, const QString&);
|
||||
virtual void updateUserSetting
|
||||
(const QString &, const QStringList &);
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -47,4 +48,4 @@ namespace CSVTools
|
|||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -449,15 +449,19 @@ void CSVWorld::Table::previewRecord()
|
|||
}
|
||||
}
|
||||
|
||||
void CSVWorld::Table::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
void CSVWorld::Table::updateUserSetting
|
||||
(const QString &name, const QStringList &list)
|
||||
{
|
||||
int columns = mModel->columnCount();
|
||||
|
||||
for (int i=0; i<columns; ++i)
|
||||
if (QAbstractItemDelegate *delegate = itemDelegateForColumn (i))
|
||||
if (dynamic_cast<CommandDelegate&> (*delegate).
|
||||
updateEditorSetting (settingName, settingValue))
|
||||
emit dataChanged (mModel->index (0, i), mModel->index (mModel->rowCount()-1, i));
|
||||
if (dynamic_cast<CommandDelegate&>
|
||||
(*delegate).updateUserSetting (name, list))
|
||||
{
|
||||
emit dataChanged (mModel->index (0, i),
|
||||
mModel->index (mModel->rowCount()-1, i));
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::Table::tableSizeUpdate()
|
||||
|
@ -598,4 +602,4 @@ std::vector<std::string> CSVWorld::Table::getColumnsWithDisplay(CSMWorld::Column
|
|||
}
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace CSVWorld
|
|||
|
||||
CSMWorld::UniversalId getUniversalId (int row) const;
|
||||
|
||||
void updateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
void updateUserSetting (const QString &name, const QStringList &list);
|
||||
|
||||
std::vector<std::string> getColumnsWithDisplay(CSMWorld::ColumnBase::Display display) const;
|
||||
|
||||
|
|
|
@ -82,9 +82,10 @@ void CSVWorld::TableSubView::editRequest (const CSMWorld::UniversalId& id, const
|
|||
focusId (id, hint);
|
||||
}
|
||||
|
||||
void CSVWorld::TableSubView::updateEditorSetting(const QString &settingName, const QString &settingValue)
|
||||
void CSVWorld::TableSubView::updateUserSetting
|
||||
(const QString &name, const QStringList &list)
|
||||
{
|
||||
mTable->updateEditorSetting(settingName, settingValue);
|
||||
mTable->updateUserSetting(name, list);
|
||||
}
|
||||
|
||||
void CSVWorld::TableSubView::setStatusBar (bool show)
|
||||
|
@ -134,4 +135,4 @@ bool CSVWorld::TableSubView::eventFilter (QObject* object, QEvent* event)
|
|||
return handled;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@ namespace CSVWorld
|
|||
|
||||
virtual void setEditLock (bool locked);
|
||||
|
||||
virtual void updateEditorSetting (const QString& key, const QString& value);
|
||||
virtual void updateUserSetting
|
||||
(const QString& name, const QStringList &list);
|
||||
|
||||
virtual void setStatusBar (bool show);
|
||||
|
||||
|
|
|
@ -196,8 +196,8 @@ bool CSVWorld::CommandDelegate::isEditLocked() const
|
|||
return mEditLock;
|
||||
}
|
||||
|
||||
bool CSVWorld::CommandDelegate::updateEditorSetting (const QString &settingName,
|
||||
const QString &settingValue)
|
||||
bool CSVWorld::CommandDelegate::updateUserSetting (const QString &name,
|
||||
const QStringList &list)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -263,4 +263,4 @@ void CSVWorld::DropLineEdit::dropEvent(QDropEvent *event)
|
|||
const CSMWorld::TableMimeData* data(dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData()));
|
||||
emit tableMimeDataDropped(data->getData(), data->getDocumentPtr());
|
||||
//WIP
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,9 @@ namespace CSVWorld
|
|||
|
||||
bool isEditLocked() const;
|
||||
|
||||
virtual bool updateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
virtual bool updateUserSetting
|
||||
(const QString &name, const QStringList &list);
|
||||
|
||||
///< \return Does column require update?
|
||||
|
||||
virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const;
|
||||
|
|
Loading…
Reference in a new issue