Fixed / implemented missing features for RecordStatusDelegate

Implemented updating editor application from preferences menu, loading
settings when editor loads, adding Record Status Display prefernce.

Fixed multiple bugs, made changes to CSM(V)Settings classes to make
implementing new prefrences easier.

Rewrote CSMSettings::UserSettings to retain last-loaded settings.

Adjusted icon position in Record Status column

Capitalized status text

Added delegate to referenceables table
pull/16/head
graffy76 12 years ago
parent 1d93cf09bc
commit 700d55f1fb

@ -57,11 +57,11 @@ opencs_hdrs_noqt (view/doc
opencs_units (view/world
table tablesubview scriptsubview
table tablesubview scriptsubview util
)
opencs_units_noqt (view/world
dialoguesubview util subviews enumdelegate vartypedelegate scripthighlighter recordstatusdelegate
dialoguesubview subviews enumdelegate vartypedelegate scripthighlighter recordstatusdelegate
)
@ -78,6 +78,7 @@ opencs_units (view/settings
proxyblock
abstractwidget
usersettingsdialog
samplepage
editorpage
)

@ -18,8 +18,6 @@ namespace CSMSettings
explicit SettingContainer (QObject *parent = 0);
explicit SettingContainer (const QString &value, QObject *parent = 0);
virtual QString getName() const {return "";}
void insert (const QString &value);
void update (const QString &value, int index = 0);

@ -12,7 +12,6 @@ namespace CSMSettings
QStringPair *mValuePair;
QStringList *mValueList;
bool mIsMultiValue;
QString mName;
QString mDefaultValue;
public:
@ -20,8 +19,10 @@ namespace CSMSettings
const QString& defaultValue, QObject *parent = 0)
: SettingContainer(defaultValue, parent),
mIsMultiValue (isMultiValue), mValueList (0),
mName (name), mValuePair (0), mDefaultValue (defaultValue)
{}
mValuePair (0), mDefaultValue (defaultValue)
{
QObject::setObjectName(name);
}
bool updateItem (const QStringList *values);
bool updateItem (const QString &value);
@ -33,7 +34,6 @@ namespace CSMSettings
inline QStringPair *getValuePair() { return mValuePair; }
inline void setValuePair (QStringPair valuePair) { mValuePair = new QStringPair(valuePair); }
inline QString getName () const { return mName; }
inline bool isMultivalue () { return mIsMultiValue; }
void setDefaultValue (const QString &value);

@ -7,12 +7,15 @@
#include <QMap>
#include <QMessageBox>
#include <QTextCodec>
#include <QFile>
#include <components/files/configurationmanager.hpp>
#include "settingcontainer.hpp"
#include <boost/version.hpp>
#include <QDebug>
/**
* Workaround for problems with whitespaces in paths in older versions of Boost library
*/
@ -29,47 +32,67 @@ namespace boost
} /* namespace boost */
#endif /* (BOOST_VERSION <= 104600) */
CSMSettings::UserSettings::UserSettings()
{
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>");
}
CSMSettings::UserSettings::~UserSettings()
{
}
QFile *CSMSettings::UserSettings::openFile (const QString &filename)
QTextStream *CSMSettings::UserSettings::openFileStream (const QString &filePath, bool isReadOnly)
{
QFile *file = new QFile(filename);
QFile *file = new QFile(filePath);
QIODevice::OpenMode openFlags;
bool success = (file->open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) ;
if (isReadOnly)
openFlags = QIODevice::ReadOnly | QIODevice::Text;
else
openFlags = QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate;
if (!success)
if (!(file->open(openFlags)))
{
// File cannot be opened or created
QMessageBox msgBox;
msgBox.setWindowTitle(QObject::tr("Error writing OpenMW configuration file"));
msgBox.setWindowTitle(QObject::tr("OpenCS configuration file I/O error"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open or create %0 for writing</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file->fileName()));
QString fileMessage = QObject::tr("<br> File: %0").arg(file->fileName());
if (!isReadOnly)
msgBox.setText (mReadWriteMessage + fileMessage);
else
msgBox.setText (mReadOnlyMessage + fileMessage);
msgBox.exec();
delete file;
file = 0;
}
return file;
QTextStream *stream = 0;
if (file)
{
stream = new QTextStream(file);
stream->setCodec(QTextCodec::codecForName("UTF-8"));
}
return stream;
}
bool CSMSettings::UserSettings::writeFile(QFile *file, QMap<QString, CSMSettings::SettingList *> &settings)
bool CSMSettings::UserSettings::writeFile(QMap<QString, CSMSettings::SettingList *> &settings)
{
if (!file)
return false;
QTextStream stream(file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
QTextStream *stream = openFileStream(mPaths.back());
QList<QString> keyList = settings.keys();
@ -77,61 +100,121 @@ bool CSMSettings::UserSettings::writeFile(QFile *file, QMap<QString, CSMSettings
{
SettingList *sectionSettings = settings[key];
stream << "[" << key << "]" << '\n';
*stream << "[" << key << "]" << '\n';
foreach (SettingContainer *item, *sectionSettings)
stream << item->getName() << " = " << item->getValue() << '\n';
*stream << item->objectName() << " = " << item->getValue() << '\n';
}
file->close();
stream->device()->close();
return true;
}
void CSMSettings::UserSettings::getSettings(QTextStream &stream, SectionMap &sections)
const CSMSettings::SectionMap &CSMSettings::UserSettings::getSettings()
{
//looks for a square bracket, "'\\["
//that has one or more "not nothing" in it, "([^]]+)"
//and is closed with a square bracket, "\\]"
QRegExp sectionRe("^\\[([^]]+)\\]");
return mSectionSettings;
}
//Find any character(s) that is/are not equal sign(s), "[^=]+"
//followed by an optional whitespace, an equal sign, and another optional whirespace, "\\s*=\\s*"
//and one or more periods, "(.+)"
void CSMSettings::UserSettings::loadFromFile(const QString &filePath)
{
if (filePath.isEmpty())
return;
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
mSectionSettings.clear();
CSMSettings::SettingMap *settings = 0;
QString section = "none";
QTextStream *stream = openFileStream (filePath, true);
while (!stream.atEnd())
if (stream)
{
QString line = stream.readLine().simplified();
//looks for a square bracket, "'\\["
//that has one or more "not nothing" in it, "([^]]+)"
//and is closed with a square bracket, "\\]"
if (line.isEmpty() || line.startsWith("#"))
continue;
QRegExp sectionRe("^\\[([^]]+)\\]");
//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)
sections.insert(section, settings);
//save new section and create a new list
section = sectionRe.cap(1);
settings = new SettingMap;
continue;
}
//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*(.+)$");
if (keyRe.indexIn(line) != -1)
CSMSettings::SettingMap *settings = 0;
QString section = "none";
while (!stream->atEnd())
{
SettingContainer *sc = new SettingContainer (keyRe.cap(2).simplified());
(*settings)[keyRe.cap(1).simplified()] = sc;
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)
mSectionSettings.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;
}
}
mSectionSettings.insert(section, settings);
}
stream->device()->close();
return;
}
void CSMSettings::UserSettings::loadSettings (const QString &fileName)
{
if (mPaths.count() == 0)
{
mPaths.append(QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName);
mPaths.append(QString::fromStdString(mCfgMgr.getLocalPath().string()) + fileName);
mPaths.append(QString::fromStdString(mCfgMgr.getUserPath().string()) + fileName);
}
foreach (const QString &path, mPaths)
{
qDebug() << "Loading config file:" << qPrintable(path);
loadFromFile(path);
}
}
void CSMSettings::UserSettings::updateSettings (const QString &sectionName, const QString &settingName)
{
SettingMap *settings = mSectionSettings[sectionName];
if (!settings)
return;
SettingContainer *setting = 0;
if (settingName.isEmpty())
{
foreach (setting, *settings)
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
}
else
{
setting = (*settings)[settingName];
if (setting)
emit signalUpdateEditorSetting (setting->objectName(), setting->getValue());
}
sections.insert(section, settings);
}

