Re-link user settings to editor main application

actorid
graffy76 11 years ago
parent e3384e3999
commit 4b607d658f

@ -28,6 +28,7 @@ CS::Editor::Editor (OgreInit::OgreInit& ogreInit)
setupDataFiles (config.first); setupDataFiles (config.first);
CSMSettings::UserSettings::instance().loadSettings ("opencs.cfg"); CSMSettings::UserSettings::instance().loadSettings ("opencs.cfg");
mSettings.setModel (CSMSettings::UserSettings::instance());
ogreInit.init ((mCfgMgr.getUserConfigPath() / "opencsOgre.log").string()); 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()); 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> >()); 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/filedialog.hpp"
#include "view/doc/newgame.hpp" #include "view/doc/newgame.hpp"
#include "view/settings/usersettingsdialog.hpp" #include "view/settings/dialog.hpp"
namespace OgreInit namespace OgreInit
{ {
@ -43,7 +43,7 @@ namespace CS
CSVDoc::ViewManager mViewManager; CSVDoc::ViewManager mViewManager;
CSVDoc::StartupDialogue mStartup; CSVDoc::StartupDialogue mStartup;
CSVDoc::NewGameDialogue mNewGame; CSVDoc::NewGameDialogue mNewGame;
CSVSettings::UserSettingsDialog mSettings; CSVSettings::Dialog mSettings;
CSVDoc::FileDialog mFileDialog; CSVDoc::FileDialog mFileDialog;
boost::filesystem::path mLocal; boost::filesystem::path mLocal;
boost::filesystem::path mResources; boost::filesystem::path mResources;

@ -9,11 +9,16 @@
#include <QTextCodec> #include <QTextCodec>
#include <QFile> #include <QFile>
#include <QSortFilterProxyModel>
#include <QDebug>
#include <components/files/configurationmanager.hpp> #include <components/files/configurationmanager.hpp>
#include "settingcontainer.hpp"
#include <boost/version.hpp> #include <boost/version.hpp>
#include "setting.hpp"
#include "support.hpp"
/** /**
* Workaround for problems with whitespaces in paths in older versions of Boost library * Workaround for problems with whitespaces in paths in older versions of Boost library
*/ */
@ -37,269 +42,235 @@ CSMSettings::UserSettings::UserSettings()
assert(!mUserSettingsInstance); assert(!mUserSettingsInstance);
mUserSettingsInstance = this; mUserSettingsInstance = this;
mReadWriteMessage = QObject::tr("<br><b>Could not open or create file for writing</b><br><br> \ buildSettingModelDefaults();
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();
} }
void CSMSettings::UserSettings::buildEditorSettingDefaults() void CSMSettings::UserSettings::buildSettingModelDefaults()
{ {
SettingContainer *windowHeight = new SettingContainer("768", this); QString section = "Window Size";
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()
{
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); Setting *width = createSetting (Type_SingleText, section, "Width");
stream->setCodec(QTextCodec::codecForName("UTF-8")); Setting *height = createSetting (Type_SingleText, section, "Height");
width->setWidgetWidth (5);
height->setWidgetWidth (5);
width->setDefaultValues (QStringList() << "1024");
height->setDefaultValues (QStringList() << "768");
width->setEditorSetting (true);
height->setEditorSetting (true);
height->setViewLocation (2,2);
width->setViewLocation (2,1);
/*
*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"
);
} }
return stream; section = "Display Format";
}
bool CSMSettings::UserSettings::writeSettings(QMap<QString, CSMSettings::SettingList *> &settings)
{
QTextStream *stream = openFileStream(mUserFilePath);
bool success = (stream);
if (success)
{ {
QList<QString> keyList = settings.keys(); QString defaultValue = "Icon and Text";
foreach (QString key, keyList) QStringList values = QStringList()
{ << defaultValue << "Icon Only" << "Text Only";
SettingList *sectionSettings = settings[key];
*stream << "[" << key << "]" << '\n'; Setting *rsd = createSetting (Type_SingleBool,
section, "Record Status Display",
values);
foreach (SettingContainer *item, *sectionSettings) Setting *ritd = createSetting (Type_SingleBool,
*stream << item->objectName() << " = " << item->getValue() << '\n'; section, "Referenceable ID Type Display",
} values);
stream->device()->close(); rsd->setEditorSetting (true);
delete stream; ritd->setEditorSetting (true);
stream = 0;
} }
else
section = "Proxy Selection Test";
{ {
displayFileErrorMessage(mReadWriteMessage, false); //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);
} }
return (success);
} }
CSMSettings::UserSettings::~UserSettings()
const CSMSettings::SectionMap &CSMSettings::UserSettings::getSectionMap() const
{ {
return mSectionSettings; mUserSettingsInstance = 0;
} }
const CSMSettings::SettingMap *CSMSettings::UserSettings::getSettings(const QString &sectionName) const void CSMSettings::UserSettings::loadSettings (const QString &fileName)
{ {
return getValidSettings(sectionName); mUserFilePath = QString::fromUtf8
} (mCfgMgr.getUserConfigPath().c_str()) + fileName.toUtf8();
bool CSMSettings::UserSettings::loadFromFile(const QString &filePath) QString global = QString::fromUtf8
{ (mCfgMgr.getGlobalPath().c_str()) + fileName.toUtf8();
if (filePath.isEmpty())
return false;
SectionMap loadedSettings; QString local = QString::fromUtf8
(mCfgMgr.getLocalPath().c_str()) + fileName.toUtf8();
QTextStream *stream = openFileStream (filePath, true); //open user and global streams
QTextStream *userStream = openFilestream (mUserFilePath, true);
QTextStream *otherStream = openFilestream (global, true);
bool success = (stream); //failed stream, try for local
if (!otherStream)
otherStream = openFilestream (local, true);
if (success) //error condition - notify and return
if (!otherStream || !userStream)
{ {
//looks for a square bracket, "'\\[" QString message = QObject::tr("<br><b>An error was encountered loading \
//that has one or more "not nothing" in it, "([^]]+)" user settings files.</b><br><br> One or several files could not \
//and is closed with a square bracket, "\\]" be read. This may be caused by a missing configuration file, \
incorrect file permissions or a corrupted installation of \
QRegExp sectionRe("^\\[([^]]+)\\]"); OpenCS.<br>");
//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) message += QObject::tr("<br>Global filepath: ") + global;
{ message += QObject::tr("<br>Local filepath: ") + local;
SettingContainer *sc = new SettingContainer (keyRe.cap(2).simplified()); message += QObject::tr("<br>User filepath: ") + mUserFilePath;
sc->setObjectName(keyRe.cap(1).simplified());
(*settings)[keyRe.cap(1).simplified()] = sc;
}
} displayFileErrorMessage ( message, true);
return;
loadedSettings.insert(section, settings);
stream->device()->close();
delete stream;
stream = 0;
} }
mergeMap (loadedSettings); //success condition - merge the two streams into a single map and save
DefinitionPageMap totalMap = readFilestream (userStream);
DefinitionPageMap otherMap = readFilestream(otherStream);
return success; //merging other settings file in and ignore duplicate settings to
} //avoid overwriting user-level settings
mergeSettings (totalMap, otherMap);
void CSMSettings::UserSettings::mergeMap (const CSMSettings::SectionMap &sectionSettings) if (!totalMap.isEmpty())
{ addDefinitions (totalMap);
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::saveSettings
(const QMap <QString, QStringList> &settingMap)
{ {
mSectionSettings.clear(); for (int i = 0; i < settings().size(); i++)
//global
QString globalFilePath = QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName;
bool globalOk = loadFromFile(globalFilePath);
//local
QString localFilePath = QString::fromStdString(mCfgMgr.getLocalPath().string()) + fileName;
bool localOk = loadFromFile(localFilePath);
//user
mUserFilePath = QString::fromStdString(mCfgMgr.getUserConfigPath().string()) + fileName;
loadFromFile(mUserFilePath);
if (!(localOk || globalOk))
{ {
QString message = QObject::tr("<br><b>Could not open user settings files for reading</b><br><br> \ Setting* setting = settings().at(i);
Global and local settings files could not be read.\
You may have incorrect file permissions or the OpenCS installation may be corrupted.<br>");
message += QObject::tr("<br>Global filepath: ") + globalFilePath; QString key = setting->page() + '.' + setting->name();
message += QObject::tr("<br>Local filepath: ") + localFilePath;
displayFileErrorMessage ( message, true); if (!settingMap.keys().contains(key))
continue;
setting->setDefinedValues (settingMap.value(key));
} }
writeFilestream (openFilestream (mUserFilePath, false), settingMap);
} }
void CSMSettings::UserSettings::updateSettings (const QString &sectionName, const QString &settingName) QString CSMSettings::UserSettings::settingValue (const QString &section,
const QString &name)
{ {
Setting *setting = findSetting(section, name);
SettingMap *settings = getValidSettings(sectionName); if (setting)
if (!settings)
return;
if (settingName.isEmpty())
{
foreach (const SettingContainer *setting, *settings)
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
}
else
{ {
if (settings->find(settingName) != settings->end()) if (!setting->definedValues().isEmpty())
{ return setting->definedValues().at(0);
const SettingContainer *setting = settings->value(settingName);
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
}
} }
} return "";
QString CSMSettings::UserSettings::getSetting (const QString &section, const QString &setting) const
{
SettingMap *settings = getValidSettings(section);
QString retVal = "";
if (settings->find(setting) != settings->end())
retVal = settings->value(setting)->getValue();
return retVal;
} }
CSMSettings::UserSettings& CSMSettings::UserSettings::instance() CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
@ -307,49 +278,3 @@ CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
assert(mUserSettingsInstance); assert(mUserSettingsInstance);
return *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 &sectionName) 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 <boost/filesystem/path.hpp>
#include "support.hpp" #include "settingmanager.hpp"
#ifndef Q_MOC_RUN #ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp> #include <components/files/configurationmanager.hpp>
@ -21,17 +21,15 @@ class QFile;
namespace CSMSettings { namespace CSMSettings {
struct UserSettings: public QObject class UserSettings: public SettingManager
{ {
Q_OBJECT Q_OBJECT
SectionMap mSectionSettings;
SectionMap mEditorSettingDefaults;
static UserSettings *mUserSettingsInstance; static UserSettings *mUserSettingsInstance;
QString mUserFilePath; QString mUserFilePath;
Files::ConfigurationManager mCfgMgr; Files::ConfigurationManager mCfgMgr;
QString mReadOnlyMessage; QString mReadOnlyMessage;
QString mReadWriteMessage; QString mReadWriteMessage;
@ -47,48 +45,23 @@ namespace CSMSettings {
void operator= (UserSettings const &); //not implemented void operator= (UserSettings const &); //not implemented
/// Writes settings to the last loaded settings file /// Writes settings to the last loaded settings file
bool writeSettings(QMap<QString, SettingList *> &sections); bool writeSettings();
/// 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 &sectionName, const QString &settingName = "");
/// Retrieves the settings file at all three levels (global, local and user). /// 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); void loadSettings (const QString &fileName);
/// Returns the entire map of settings across all sections /// Writes settings to the user's config file path
const SectionMap &getSectionMap () const; void saveSettings (const QMap <QString, QStringList > &settingMap);
const SettingMap *getSettings (const QString &sectionName) const;
/// Retrieves the value as a QString of the specified setting in the specified section QString settingValue (const QString &section, const QString &name);
QString getSetting(const QString &section, const QString &setting) const;
private: private:
void buildSettingModelDefaults();
/// 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 &sectionName) const;
signals: signals:
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); void userSettingUpdated(const QString &, const QStringList &);
}; };
} }
#endif // USERSETTINGS_HPP #endif // USERSETTINGS_HPP

@ -12,16 +12,15 @@ CSMWorld::UniversalId CSVDoc::SubView::getUniversalId() const
return mUniversalId; return mUniversalId;
} }
void CSVDoc::SubView::updateEditorSetting (const QString &settingName, const QString &settingValue)
{
}
void CSVDoc::SubView::setStatusBar (bool show) {} void CSVDoc::SubView::setStatusBar (bool show) {}
void CSVDoc::SubView::useHint (const std::string& hint) {} void CSVDoc::SubView::useHint (const std::string& hint) {}
void CSVDoc::SubView::updateUserSetting (const QString &, const QStringList &)
{}
void CSVDoc::SubView::setUniversalId (const CSMWorld::UniversalId& id) void CSVDoc::SubView::setUniversalId (const CSMWorld::UniversalId& id)
{ {
mUniversalId = id; mUniversalId = id;
setWindowTitle (mUniversalId.toString().c_str()); setWindowTitle (mUniversalId.toString().c_str());
} }

@ -37,7 +37,9 @@ namespace CSVDoc
CSMWorld::UniversalId getUniversalId() const; CSMWorld::UniversalId getUniversalId() const;
virtual void setEditLock (bool locked) = 0; 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); virtual void setStatusBar (bool show);
///< Default implementation: ignored ///< Default implementation: ignored

@ -12,7 +12,7 @@
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../world/subviews.hpp" #include "../world/subviews.hpp"
#include "../tools/subviews.hpp" #include "../tools/subviews.hpp"
#include "../settings/usersettingsdialog.hpp" #include "../../model/settings/usersettings.hpp"
#include "viewmanager.hpp" #include "viewmanager.hpp"
#include "operations.hpp" #include "operations.hpp"
#include "subview.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), : mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1),
mViewTotal (totalViews) mViewTotal (totalViews)
{ {
QString width = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Width")); QString width = CSMSettings::UserSettings::instance().settingValue
QString height = CSMSettings::UserSettings::instance().getSetting(QString("Window Size"), QString("Height")); (QString("Window Size"), QString("Width"));
QString height = CSMSettings::UserSettings::instance().settingValue
(QString("Window Size"), QString("Height"));
resize (width.toInt(), height.toInt()); 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, connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&, const std::string&)), this,
SLOT (addSubView (const CSMWorld::UniversalId&, const std::string&))); 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(); view->show();
} }
@ -484,24 +490,19 @@ void CSVDoc::View::resizeViewHeight (int height)
resize (geometry().width(), 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") ) if (list.isEmpty())
{ return;
foreach (QObject *view, mSubViewWindow.children())
{ int value = list.at(0).toInt();
// not all mSubviewWindow children are CSVDoc::Subview objects
CSVDoc::SubView *subview = dynamic_cast<CSVDoc::SubView *>(view); if (name == "Width")
resizeViewWidth (value);
if (subview)
subview->updateEditorSetting (settingName, settingValue);
}
}
else if (settingName == "Width")
resizeViewWidth (settingValue.toInt());
else if (settingName == "Height") else if (name == "Height")
resizeViewHeight (settingValue.toInt()); resizeViewHeight (value);
} }
void CSVDoc::View::toggleShowStatusBar (bool show) void CSVDoc::View::toggleShowStatusBar (bool show)

@ -126,6 +126,8 @@ namespace CSVDoc
void abortOperation (int type); void abortOperation (int type);
void updateUserSetting (const QString &, const QStringList &);
private slots: private slots:
void newView(); void newView();

@ -15,7 +15,8 @@
#include "../world/vartypedelegate.hpp" #include "../world/vartypedelegate.hpp"
#include "../world/recordstatusdelegate.hpp" #include "../world/recordstatusdelegate.hpp"
#include "../world/idtypedelegate.hpp" #include "../world/idtypedelegate.hpp"
#include "../settings/usersettingsdialog.hpp"
#include "../../model/settings/usersettings.hpp"
#include "view.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) for (std::size_t i=0; i<sizeof (sMapping)/sizeof (Mapping); ++i)
mDelegateFactories->add (sMapping[i].mDisplay, new CSVWorld::EnumDelegateFactory ( mDelegateFactories->add (sMapping[i].mDisplay, new CSVWorld::EnumDelegateFactory (
CSMWorld::Columns::getEnums (sMapping[i].mColumnId), sMapping[i].mAllowNone)); 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() 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 (loadDocumentRequest ()), this, SIGNAL (loadDocumentRequest()));
connect (view, SIGNAL (editSettingsRequest()), this, SIGNAL (editSettingsRequest())); 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(); updateIndices();
return view; return view;
@ -313,9 +316,3 @@ void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view)
if (notifySaveOnClose (view)) if (notifySaveOnClose (view))
QApplication::instance()->exit(); 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 progress (int current, int max, int type, int threads, CSMDoc::Document *document);
void onExitWarningHandler(int state, 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. // 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) void CSVTools::ReportSubView::show (const QModelIndex& index)
{ {
focusId (mModel->getUniversalId (index.row()), ""); focusId (mModel->getUniversalId (index.row()), "");
} }

@ -39,7 +39,8 @@ namespace CSVTools
virtual void setEditLock (bool locked); virtual void setEditLock (bool locked);
virtual void updateEditorSetting (const QString&, const QString&); virtual void updateUserSetting
(const QString &, const QStringList &);
private slots: 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(); int columns = mModel->columnCount();
for (int i=0; i<columns; ++i) for (int i=0; i<columns; ++i)
if (QAbstractItemDelegate *delegate = itemDelegateForColumn (i)) if (QAbstractItemDelegate *delegate = itemDelegateForColumn (i))
if (dynamic_cast<CommandDelegate&> (*delegate). if (dynamic_cast<CommandDelegate&>
updateEditorSetting (settingName, settingValue)) (*delegate).updateUserSetting (name, list))
emit dataChanged (mModel->index (0, i), mModel->index (mModel->rowCount()-1, i)); {
emit dataChanged (mModel->index (0, i),
mModel->index (mModel->rowCount()-1, i));
}
} }
void CSVWorld::Table::tableSizeUpdate() void CSVWorld::Table::tableSizeUpdate()
@ -598,4 +602,4 @@ std::vector<std::string> CSVWorld::Table::getColumnsWithDisplay(CSMWorld::Column
} }
} }
return titles; return titles;
} }

@ -78,7 +78,7 @@ namespace CSVWorld
CSMWorld::UniversalId getUniversalId (int row) const; 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; 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); 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) void CSVWorld::TableSubView::setStatusBar (bool show)
@ -134,4 +135,4 @@ bool CSVWorld::TableSubView::eventFilter (QObject* object, QEvent* event)
return handled; return handled;
} }
return false; return false;
} }

@ -43,7 +43,8 @@ namespace CSVWorld
virtual void setEditLock (bool locked); 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); virtual void setStatusBar (bool show);

@ -196,8 +196,8 @@ bool CSVWorld::CommandDelegate::isEditLocked() const
return mEditLock; return mEditLock;
} }
bool CSVWorld::CommandDelegate::updateEditorSetting (const QString &settingName, bool CSVWorld::CommandDelegate::updateUserSetting (const QString &name,
const QString &settingValue) const QStringList &list)
{ {
return false; return false;
} }
@ -263,4 +263,4 @@ void CSVWorld::DropLineEdit::dropEvent(QDropEvent *event)
const CSMWorld::TableMimeData* data(dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData())); const CSMWorld::TableMimeData* data(dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData()));
emit tableMimeDataDropped(data->getData(), data->getDocumentPtr()); emit tableMimeDataDropped(data->getData(), data->getDocumentPtr());
//WIP //WIP
} }

@ -136,7 +136,9 @@ namespace CSVWorld
bool isEditLocked() const; 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? ///< \return Does column require update?
virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const; virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const;

Loading…
Cancel
Save