second batch of changing over user settings usage to the new system

openmw-38
Marc Zinnschlag 9 years ago
parent cf9fa0e0e9
commit a3a2c2f476

@ -153,6 +153,7 @@ void CSMPrefs::State::declare()
declareColour ("colour-special", "Highlight Colour: Special Characters", QColor ("darkorange"));
declareColour ("colour-comment", "Highlight Colour: Comments", QColor ("green"));
declareColour ("colour-id", "Highlight Colour: IDs", QColor ("blue"));
declareCategory ("General Input");
declareBool ("cycle", "Cyclic next/previous", false).
setTooltip ("When using next/previous functions at the last/first item of a "

@ -27,11 +27,6 @@ void CSVTools::ReportSubView::setEditLock (bool locked)
// ignored. We don't change document state anyway.
}
void CSVTools::ReportSubView::updateUserSetting (const QString &name, const QStringList &list)
{
mTable->updateUserSetting (name, list);
}
void CSVTools::ReportSubView::refreshRequest()
{
if (!(mDocument.getState() & mRefreshState))
@ -39,7 +34,7 @@ void CSVTools::ReportSubView::refreshRequest()
if (mRefreshState==CSMDoc::State_Verifying)
{
mTable->clear();
mDocument.verify (getUniversalId());
mDocument.verify (getUniversalId());
}
}
}

@ -29,8 +29,6 @@ namespace CSVTools
virtual void setEditLock (bool locked);
virtual void updateUserSetting (const QString &, const QStringList &);
private slots:
void refreshRequest();