@ -10,6 +10,10 @@
#include "support.hpp"
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#endif
namespace Files { typedef std::vector<boost::filesystem::path> PathContainer;
struct ConfigurationManager;}
@ -22,6 +26,14 @@ namespace CSMSettings {
Q_OBJECT
SectionMap mSectionSettings;
UserSettings *mUserSettingsInstance;
QStringList mPaths;
Files::ConfigurationManager mCfgMgr;
QString mReadOnlyMessage;
QString mReadWriteMessage;
public:
static UserSettings &instance()
@ -31,19 +43,22 @@ namespace CSMSettings {
return instance;
}
QFile *openFile (const QString &);
bool writeFile(QFile *file, QMap<QString, SettingList *> &sections);
void getSettings (QTextStream &stream, SectionMap &settings);
bool writeFile(QMap<QString, SettingList *> &sections);
const SectionMap &getSettings ();
void updateSettings (const QString &sectionName, const QString &settingName = "");
void loadSettings (const QString &fileName);
private:
UserSettings *mUserSettingsInstance;
UserSettings();
~UserSettings();
UserSettings (UserSettings const &); //not implemented
void operator= (UserSettings const &); //not implemented
QTextStream *openFileStream (const QString &filePath, bool isReadOnly = false);
void loadFromFile (const QString &filePath = "");
signals:
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);

@ -39,7 +39,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
mColumns.push_back (RefIdColumn ("ID", ColumnBase::Display_String,
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
baseColumns.mId = &mColumns.back();
mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_Integer,
mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_RecordState,
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
baseColumns.mModified = &mColumns.back();
mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_Integer,
@ -537,4 +537,4 @@ void CSMWorld::RefIdCollection::load (ESM::ESMReader& reader, bool base, Univers
int CSMWorld::RefIdCollection::getAppendIndex (UniversalId::Type type) const
{
return mData.getAppendIndex (type);
}
}

@ -1,5 +1,6 @@
#include "subview.hpp"
CSVDoc::SubView::SubView (const CSMWorld::UniversalId& id) : mUniversalId (id)
{
/// \todo add a button to the title bar that clones this sub view
@ -15,3 +16,7 @@ CSMWorld::UniversalId CSVDoc::SubView::getUniversalId() const
{
return mUniversalId;
}
void CSVDoc::SubView::updateEditorSetting (const QString &settingName, const QString &settingValue)
{
}

@ -35,6 +35,7 @@ namespace CSVDoc
CSMWorld::UniversalId getUniversalId() const;
virtual void setEditLock (bool locked) = 0;
virtual void updateEditorSetting (const QString &, const QString &);
signals:
@ -42,4 +43,4 @@ namespace CSVDoc
};
}
#endif
#endif

@ -258,11 +258,14 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id)
/// \todo add an user setting to reuse sub views (on a per document basis or on a per top level view basis)
SubView *view = mSubViewFactory.makeSubView (id, *mDocument);
view->setObjectName ("subview");
mSubViewWindow.addDockWidget (Qt::TopDockWidgetArea, view);
connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&)), this,
SLOT (addSubView (const CSMWorld::UniversalId&)));
CSMSettings::UserSettings::instance().updateSettings("Editor", "Record Status Display");
view->show();
}
@ -366,20 +369,13 @@ void CSVDoc::View::showUserSettings()
{
CSVSettings::UserSettingsDialog *settingsDialog = new CSVSettings::UserSettingsDialog(this);
connect (&(CSMSettings::UserSettings::instance()), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)),
this, SLOT (slotUpdateEditorSetting (const QString &, const QString &)) );
settingsDialog->show();
}
void CSVDoc::View::slotUpdateEditorSetting(const QString &settingName, const QString &settingValue)
void CSVDoc::View::updateEditorSetting (const QString &settingName, const QString &settingValue)
{
static QString lastValue = "";
if (lastValue != settingValue)
{
//evaluate settingName against tokens to determine which function to call to update Editor application.
lastValue = settingValue;
}
if (settingName == "Record Status Display")
foreach (QObject *view, mSubViewWindow.children())
if (view->objectName() == "subview")
dynamic_cast<CSVDoc::SubView *>(view)->updateEditorSetting (settingName, settingValue);
}

@ -68,6 +68,8 @@ namespace CSVDoc
void exitApplication();
void loadUserSettings();
public:
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);
@ -88,6 +90,8 @@ namespace CSVDoc
Operations *getOperations() const;
void updateEditorSetting (const QString &, const QString &);
signals:
void newDocumentRequest();
@ -102,8 +106,6 @@ namespace CSVDoc
void abortOperation (int type);
void slotUpdateEditorSetting (const QString &settingName, const QString &settingValue);
private slots:
void newView();

@ -13,13 +13,13 @@
#include "../world/enumdelegate.hpp"
#include "../world/vartypedelegate.hpp"
#include "../world/recordstatusdelegate.hpp"
#include "../settings/usersettingsdialog.hpp"
#include "view.hpp"
#include <QMessageBox>
#include <QPushButton>
#include <QtGui/QApplication>
#include <QDebug>
void CSVDoc::ViewManager::updateIndices()
{
@ -121,6 +121,11 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
mDelegateFactories->add (CSMWorld::ColumnBase::Display_RecordState,
new CSVWorld::RecordStatusDelegateFactory() );
connect (&CSMSettings::UserSettings::instance(), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)),
this, SLOT (slotUpdateEditorSetting (const QString &, const QString &)));
CSMSettings::UserSettings::instance().loadSettings("opencs.cfg");
}
CSVDoc::ViewManager::~ViewManager()
@ -347,3 +352,10 @@ void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view)
if (notifySaveOnClose (view))
QApplication::instance()->exit();
}
void CSVDoc::ViewManager::slotUpdateEditorSetting (const QString &settingName, const QString &settingValue)
{
if (settingName == "Record Status Display")
foreach (CSVDoc::View *view, mViews)
view->updateEditorSetting (settingName, settingValue);
}

@ -72,6 +72,8 @@ namespace CSVDoc
void progress (int current, int max, int type, int threads, CSMDoc::Document *document);
void onExitWarningHandler(int state, CSMDoc::Document* document);
void slotUpdateEditorSetting (const QString &, const QString &);
};
}

@ -13,18 +13,32 @@
CSVSettings::AbstractPage::AbstractPage(QWidget *parent):
QWidget(parent)
{
QGridLayout *pageLayout = new QGridLayout(this);
setLayout (pageLayout);
}
CSVSettings::AbstractPage::AbstractPage(const QString &pageName, QWidget *parent):
QWidget(parent)
{
QWidget::setObjectName (pageName);
QGridLayout *pageLayout = new QGridLayout(this);
setLayout (pageLayout);
}
CSVSettings::AbstractPage::~AbstractPage()
{
}
/*
void CSVSettings::AbstractPage::setupUi()
{
// Hacks to get the stylesheet look properly
#ifdef Q_OS_MAC
QPlastiqueStyle *style = new QPlastiqueStyle;
//profilesComboBox->setStyle(style);
#endif
}
*/
CSMSettings::SettingList *CSVSettings::AbstractPage::getSettings()
{
CSMSettings::SettingList *settings = new CSMSettings::SettingList();

@ -28,7 +28,7 @@ namespace CSVSettings {
~AbstractPage();
virtual void setupUi()=0;
virtual void setupUi() = 0;
virtual void initializeWidgets (const CSMSettings::SettingMap &settings) = 0;
@ -39,7 +39,7 @@ namespace CSVSettings {
protected:
template <typename S, typename T>
AbstractBlock *buildBlock (T &def)
AbstractBlock *buildBlock (T *def)
{
S *block = new S (this);
int ret = block->build (def);
@ -47,12 +47,12 @@ namespace CSVSettings {
if (ret < 0)
return 0;
QWidget::layout()->addWidget (block->getGroupBox());
QGroupBox *box = block->getGroupBox();
QWidget::layout()->addWidget (box);
return block;
}
};
}

@ -43,10 +43,7 @@ void CSVSettings::BlankPage::initPage()
void CSVSettings::BlankPage::setupUi()
{
QGroupBox *pageBox = new QGroupBox(this);
QLayout* pageLayout = new QVBoxLayout();
setLayout(pageLayout);
pageLayout->addWidget(pageBox);
layout()->addWidget(pageBox);
}
void CSVSettings::BlankPage::initializeWidgets (const CSMSettings::SettingMap &settings)

@ -23,7 +23,7 @@ int CSVSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefLis
for (; listIt != defList.end(); ++listIt)
{
if (!(*listIt)->isProxy)
retVal = buildGroupBlock (*(*listIt));
retVal = buildGroupBlock (*listIt);
else
{
mGroupList << proxyBlock;
@ -32,7 +32,7 @@ int CSVSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefLis
}
if (proxyIt != defaultIt)
retVal = buildProxyBlock (*(*proxyIt), proxyBlock);
retVal = buildProxyBlock (*proxyIt, proxyBlock);
return retVal;
}
@ -45,7 +45,7 @@ CSVSettings::GroupBox *CSVSettings::CustomBlock::buildGroupBox (Orientation orie
return box;
}
int CSVSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def)
int CSVSettings::CustomBlock::buildGroupBlock(GroupBlockDef *def)
{
GroupBlock *block = new GroupBlock (getParent());
@ -57,9 +57,9 @@ int CSVSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def)
return block->build(def);
}
int CSVSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *block)
int CSVSettings::CustomBlock::buildProxyBlock(GroupBlockDef *def, ProxyBlock *block)
{
if (def.properties.size() != 1)
if (def->properties.size() != 1)
return -1;
int retVal = block->build(def);
@ -67,7 +67,7 @@ int CSVSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *bl
if (retVal != 0)
return retVal;
foreach (QStringList *list, *(def.properties.at(0)->proxyList))
foreach (QStringList *list, *(def->properties.at(0)->proxyList))
{
QString proxiedBlockName = list->at(0);

@ -29,8 +29,8 @@ namespace CSVSettings
private:
int buildGroupBlock(GroupBlockDef &def);
int buildProxyBlock(GroupBlockDef &def, ProxyBlock *block);
int buildGroupBlock(GroupBlockDef *def);
int buildProxyBlock(GroupBlockDef *def, ProxyBlock *block);
};
}
#endif // CUSTOMBLOCK_HPP