@ -14,6 +14,8 @@
#include "../../model/tools/reportmodel.hpp"
#include "../../model/prefs/state.hpp"
#include "../../view/world/idtypedelegate.hpp"
namespace CSVTools
@ -189,6 +191,10 @@ CSVTools::ReportTable::ReportTable (CSMDoc::Document& document,
mDoubleClickActions.insert (std::make_pair (Qt::NoModifier, Action_Edit));
mDoubleClickActions.insert (std::make_pair (Qt::ShiftModifier, Action_Remove));
mDoubleClickActions.insert (std::make_pair (Qt::ControlModifier, Action_EditAndRemove));
connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
this, SLOT (settingChanged (const CSMPrefs::Setting *)));
CSMPrefs::get()["Reports"].update();
}
std::vector<CSMWorld::UniversalId> CSVTools::ReportTable::getDraggedRecords() const
@ -206,40 +212,6 @@ std::vector<CSMWorld::UniversalId> CSVTools::ReportTable::getDraggedRecords() co
return ids;
}
void CSVTools::ReportTable::updateUserSetting (const QString& name, const QStringList& list)
{
mIdTypeDelegate->updateUserSetting (name, list);
QString base ("report-input/double");
if (name.startsWith (base))
{
QString modifierString = name.mid (base.size());
Qt::KeyboardModifiers modifiers = 0;
if (modifierString=="-s")
modifiers = Qt::ShiftModifier;
else if (modifierString=="-c")
modifiers = Qt::ControlModifier;
else if (modifierString=="-sc")
modifiers = Qt::ShiftModifier | Qt::ControlModifier;
DoubleClickAction action = Action_None;
QString value = list.at (0);
if (value=="Edit")
action = Action_Edit;
else if (value=="Remove")
action = Action_Remove;
else if (value=="Edit And Remove")
action = Action_EditAndRemove;
mDoubleClickActions[modifiers] = action;
return;
}
}
std::vector<int> CSVTools::ReportTable::getReplaceIndices (bool selection) const
{
std::vector<int> indices;
@ -285,6 +257,44 @@ void CSVTools::ReportTable::flagAsReplaced (int index)
mModel->flagAsReplaced (index);
}
void CSVTools::ReportTable::settingChanged (const CSMPrefs::Setting *setting)
{
if (setting->getParent()->getKey()=="Reports")
{
QString base ("double");
QString key = setting->getKey().c_str();
if (key.startsWith (base))
{
QString modifierString = key.mid (base.size());
Qt::KeyboardModifiers modifiers = 0;
if (modifierString=="-s")
modifiers = Qt::ShiftModifier;
else if (modifierString=="-c")
modifiers = Qt::ControlModifier;
else if (modifierString=="-sc")
modifiers = Qt::ShiftModifier | Qt::ControlModifier;
DoubleClickAction action = Action_None;
std::string value = setting->toString();
if (value=="Edit")
action = Action_Edit;
else if (value=="Remove")
action = Action_Remove;
else if (value=="Edit And Remove")
action = Action_EditAndRemove;
mDoubleClickActions[modifiers] = action;
return;
}
}
else if (*setting=="Records/type-format")
mIdTypeDelegate->settingChanged (setting);
}
void CSVTools::ReportTable::showSelection()
{
QModelIndexList selectedRows = selectionModel()->selectedRows();

@ -13,6 +13,11 @@ namespace CSMTools
class ReportModel;
}
namespace CSMPrefs
{
class Setting;
}
namespace CSVWorld
{
class CommandDelegate;
@ -61,8 +66,6 @@ namespace CSVTools
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;
void updateUserSetting (const QString& name, const QStringList& list);
void clear();
/// Return indices of rows that are suitable for replacement.
@ -77,6 +80,8 @@ namespace CSVTools
private slots:
void settingChanged (const CSMPrefs::Setting *setting);
void showSelection();
void removeSelection();

@ -102,11 +102,6 @@ void CSVTools::SearchSubView::setEditLock (bool locked)
mSearchBox.setEditLock (locked);
}
void CSVTools::SearchSubView::updateUserSetting (const QString &name, const QStringList &list)
{
mTable->updateUserSetting (name, list);
}
void CSVTools::SearchSubView::stateChanged (int state, CSMDoc::Document *document)
{
mSearchBox.setSearchMode (!(state & CSMDoc::State_Searching));

@ -36,15 +36,13 @@ namespace CSVTools
protected:
void showEvent (QShowEvent *event);
public:
SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
virtual void setEditLock (bool locked);
virtual void updateUserSetting (const QString &, const QStringList &);
private slots:
void stateChanged (int state, CSMDoc::Document *document);

@ -1,5 +1,6 @@
#include "datadisplaydelegate.hpp"
#include "../../model/settings/usersettings.hpp"
#include "../../model/prefs/state.hpp"
#include <QApplication>
#include <QPainter>
@ -8,8 +9,8 @@ CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList &values,
const IconList &icons,
CSMWorld::CommandDispatcher *dispatcher,
CSMDoc::Document& document,
const QString &pageName,
const QString &settingName,
const std::string &pageName,
const std::string &settingName,
QObject *parent)
: EnumDelegate (values, dispatcher, document, parent), mDisplayMode (Mode_TextOnly),
mIcons (icons), mIconSize (QSize(16, 16)),
@ -18,10 +19,8 @@ CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList &values,
{
buildPixmaps();
QString value =
CSMSettings::UserSettings::instance().settingValue (mSettingKey);
updateDisplayMode(value);
if (!pageName.empty())
updateDisplayMode (CSMPrefs::get()[pageName][settingName].toString());
}
void CSVWorld::DataDisplayDelegate::buildPixmaps ()
@ -52,7 +51,7 @@ void CSVWorld::DataDisplayDelegate::setTextLeftOffset(int offset)
QSize CSVWorld::DataDisplayDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size = EnumDelegate::sizeHint(option, index);
int valueIndex = getValueIndex(index);
if (valueIndex != -1)
{
@ -105,7 +104,7 @@ void CSVWorld::DataDisplayDelegate::paintIcon (QPainter *painter, const QStyleOp
textRect.setLeft(iconRect.right() + mTextLeftOffset);
textRect.setRight(option.rect.right() - mHorizontalMargin);
QString text = option.fontMetrics.elidedText(mValues.at(index).second,
QString text = option.fontMetrics.elidedText(mValues.at(index).second,
option.textElideMode,
textRect.width());
QApplication::style()->drawItemText(painter,
@ -118,19 +117,7 @@ void CSVWorld::DataDisplayDelegate::paintIcon (QPainter *painter, const QStyleOp
QApplication::style()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, mPixmaps.at(index).second);
}
void CSVWorld::DataDisplayDelegate::updateUserSetting (const QString &name,
const QStringList &list)
{
if (list.isEmpty())
return;
QString value = list.at(0);
if (name == mSettingKey)
updateDisplayMode (value);
}
void CSVWorld::DataDisplayDelegate::updateDisplayMode (const QString &mode)
void CSVWorld::DataDisplayDelegate::updateDisplayMode (const std::string &mode)
{
if (mode == "Icon and Text")
mDisplayMode = Mode_IconAndText;
@ -146,6 +133,13 @@ CSVWorld::DataDisplayDelegate::~DataDisplayDelegate()
{
}
void CSVWorld::DataDisplayDelegate::settingChanged (const CSMPrefs::Setting *setting)
{
if (*setting==mSettingKey)
updateDisplayMode (setting->toString());
}
void CSVWorld::DataDisplayDelegateFactory::add (int enumValue, QString enumName, QString iconFilename)
{
mIcons.push_back (std::make_pair(enumValue, QIcon(iconFilename)));
@ -158,5 +152,3 @@ CSVWorld::CommandDelegate *CSVWorld::DataDisplayDelegateFactory::makeDelegate (
{
return new DataDisplayDelegate (mValues, mIcons, dispatcher, document, "", "", parent);
}

@ -4,10 +4,13 @@
#include <QTextOption>
#include "enumdelegate.hpp"
namespace CSVWorld
namespace CSMPrefs
{
class Setting;
}
namespace CSVWorld
{
class DataDisplayDelegate : public EnumDelegate
{
public:
@ -34,12 +37,12 @@ namespace CSVWorld
int mHorizontalMargin;
int mTextLeftOffset;
QString mSettingKey;
std::string mSettingKey;
public:
DataDisplayDelegate (const ValueList & values, const IconList & icons,
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document,
const QString &pageName, const QString &settingName, QObject *parent);
const std::string& pageName, const std::string& settingName, QObject *parent);
~DataDisplayDelegate();
@ -53,13 +56,10 @@ namespace CSVWorld
/// offset the horizontal position of the text from the right edge of the icon. Default is 8 pixels.
void setTextLeftOffset (int offset);
///update the display mode for the delegate
void updateUserSetting (const QString &name, const QStringList &list);
private:
/// update the display mode based on a passed string
void updateDisplayMode (const QString &);
void updateDisplayMode (const std::string &);
/// custom paint function for painting the icon. Mode_IconAndText and Mode_Icon only.
void paintIcon (QPainter *painter, const QStyleOptionViewItem &option, int i) const;
@ -67,6 +67,7 @@ namespace CSVWorld
/// rebuild the list of pixmaps from the provided icons (called when icon size is changed)
void buildPixmaps();
virtual void settingChanged (const CSMPrefs::Setting *setting);
};
class DataDisplayDelegateFactory : public EnumDelegateFactory

@ -919,9 +919,6 @@ void CSVWorld::DialogueSubView::updateUserSetting (const QString& name, const QS
}
}
}
if (mButtons)
mButtons->updateUserSetting (name, value);
}
void CSVWorld::DialogueSubView::showPreview ()

@ -5,7 +5,7 @@
CSVWorld::IdTypeDelegate::IdTypeDelegate
(const ValueList &values, const IconList &icons, CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent)
: DataDisplayDelegate (values, icons, dispatcher, document,
"records", "type-format",
"Records", "type-format",
parent)
{}

@ -6,7 +6,7 @@
#include "../../model/world/idtable.hpp"
#include "../../model/world/commanddispatcher.hpp"
#include "../../model/settings/usersettings.hpp"
#include "../../model/prefs/state.hpp"
#include "../world/tablebottombox.hpp"
@ -32,7 +32,7 @@ void CSVWorld::RecordButtonBar::updatePrevNextButtons()
mPrevButton->setDisabled (true);
mNextButton->setDisabled (true);
}
else if (CSMSettings::UserSettings::instance().settingValue ("general-input/cycle")=="true")
else if (CSMPrefs::get()["General Input"]["cycle"].isTrue())
{
mPrevButton->setDisabled (false);
mNextButton->setDisabled (false);
@ -131,6 +131,9 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
connect (&mTable, SIGNAL (rowsRemoved (const QModelIndex&, int, int)),
this, SLOT (rowNumberChanged (const QModelIndex&, int, int)));
connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
this, SLOT (settingChanged (const CSMPrefs::Setting *)));
updateModificationButtons();
updatePrevNextButtons();
}
@ -141,18 +144,18 @@ void CSVWorld::RecordButtonBar::setEditLock (bool locked)
updateModificationButtons();
}
void CSVWorld::RecordButtonBar::updateUserSetting (const QString& name, const QStringList& value)
{
if (name=="general-input/cycle")
updatePrevNextButtons();
}
void CSVWorld::RecordButtonBar::universalIdChanged (const CSMWorld::UniversalId& id)
{
mId = id;
updatePrevNextButtons();
}
void CSVWorld::RecordButtonBar::settingChanged (const CSMPrefs::Setting *setting)
{
if (*setting=="General Input/cycle")
updatePrevNextButtons();
}
void CSVWorld::RecordButtonBar::cloneRequest()
{
if (mBottom)
@ -173,8 +176,7 @@ void CSVWorld::RecordButtonBar::nextId()
if (newRow >= mTable.rowCount())
{
if (CSMSettings::UserSettings::instance().settingValue ("general-input/cycle")
=="true")
if (CSMPrefs::get()["General Input"]["cycle"].isTrue())
newRow = 0;
else
return;
@ -189,8 +191,7 @@ void CSVWorld::RecordButtonBar::prevId()
if (newRow < 0)
{
if (CSMSettings::UserSettings::instance().settingValue ("general-input/cycle")
=="true")
if (CSMPrefs::get()["General Input"]["cycle"].isTrue())
newRow = mTable.rowCount()-1;
else
return;

@ -14,6 +14,11 @@ namespace CSMWorld
class CommandDispatcher;
}
namespace CSMPrefs
{
class Setting;
}
namespace CSVWorld
{
class TableBottomBox;
@ -49,7 +54,7 @@ namespace CSVWorld
void updateModificationButtons();
void updatePrevNextButtons();
public:
RecordButtonBar (const CSMWorld::UniversalId& id,
@ -58,14 +63,14 @@ namespace CSVWorld
void setEditLock (bool locked);
void updateUserSetting (const QString& name, const QStringList& value);
public slots:
void universalIdChanged (const CSMWorld::UniversalId& id);
private slots:
void settingChanged (const CSMPrefs::Setting *setting);
void cloneRequest();
void nextId();
@ -73,7 +78,7 @@ namespace CSVWorld
void prevId();
void rowNumberChanged (const QModelIndex& parent, int start, int end);
signals:
void showPreview();

@ -11,7 +11,7 @@ CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values,
const IconList & icons,
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent)
: DataDisplayDelegate (values, icons, dispatcher, document,
"records", "status-format",
"Records", "status-format",
parent)
{}

@ -135,7 +135,7 @@ bool CSVWorld::ScriptErrorTable::clearLocals (const std::string& script)
void CSVWorld::ScriptErrorTable::settingChanged (const CSMPrefs::Setting *setting)
{
if (*setting=="Scripst/warnings")
if (*setting=="Scripts/warnings")
setWarningsMode (setting->toString());
}

@ -13,7 +13,7 @@
#include "../../model/world/columnbase.hpp"
#include "../../model/world/commands.hpp"
#include "../../model/world/idtable.hpp"
#include "../../model/settings/usersettings.hpp"
#include "../../model/prefs/state.hpp"
#include "scriptedit.hpp"
#include "recordbuttonbar.hpp"
@ -39,8 +39,7 @@ void CSVWorld::ScriptSubView::addButtonBar()
void CSVWorld::ScriptSubView::recompile()
{
if (!mCompileDelay->isActive() && !isDeleted())
mCompileDelay->start (
CSMSettings::UserSettings::instance().setting ("script-editor/compile-delay").toInt());
mCompileDelay->start (CSMPrefs::get()["Scripts"]["compile-delay"].toInt());
}
bool CSVWorld::ScriptSubView::isDeleted() const
@ -89,7 +88,7 @@ void CSVWorld::ScriptSubView::adjustSplitter()
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
: SubView (id), mDocument (document), mColumn (-1), mBottom(0), mButtons (0),
mCommandDispatcher (document, CSMWorld::UniversalId::getParentType (id.getType())),
mErrorHeight (CSMSettings::UserSettings::instance().setting ("script-editor/error-height").toInt())
mErrorHeight (CSMPrefs::get()["Scripts"]["error-height"].toInt())
{
std::vector<std::string> selection (1, id.getId());
mCommandDispatcher.setSelection (selection);
@ -126,9 +125,6 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
// bottom box and buttons
mBottom = new TableBottomBox (CreatorFactory<GenericCreator>(), document, id, this);
if (CSMSettings::UserSettings::instance().setting ("script-editor/toolbar", QString("true")) == "true")
addButtonBar();
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
this, SLOT (switchToId (const std::string&)));
@ -156,53 +152,40 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
connect (mCompileDelay, SIGNAL (timeout()), this, SLOT (updateRequest()));
updateDeletedState();
connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
this, SLOT (settingChanged (const CSMPrefs::Setting *)));
CSMPrefs::get()["Scripts"].update();
}
void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStringList& value)
void CSVWorld::ScriptSubView::setStatusBar (bool show)
{
if (name == "script-editor/show-linenum")
{
std::string showLinenum = value.at(0).toUtf8().constData();
mEditor->showLineNum(showLinenum == "true");
mBottom->setVisible(showLinenum == "true");
}
else if (name == "script-editor/mono-font")
{
mEditor->setMonoFont (value.at(0)==QString ("true"));
}
else if (name=="script-editor/toolbar")
mBottom->setStatusBar (show);
}
void CSVWorld::ScriptSubView::settingChanged (const CSMPrefs::Setting *setting)
{
if (*setting=="Scripts/toolbar")
{
if (value.at(0)==QString ("true"))
if (setting->isTrue())
{
addButtonBar();
}
else
else if (mButtons)
{
if (mButtons)
{
mLayout.removeWidget (mButtons);
delete mButtons;
mButtons = 0;
}
mLayout.removeWidget (mButtons);
delete mButtons;
mButtons = 0;
}
}
else if (name=="script-editor/compile-delay")
else if (*setting=="Scripts/compile-delay")
{
mCompileDelay->setInterval (value.at (0).toInt());
mCompileDelay->setInterval (setting->toInt());
}
if (mButtons)
mButtons->updateUserSetting (name, value);
if (name=="script-editor/warnings")
else if (*setting=="Scripts/warnings")
recompile();
}
void CSVWorld::ScriptSubView::setStatusBar (bool show)
{
mBottom->setStatusBar (show);
}
void CSVWorld::ScriptSubView::updateStatusBar ()
{
mBottom->positionChanged (mEditor->textCursor().blockNumber() + 1,

@ -23,6 +23,11 @@ namespace CSMWorld
class IdTable;
}
namespace CSMPrefs
{
class Setting;
}
namespace CSVWorld
{
class ScriptEdit;
@ -69,8 +74,6 @@ namespace CSVWorld
virtual void useHint (const std::string& hint);
virtual void updateUserSetting (const QString& name, const QStringList& value);
virtual void setStatusBar (bool show);
public slots:
@ -83,6 +86,8 @@ namespace CSVWorld
private slots:
void settingChanged (const CSMPrefs::Setting *setting);
void updateStatusBar();
void switchToRow (int row);

@ -558,23 +558,6 @@ void CSVWorld::Table::executeExtendedRevert()
void CSVWorld::Table::updateUserSetting (const QString &name, const QStringList &list)
{
if (name=="records/type-format" || name=="records/status-format")
{
int columns = mModel->columnCount();
for (int i=0; i<columns; ++i)
if (QAbstractItemDelegate *delegate = itemDelegateForColumn (i))
{
dynamic_cast<CommandDelegate&>
(*delegate).updateUserSetting (name, list);
{
emit dataChanged (mModel->index (0, i),
mModel->index (mModel->rowCount()-1, i));
}
}
return;
}
QString base ("table-input/double");
if (name.startsWith (base))
{
@ -633,7 +616,18 @@ void CSVWorld::Table::settingChanged (const CSMPrefs::Setting *setting)
mUnselectAfterJump = false;
}
}
else if (*setting=="Records/type-format" || *setting=="Records/status-format")
{
int columns = mModel->columnCount();
for (int i=0; i<columns; ++i)
if (QAbstractItemDelegate *delegate = itemDelegateForColumn (i))
{
dynamic_cast<CommandDelegate&> (*delegate).settingChanged (setting);
emit dataChanged (mModel->index (0, i),
mModel->index (mModel->rowCount()-1, i));
}
}
}
void CSVWorld::Table::tableSizeUpdate()

@ -166,7 +166,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
const QModelIndex& index) const
{
CSMWorld::ColumnBase::Display display = getDisplayTypeFromIndex(index);
// This createEditor() method is called implicitly from tables.
// For boolean values in tables use the default editor (combobox).
// Checkboxes is looking ugly in the table view.
@ -239,7 +239,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
edit->setUndoRedoEnabled (false);
return edit;
}
case CSMWorld::ColumnBase::Display_Boolean:
return new QCheckBox(parent);
@ -260,7 +260,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
widget->setMaxLength (32);
return widget;
}
default:
return QStyledItemDelegate::createEditor (parent, option, index);
@ -329,3 +329,5 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
}
}
void CSVWorld::CommandDelegate::settingChanged (const CSMPrefs::Setting *setting) {}

@ -18,6 +18,11 @@ namespace CSMWorld
class CommandDispatcher;
}
namespace CSMPrefs
{
class Setting;
}
namespace CSVWorld
{
///< \brief Getting the data out of an editor widget
@ -138,10 +143,9 @@ namespace CSVWorld
virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const;
public slots:
virtual void updateUserSetting
(const QString &name, const QStringList &list) {}
/// \attention This is not a slot. For ordering reasons this function needs to be
/// called manually from the parent object's settingChanged function.
virtual void settingChanged (const CSMPrefs::Setting *setting);
};
}

Loading…
Cancel
Save