@ -1,156 +1,52 @@
#include "editorpage.hpp"
#include <QList>
#include <QListView>
#include <QGroupBox>
#include <QRadioButton>
#include <QDockWidget>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QStyle>
#ifdef Q_OS_MAC
#include <QPlastiqueStyle>
#endif
#include "../../model/settings/usersettings.hpp"
#include "groupblock.hpp"
#include "toggleblock.hpp"
#include "../../model/settings/usersettings.hpp"
CSVSettings::EditorPage::EditorPage(QWidget *parent):
AbstractPage("Editor", parent)
CSVSettings::EditorPage::EditorPage(QWidget* parent) :
AbstractPage(parent)
{
// Hacks to get the stylesheet look properly
#ifdef Q_OS_MAC
QPlastiqueStyle *style = new QPlastiqueStyle;
//profilesComboBox->setStyle(style);
#endif
setupUi();
}
void CSVSettings::EditorPage::setupUi()
CSVSettings::EditorPage::EditorPage (const QString &pageName, QWidget* parent)
: AbstractPage (pageName, parent)
{
GroupBlockDef undoStack (QString("Undo Stack Size"));
GroupBlockDef topLevelWindowCount (QString("Maximum Top-Level Window Count"));
GroupBlockDef reuseSubwindow (QString("Reuse Subwindows"));
GroupBlockDef customWindowSize (QString ("Custom Window Size"));
GroupBlockDef definedWindowSize (QString ("Pre-Defined Window Size"));
GroupBlockDef windowSizeToggle (QString ("Window Size"));
CustomBlockDef windowSize (QString ("Window Size"));
////////////////////////////
//undo stack size property
///////////////////////////
SettingsItemDef *undoStackItem = new SettingsItemDef (undoStack.title, "32");
undoStack.properties << undoStackItem;
undoStackItem->minMax.left = "0";
undoStackItem->minMax.right = "64";
WidgetDef stackWidget (Widget_SpinBox);
stackWidget.minMax = &(undoStackItem->minMax);
stackWidget.widgetWidth = 50;
undoStackItem->widget = stackWidget;
//////////////////////////////////////
//number of top level windows property
/////////////////////////////////////
SettingsItemDef *topLevelItem = new SettingsItemDef (topLevelWindowCount.title, "100");
topLevelWindowCount.properties << topLevelItem;
topLevelItem->minMax.left = "1";
topLevelItem->minMax.right = "256";
WidgetDef topLvlWinWidget (Widget_SpinBox);
topLvlWinWidget.minMax = &(topLevelItem->minMax);
topLvlWinWidget.widgetWidth = 50;
topLevelItem->widget = topLvlWinWidget;
///////////////////////////
//reuse subwindows property
////////////////////////////
SettingsItemDef *reuseSubItem = new SettingsItemDef (reuseSubwindow.title, "Reuse Subwindows");
*(reuseSubItem->valueList) << "None" << "Top-Level" << "Document-Level";
WidgetDef reuseSubWidget (Widget_RadioButton);
reuseSubWidget.valueList = (reuseSubItem->valueList);
reuseSubWidget.widgetAlignment = Align_Left;
reuseSubwindow.properties << reuseSubItem;
reuseSubItem->widget = reuseSubWidget;
///////////////////////////////
//custom window size properties
///////////////////////////////
//custom width
SettingsItemDef *widthItem = new SettingsItemDef ("Window Width", "640");
widthItem->widget = WidgetDef (Widget_LineEdit);
widthItem->widget.widgetWidth = 45;
//custom height
SettingsItemDef *heightItem = new SettingsItemDef ("Window Height", "480");
heightItem->widget = WidgetDef (Widget_LineEdit);
heightItem->widget.widgetWidth = 45;
heightItem->widget.caption = "x";
customWindowSize.properties << widthItem << heightItem;
customWindowSize.widgetOrientation = Orient_Horizontal;
customWindowSize.isVisible = false;
//pre-defined
SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480");
WidgetDef widthByHeightWidget = WidgetDef (Widget_ComboBox);
widthByHeightWidget.widgetWidth = 90;
*(widthByHeightItem->valueList) << "640x480" << "800x600" << "1024x768";
QStringList *widthProxy = new QStringList;
QStringList *heightProxy = new QStringList;
(*widthProxy) << "Window Width" << "640" << "800" << "1024";
(*heightProxy) << "Window Height" << "480" << "600" << "768";
*(widthByHeightItem->proxyList) << widthProxy << heightProxy;
widthByHeightItem->widget = widthByHeightWidget;
setupUi();
}
definedWindowSize.properties << widthByHeightItem;
definedWindowSize.isProxy = true;
definedWindowSize.isVisible = false;
CSVSettings::GroupBlockDef *CSVSettings::EditorPage::setupRecordStatusDisplay()
{
GroupBlockDef *statusBlock = new GroupBlockDef(QString("Record Status Display"));
// window size toggle
windowSizeToggle.captions << "Pre-Defined" << "Custom";
windowSizeToggle.widgetOrientation = Orient_Vertical;
windowSizeToggle.isVisible = false;
SettingsItemDef *statusItem = new SettingsItemDef (statusBlock->title, "Icon and Text");
*(statusItem->valueList) << QString("Icon and Text") << QString("Icon Only") << QString("Text Only");
//define a widget for each group in the toggle
for (int i = 0; i < 2; i++)
windowSizeToggle.widgets << new WidgetDef (Widget_RadioButton);
WidgetDef statusWidget (Widget_RadioButton);
statusWidget.valueList = statusItem->valueList;
windowSizeToggle.widgets.at(0)->isDefault = false;
statusItem->widget = statusWidget;
windowSize.blockDefList << &windowSizeToggle << &definedWindowSize << &customWindowSize;
windowSize.defaultValue = "Custom";
statusBlock->properties << statusItem;
QGridLayout *pageLayout = new QGridLayout(this);
return statusBlock;
}
setLayout (pageLayout);
void CSVSettings::EditorPage::setupUi()
{
mAbstractBlocks << buildBlock<GroupBlock> (topLevelWindowCount)
<< buildBlock<GroupBlock> (reuseSubwindow)
<< buildBlock<ToggleBlock> (windowSize)
<< buildBlock<GroupBlock> (undoStack);
mAbstractBlocks << buildBlock<GroupBlock>(setupRecordStatusDisplay());
foreach (AbstractBlock *block, mAbstractBlocks)
{
connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)),
this, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)) );
}
connect ( this,
SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)),
&(CSMSettings::UserSettings::instance()),
SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
}
void CSVSettings::EditorPage::initializeWidgets (const CSMSettings::SettingMap &settings)

@ -1,28 +1,30 @@
#ifndef EDITORPAGE_H
#define EDITORPAGE_H
#ifndef EDITORPAGE_HPP
#define EDITORPAGE_HPP
#include "support.hpp"
#include "abstractpage.hpp"
class QGroupBox;
namespace CSVSettings {
class UserSettings;
class AbstractBlock;
namespace CSVSettings
{
class EditorPage : public AbstractPage
{
Q_OBJECT
public:
explicit EditorPage(QWidget *parent = 0);
explicit EditorPage (const QString &pageName, QWidget* parent = 0);
EditorPage(QWidget *parent = 0);
void setupUi();
void initializeWidgets (const CSMSettings::SettingMap &settings);
void setupUi();
private:
GroupBlockDef *setupRecordStatusDisplay();
signals:
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
public slots:
};
}
#endif //EDITORPAGE_H
#endif // EDITORPAGE_HPP

@ -9,22 +9,22 @@ CSVSettings::GroupBlock::GroupBlock (bool isVisible, QWidget *parent)
: AbstractBlock (isVisible, parent)
{}
int CSVSettings::GroupBlock::build (GroupBlockDef &def)
int CSVSettings::GroupBlock::build (GroupBlockDef *def)
{
if (def.properties.size() == 0)
if (def->properties.size() == 0)
return -1;
int retVal = 0;
setVisible (def.isVisible);
setVisible (def->isVisible);
mBox->setLayout(createLayout (def.widgetOrientation, true));
mBox->setLayout(createLayout (def->widgetOrientation, true));
setObjectName (def.title);
mBox->setTitle (def.title);
setObjectName (def->title);
mBox->setTitle (def->title);
foreach (SettingsItemDef *itemDef, def.properties)
foreach (SettingsItemDef *itemDef, def->properties)
{
ItemBlock *block = new ItemBlock (mBox);

@ -16,7 +16,7 @@ namespace CSVSettings
GroupBlock (QWidget* parent = 0);
GroupBlock (bool isVisible, QWidget *parent = 0);
int build (GroupBlockDef &def);
int build (GroupBlockDef *def);
bool updateSettings (const CSMSettings::SettingMap &settings);

@ -5,10 +5,10 @@ CSVSettings::ProxyBlock::ProxyBlock (QWidget *parent)
: GroupBlock (parent)
{
}
int CSVSettings::ProxyBlock::build (GroupBlockDef &proxyDef)
int CSVSettings::ProxyBlock::build (GroupBlockDef *proxyDef)
{
//get the list of pre-defined values for the proxy
mValueList = proxyDef.properties.at(0)->valueList;
mValueList = proxyDef->properties.at(0)->valueList;
bool success = GroupBlock::build(proxyDef);

@ -21,7 +21,7 @@ namespace CSVSettings
explicit ProxyBlock (ItemBlock *proxyItemBlock, QWidget *parent = 0);
void addSetting (ItemBlock* settingBlock, QStringList *proxyList);
int build (GroupBlockDef &def);
int build (GroupBlockDef *def);
CSMSettings::SettingList *getSettings() { return 0; }
bool updateSettings (const CSMSettings::SettingMap &settings);

@ -0,0 +1,159 @@
#include "samplepage.hpp"
#include <QList>
#include <QListView>
#include <QGroupBox>
#include <QRadioButton>
#include <QDockWidget>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QStyle>
#ifdef Q_OS_MAC
#include <QPlastiqueStyle>
#endif
#include "../../model/settings/usersettings.hpp"
#include "groupblock.hpp"
#include "toggleblock.hpp"
CSVSettings::SamplePage::SamplePage(QWidget *parent):
AbstractPage("Editor", parent)
{
// Hacks to get the stylesheet look properly
#ifdef Q_OS_MAC
QPlastiqueStyle *style = new QPlastiqueStyle;
//profilesComboBox->setStyle(style);
#endif
setupUi();
}
void CSVSettings::SamplePage::setupUi()
{
GroupBlockDef *undoStack = new GroupBlockDef(QString("Undo Stack Size"));
GroupBlockDef *topLevelWindowCount = new GroupBlockDef(QString("Maximum Top-Level Window Count"));
GroupBlockDef *reuseSubwindow = new GroupBlockDef(QString("Reuse Subwindows"));
GroupBlockDef *customWindowSize = new GroupBlockDef(QString ("Custom Window Size"));
GroupBlockDef *definedWindowSize = new GroupBlockDef(QString ("Pre-Defined Window Size"));
GroupBlockDef *windowSizeToggle = new GroupBlockDef(QString ("Window Size"));
CustomBlockDef *windowSize = new CustomBlockDef(QString ("Window Size"));
////////////////////////////
//undo stack size property
///////////////////////////
SettingsItemDef *undoStackItem = new SettingsItemDef (undoStack->title, "32");
undoStack->properties << undoStackItem;
undoStackItem->minMax.left = "0";
undoStackItem->minMax.right = "64";
WidgetDef stackWidget (Widget_SpinBox);
stackWidget.minMax = &(undoStackItem->minMax);
stackWidget.widgetWidth = 50;
undoStackItem->widget = stackWidget;
//////////////////////////////////////
//number of top level windows property
/////////////////////////////////////
SettingsItemDef *topLevelItem = new SettingsItemDef (topLevelWindowCount->title, "100");
topLevelWindowCount->properties << topLevelItem;
topLevelItem->minMax.left = "1";
topLevelItem->minMax.right = "256";
WidgetDef topLvlWinWidget (Widget_SpinBox);
topLvlWinWidget.minMax = &(topLevelItem->minMax);
topLvlWinWidget.widgetWidth = 50;
topLevelItem->widget = topLvlWinWidget;
///////////////////////////
//reuse subwindows property
////////////////////////////
SettingsItemDef *reuseSubItem = new SettingsItemDef (reuseSubwindow->title, "Reuse Subwindows");
*(reuseSubItem->valueList) << "None" << "Top-Level" << "Document-Level";
WidgetDef reuseSubWidget (Widget_RadioButton);
reuseSubWidget.valueList = (reuseSubItem->valueList);
reuseSubWidget.widgetAlignment = Align_Left;
reuseSubwindow->properties << reuseSubItem;
reuseSubItem->widget = reuseSubWidget;
///////////////////////////////
//custom window size properties
///////////////////////////////
//custom width
SettingsItemDef *widthItem = new SettingsItemDef ("Window Width", "640");
widthItem->widget = WidgetDef (Widget_LineEdit);
widthItem->widget.widgetWidth = 45;
//custom height
SettingsItemDef *heightItem = new SettingsItemDef ("Window Height", "480");
heightItem->widget = WidgetDef (Widget_LineEdit);
heightItem->widget.widgetWidth = 45;
heightItem->widget.caption = "x";
customWindowSize->properties << widthItem << heightItem;
customWindowSize->widgetOrientation = Orient_Horizontal;
customWindowSize->isVisible = false;
//pre-defined
SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480");
WidgetDef widthByHeightWidget = WidgetDef (Widget_ComboBox);
widthByHeightWidget.widgetWidth = 90;
*(widthByHeightItem->valueList) << "640x480" << "800x600" << "1024x768";
QStringList *widthProxy = new QStringList;
QStringList *heightProxy = new QStringList;
(*widthProxy) << "Window Width" << "640" << "800" << "1024";
(*heightProxy) << "Window Height" << "480" << "600" << "768";
*(widthByHeightItem->proxyList) << widthProxy << heightProxy;
widthByHeightItem->widget = widthByHeightWidget;
definedWindowSize->properties << widthByHeightItem;
definedWindowSize->isProxy = true;
definedWindowSize->isVisible = false;
// window size toggle
windowSizeToggle->captions << "Pre-Defined" << "Custom";
windowSizeToggle->widgetOrientation = Orient_Vertical;
windowSizeToggle->isVisible = false;
//define a widget for each group in the toggle
for (int i = 0; i < 2; i++)
windowSizeToggle->widgets << new WidgetDef (Widget_RadioButton);
windowSizeToggle->widgets.at(0)->isDefault = false;
windowSize->blockDefList << windowSizeToggle << definedWindowSize << customWindowSize;
windowSize->defaultValue = "Custom";
mAbstractBlocks << buildBlock<GroupBlock> (topLevelWindowCount)
<< buildBlock<GroupBlock> (reuseSubwindow)
<< buildBlock<ToggleBlock> (windowSize)
<< buildBlock<GroupBlock> (undoStack);
foreach (AbstractBlock *block, mAbstractBlocks)
{
connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)),
this, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)) );
}
}
void CSVSettings::SamplePage::initializeWidgets (const CSMSettings::SettingMap &settings)
{
//iterate each item in each blocks in this section
//validate the corresponding setting against the defined valuelist if any.
for (AbstractBlockList::Iterator it_block = mAbstractBlocks.begin();
it_block != mAbstractBlocks.end(); ++it_block)
(*it_block)->updateSettings (settings);
}

@ -0,0 +1,28 @@
#ifndef SAMPLEPAGE_H
#define SAMPLEPAGE_H
#include "abstractpage.hpp"
class QGroupBox;
namespace CSVSettings {
class UserSettings;
class AbstractBlock;
class SamplePage : public AbstractPage
{
Q_OBJECT
public:
explicit SamplePage(QWidget *parent = 0);
void setupUi();
void initializeWidgets (const CSMSettings::SettingMap &settings);
signals:
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
};
}
#endif //SAMPLEPAGE_H

@ -7,24 +7,24 @@ CSVSettings::ToggleBlock::ToggleBlock(QWidget *parent) :
CustomBlock(parent)
{}
int CSVSettings::ToggleBlock::build(CustomBlockDef &def)
int CSVSettings::ToggleBlock::build(CustomBlockDef *def)
{
if (def.blockDefList.size()==0)
if (def->blockDefList.size()==0)
return -1;
QList<GroupBlockDef *>::Iterator it = def.blockDefList.begin();
QList<GroupBlockDef *>::Iterator it = def->blockDefList.begin();
//first def in the list is the def for the toggle block
GroupBlockDef *toggleDef = *it++;
if (toggleDef->captions.size() != def.blockDefList.size()-1 )
if (toggleDef->captions.size() != def->blockDefList.size()-1 )
return -2;
if (toggleDef->widgets.size() == 0)
return -3;
//create the toogle block UI structure
QLayout *blockLayout = createLayout (def.blockOrientation, true);
QLayout *blockLayout = createLayout (def->blockOrientation, true);
GroupBox *propertyBox = buildGroupBox (toggleDef->widgetOrientation);
mBox->setLayout(blockLayout);
@ -34,13 +34,13 @@ int CSVSettings::ToggleBlock::build(CustomBlockDef &def)
//this manages proxy block construction.
//Any settings managed by the proxy setting
//must be included in the blocks defined in the list.
CustomBlock::build (def.blockDefList, &it);
CustomBlock::build (def->blockDefList, &it);
for (GroupBlockList::iterator it = mGroupList.begin(); it != mGroupList.end(); ++it)
propertyBox->layout()->addWidget ((*it)->getGroupBox());
//build togle widgets, linking them to the settings
GroupBox *toggleBox = buildToggleWidgets (*toggleDef, def.defaultValue);
GroupBox *toggleBox = buildToggleWidgets (toggleDef, def->defaultValue);
blockLayout->addWidget(toggleBox);
blockLayout->addWidget(propertyBox);
@ -49,16 +49,16 @@ int CSVSettings::ToggleBlock::build(CustomBlockDef &def)
return 0;
}
CSVSettings::GroupBox *CSVSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle)
CSVSettings::GroupBox *CSVSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef *def, QString &defaultToggle)
{
GroupBox *box = new GroupBox (false, getParent());
QLayout *layout = createLayout (def.widgetOrientation, true, static_cast<QWidget *>(box));
QLayout *layout = createLayout (def->widgetOrientation, true, static_cast<QWidget *>(box));
for (int i = 0; i < def.widgets.size(); ++i)
for (int i = 0; i < def->widgets.size(); ++i)
{
QString caption = def.captions.at(i);
WidgetDef *wDef = def.widgets.at(i);
QString caption = def->captions.at(i);
WidgetDef *wDef = def->widgets.at(i);
wDef->caption = caption;
wDef->widgetAlignment = Align_Left;

@ -18,10 +18,10 @@ namespace CSVSettings
public:
explicit ToggleBlock(QWidget *parent = 0);
int build (CustomBlockDef &def);
int build (CustomBlockDef *def);
private:
GroupBox *buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle);
GroupBox *buildToggleWidgets (GroupBlockDef *def, QString &defaultToggle);
};
}
#endif // TOGGLEBLOCK_HPP

@ -9,26 +9,27 @@
#include <QFile>
#include <QPushButton>
#include <QDockWidget>
#include <QGridLayout>
#include "blankpage.hpp"
#include "editorpage.hpp"
#include "../../model/settings/support.hpp"
#include "samplepage.hpp"
#include "../../model/settings/support.hpp"
#include <boost/filesystem/path.hpp>
#include "settingwidget.hpp"
#include <QDebug>
CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) :
QMainWindow (parent), mStackedWidget (0)
{
setWindowTitle(QString::fromUtf8 ("User Settings"));
buildPages();
setWidgetStates (loadSettings());
setWidgetStates ();
positionWindow ();
connect (mListWidget,
SIGNAL (currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
this,
SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*)));
SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*)));
}
CSVSettings::UserSettingsDialog::~UserSettingsDialog()
@ -40,13 +41,16 @@ void CSVSettings::UserSettingsDialog::closeEvent (QCloseEvent *event)
writeSettings();
}
void CSVSettings::UserSettingsDialog::setWidgetStates (CSMSettings::SectionMap settingsMap)
void CSVSettings::UserSettingsDialog::setWidgetStates ()
{
CSMSettings::UserSettings::instance().loadSettings("opencs.cfg");
const CSMSettings::SectionMap &sectionSettings = CSMSettings::UserSettings::instance().getSettings();
//iterate the tabWidget's pages (sections)
for (int i = 0; i < mStackedWidget->count(); i++)
{
//get the settings defined for the entire section
CSMSettings::SettingMap *settings = settingsMap [mStackedWidget->widget(i)->objectName()];
CSMSettings::SettingMap *settings = sectionSettings [mStackedWidget->widget(i)->objectName()];
//if found, initialize the page's widgets
if (settings)
@ -65,18 +69,25 @@ void CSVSettings::UserSettingsDialog::buildPages()
mListWidget = new QListWidget (centralWidget);
mStackedWidget = new QStackedWidget (centralWidget);
QLayout* dialogLayout = new QHBoxLayout();
QGridLayout* dialogLayout = new QGridLayout();
dialogLayout->addWidget (mListWidget);
dialogLayout->addWidget (mStackedWidget);
mListWidget->setMinimumWidth(0);
mListWidget->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Expanding);
mStackedWidget->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
dialogLayout->addWidget (mListWidget,0,0);
dialogLayout->addWidget (mStackedWidget,0,1, Qt::AlignTop);
centralWidget->setLayout (dialogLayout);
setCentralWidget (centralWidget);
setDockOptions (QMainWindow::AllowNestedDocks);
//uncomment to test with sample editor page.
//createSamplePage();
createPage<BlankPage>("Page1");
// TODO: Reimplement sample page using createPage function
//createPage<SamplePage>("Sample");
createPage<EditorPage>("Editor");
createPage<BlankPage>("Page2");
createPage<BlankPage>("Page3");
}
@ -85,14 +96,16 @@ void CSVSettings::UserSettingsDialog::createSamplePage()
{
//add pages to stackedwidget and items to listwidget
CSVSettings::AbstractPage *page
= new CSVSettings::EditorPage(this);
= new CSVSettings::SamplePage(this);
mStackedWidget->addWidget (page);
new QListWidgetItem (page->objectName(), mListWidget);
connect ( page,
SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)),
&(CSMSettings::UserSettings::instance()),
SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
connect ( page, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)),
&(CSMSettings::UserSettings::instance()), SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
new QListWidgetItem (page->objectName(), mListWidget);
}
void CSVSettings::UserSettingsDialog::positionWindow ()
@ -103,47 +116,6 @@ void CSVSettings::UserSettingsDialog::positionWindow ()
}
CSMSettings::SectionMap CSVSettings::UserSettingsDialog::loadSettings ()
{
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
mPaths.append(QString("opencs.cfg"));
mPaths.append(userPath + QString("opencs.cfg"));
CSMSettings::SectionMap settingsMap;
foreach (const QString &path, mPaths)
{
qDebug() << "Loading config file:" << qPrintable(path);
QFile file(path);
if (file.exists())
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error opening OpenCS configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return settingsMap;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
CSMSettings::UserSettings::instance().getSettings(stream, settingsMap);
}
file.close();
}
return settingsMap;
}
void CSVSettings::UserSettingsDialog::writeSettings()
{
QMap<QString, CSMSettings::SettingList *> settings;
@ -154,7 +126,7 @@ void CSVSettings::UserSettingsDialog::writeSettings()
settings [page->objectName()] = page->getSettings();
}
CSMSettings::UserSettings::instance().writeFile(CSMSettings::UserSettings::instance().openFile(mPaths.back()), settings);
CSMSettings::UserSettings::instance().writeFile(settings);
}

@ -4,14 +4,13 @@
#include <QMainWindow>
#include <QStackedWidget>
#include <QListWidgetItem>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#endif
#include <QApplication>
#include "../../model/settings/usersettings.hpp"
#include "../../model/settings/support.hpp"
#include "editorpage.hpp"
class QHBoxLayout;
class AbstractWidget;
class QStackedWidget;
@ -28,7 +27,6 @@ namespace CSVSettings {
QStringList mPaths;
QListWidget *mListWidget;
QStackedWidget *mStackedWidget;
Files::ConfigurationManager mCfgMgr;
public:
UserSettingsDialog(QMainWindow *parent = 0);
@ -38,10 +36,9 @@ namespace CSVSettings {
void closeEvent (QCloseEvent *event);
AbstractPage *getAbstractPage (int index);
void setWidgetStates (CSMSettings::SectionMap settingsMap);
void setWidgetStates ();
void buildPages();
void positionWindow ();
CSMSettings::SectionMap loadSettings();
void writeSettings();
void createSamplePage();
@ -61,6 +58,12 @@ namespace CSVSettings {
if (mStackedWidget->sizeHint().height() < 480)
mStackedWidget->sizeHint().setHeight(480);
QFontMetrics fm (QApplication::font());
int textWidth = fm.width(page->objectName());
if ((textWidth + 50) > mListWidget->minimumWidth())
mListWidget->setMinimumWidth(textWidth + 50);
resize (mStackedWidget->sizeHint());
}

@ -2,6 +2,7 @@
#include <QPainter>
#include <QApplication>
#include <QUndoStack>
#include "../../model/settings/usersettings.hpp"
CSVWorld::RecordStatusDelegate::RecordStatusDelegate(QUndoStack &undoStack, QObject *parent)
: CommandDelegate (undoStack, parent)
@ -36,23 +37,23 @@ void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptio
switch (index.data().toInt())
{
case 0: // State_BaseOnly
text = "base";
text = "Base";
break;
case 1: // State_Modified
text = "modified";
text = "Modified";
icon = mModifiedIcon;
break;
case 2: // State_Modified_Only
text = "added";
text = "Added";
icon = mAddedIcon;
break;
case 3: // State_Deleted
case 4: // State_Erased
text = "deleted";
text = "Deleted";
icon = mDeletedIcon;
break;
@ -70,14 +71,14 @@ void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptio
if (mStatusDisplay == 0 && (icon) )
{
iconRect.setRight (iconRect.left() + mIconSize*2);
textRect.setLeft (iconRect.right() + mTextLeftOffset *2);
iconRect.setRight (iconRect.left()+ mIconSize*2);
textRect.setLeft (iconRect.right() + mTextLeftOffset *1.25);
}
else
textRect.setLeft (textRect.left() + mTextLeftOffset );
if ( (mStatusDisplay == 0 || mStatusDisplay == 1) && (icon) )
painter->drawPixmap(iconRect.center(),icon->pixmap(mIconSize, mIconSize));
painter->drawPixmap(iconRect.center().x()-10,iconRect.center().y()+2, icon->pixmap(mIconSize, mIconSize));
// icon + text or text only, or force text if no icon exists for status
if (mStatusDisplay == 0 || mStatusDisplay == 2 || !(icon) )
@ -99,3 +100,21 @@ CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (
{
return new RecordStatusDelegate (undoStack, parent);
}
void CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue)
{
if (settingName == "Record Status Display")
{
if (settingValue == "Icon and Text")
mStatusDisplay = 0;
else if (settingValue == "Icon Only")
mStatusDisplay = 1;
else if (settingValue == "Text Only")
mStatusDisplay = 2;
else
mStatusDisplay = 0;
}
}

@ -35,12 +35,12 @@ namespace CSVWorld
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const;
void updateEditorSetting (const QString &settingName, const QString &settingValue);
};
class RecordStatusDelegateFactory : public CommandDelegateFactory
{
//std::vector<std::pair<int, QString> > mValues;
public:
virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const;

@ -12,6 +12,7 @@
#include "../../model/world/idtableproxymodel.hpp"
#include "../../model/world/idtable.hpp"
#include "../../model/world/record.hpp"
#include "recordstatusdelegate.hpp"
#include "util.hpp"
@ -80,7 +81,7 @@ std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack,
bool createAndDelete)
: mUndoStack (undoStack), mCreateAction (0), mEditLock (false)
: mUndoStack (undoStack), mCreateAction (0), mEditLock (false), mRecordStatusDisplay (0)
{
mModel = &dynamic_cast<CSMWorld::IdTable&> (*data.getTableModel (id));
@ -161,6 +162,7 @@ void CSVWorld::Table::createRecord()
mUndoStack.push (new CSMWorld::CreateCommand (*mProxyModel, stream.str()));
}
}
void CSVWorld::Table::revertRecord()
@ -201,4 +203,13 @@ void CSVWorld::Table::deleteRecord()
mUndoStack.endMacro();
}
}
}
}
void CSVWorld::Table::updateEditorSetting (const QString &settingName, const QString &settingValue)
{
if (settingName == "Record Status Display")
{
dynamic_cast<CSVWorld::RecordStatusDelegate *>(this->itemDelegateForColumn(1))->updateEditorSetting (settingName, settingValue);
emit dataChanged(mModel->index(0,1), mModel->index(mModel->rowCount()-1, 1));
}
}

@ -34,6 +34,7 @@ namespace CSVWorld
CSMWorld::IdTableProxyModel *mProxyModel;
CSMWorld::IdTable *mModel;
bool mEditLock;
int mRecordStatusDisplay;
private:
@ -52,6 +53,8 @@ namespace CSVWorld
CSMWorld::UniversalId getUniversalId (int row) const;
void updateEditorSetting (const QString &settingName, const QString &settingValue);
private slots:
void createRecord();

@ -22,4 +22,11 @@ void CSVWorld::TableSubView::setEditLock (bool locked)
void CSVWorld::TableSubView::rowActivated (const QModelIndex& index)
{
focusId (mTable->getUniversalId (index.row()));
}
}
void CSVWorld::TableSubView::updateEditorSetting(const QString &settingName, const QString &settingValue)
{
if (settingName == "Record Status Display")
mTable->updateEditorSetting(settingName, settingValue);
}

@ -23,8 +23,8 @@ namespace CSVWorld
public:
TableSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete);
virtual void setEditLock (bool locked);
void updateEditorSetting (const QString &, const QString &);
private slots:
@ -32,4 +32,4 @@ namespace CSVWorld
};
}
#endif
#endif

@ -82,6 +82,8 @@ namespace CSVWorld
///< \brief Use commands instead of manipulating the model directly
class CommandDelegate : public QStyledItemDelegate
{
Q_OBJECT
QUndoStack& mUndoStack;
bool mEditLock;
@ -105,6 +107,10 @@ namespace CSVWorld
void setEditLock (bool locked);
bool isEditLocked() const;
private slots:
virtual void slotUpdateEditorSetting (const QString &settingName, const QString &settingValue) {}
};
}

Loading…
Cancel
Save