mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 17:15:33 +00:00
moving bloat away from the dispatcher
This commit is contained in:
parent
17b521cec8
commit
a25271f0b6
4 changed files with 84 additions and 27 deletions
|
@ -24,6 +24,59 @@
|
||||||
|
|
||||||
#include "recordstatusdelegate.hpp"
|
#include "recordstatusdelegate.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
/*
|
||||||
|
==============================NotEditableSubDelegate==========================================
|
||||||
|
*/
|
||||||
|
CSVWorld::NotEditableSubDelegate::NotEditableSubDelegate(const CSMWorld::IdTable* table, QObject * parent) :
|
||||||
|
QAbstractItemDelegate(parent),
|
||||||
|
mTable(table)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void CSVWorld::NotEditableSubDelegate::setEditorData (QLabel* editor, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
QVariant v = index.data(Qt::EditRole);
|
||||||
|
if (!v.isValid())
|
||||||
|
{
|
||||||
|
v = index.data(Qt::DisplayRole);
|
||||||
|
if (!v.isValid())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QVariant::String == v.type())
|
||||||
|
{
|
||||||
|
editor->setText(v.toString());
|
||||||
|
} else //else we are facing enums
|
||||||
|
{
|
||||||
|
int data = v.toInt();
|
||||||
|
std::vector<std::string> enumNames (CSMWorld::Columns::getEnums (static_cast<CSMWorld::Columns::ColumnId> (mTable->getColumnId (index.column()))));
|
||||||
|
editor->setText(QString::fromUtf8(enumNames.at(data).c_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::NotEditableSubDelegate::setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const
|
||||||
|
{
|
||||||
|
//not editable widgets will not save model data
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::NotEditableSubDelegate::paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
//does nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize CSVWorld::NotEditableSubDelegate::sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
return QSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget* CSVWorld::NotEditableSubDelegate::createEditor (QWidget *parent,
|
||||||
|
const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index,
|
||||||
|
CSMWorld::ColumnBase::Display display) const
|
||||||
|
{
|
||||||
|
return new QLabel(parent);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==============================DialogueDelegateDispatcherProxy==========================================
|
==============================DialogueDelegateDispatcherProxy==========================================
|
||||||
|
@ -64,7 +117,8 @@ QWidget* CSVWorld::DialogueDelegateDispatcherProxy::getEditor() const
|
||||||
CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack) :
|
CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack) :
|
||||||
mParent(parent),
|
mParent(parent),
|
||||||
mTable(table),
|
mTable(table),
|
||||||
mUndoStack(undoStack)
|
mUndoStack(undoStack),
|
||||||
|
mNotEditableDelegate(table, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,27 +151,7 @@ void CSVWorld::DialogueDelegateDispatcher::setEditorData (QWidget* editor, const
|
||||||
QLabel* label = qobject_cast<QLabel*>(editor);
|
QLabel* label = qobject_cast<QLabel*>(editor);
|
||||||
if(label)
|
if(label)
|
||||||
{
|
{
|
||||||
QVariant v = index.data(Qt::EditRole);
|
mNotEditableDelegate.setEditorData(label, index);
|
||||||
if (!v.isValid())
|
|
||||||
{
|
|
||||||
v = index.data(Qt::DisplayRole);
|
|
||||||
if (!v.isValid())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CSMWorld::Columns::hasEnums(static_cast<CSMWorld::Columns::ColumnId>(mTable->getColumnId(index.column()))))
|
|
||||||
{
|
|
||||||
int data = v.toInt();
|
|
||||||
std::vector<std::string> enumNames (CSMWorld::Columns::getEnums (static_cast<CSMWorld::Columns::ColumnId> (mTable->getColumnId (index.column()))));
|
|
||||||
label->setText(QString::fromUtf8(enumNames.at(data).c_str()));
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
if (QVariant::String == v.type())
|
|
||||||
{
|
|
||||||
label->setText(v.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,8 +204,7 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
|
||||||
QWidget* editor = NULL;
|
QWidget* editor = NULL;
|
||||||
if (! (mTable->flags (index) & Qt::ItemIsEditable))
|
if (! (mTable->flags (index) & Qt::ItemIsEditable))
|
||||||
{
|
{
|
||||||
editor = new QLabel(qobject_cast<QWidget*>(mParent));
|
return mNotEditableDelegate.createEditor(qobject_cast<QWidget*>(mParent), QStyleOptionViewItem(), index, display);
|
||||||
return editor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, CommandDelegate*>::iterator delegateIt(mDelegates.find(display));
|
std::map<int, CommandDelegate*>::iterator delegateIt(mDelegates.find(display));
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
class QDataWidgetMapper;
|
class QDataWidgetMapper;
|
||||||
class QSize;
|
class QSize;
|
||||||
class QEvent;
|
class QEvent;
|
||||||
|
class QLabel;
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
|
@ -27,6 +28,27 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
class CommandDelegate;
|
class CommandDelegate;
|
||||||
|
|
||||||
|
class NotEditableSubDelegate : public QAbstractItemDelegate
|
||||||
|
{
|
||||||
|
const CSMWorld::IdTable* mTable;
|
||||||
|
public:
|
||||||
|
NotEditableSubDelegate(const CSMWorld::IdTable* table, QObject * parent = 0);
|
||||||
|
|
||||||
|
virtual void setEditorData (QLabel* editor, const QModelIndex& index) const;
|
||||||
|
|
||||||
|
virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const;
|
||||||
|
|
||||||
|
virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
|
///< does nothing
|
||||||
|
|
||||||
|
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
|
///< does nothing
|
||||||
|
|
||||||
|
virtual QWidget *createEditor (QWidget *parent,
|
||||||
|
const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index,
|
||||||
|
CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const;
|
||||||
|
};
|
||||||
|
|
||||||
//this can't be nested into the DialogueDelegateDispatcher, because it needs to emit signals
|
//this can't be nested into the DialogueDelegateDispatcher, because it needs to emit signals
|
||||||
class DialogueDelegateDispatcherProxy : public QObject
|
class DialogueDelegateDispatcherProxy : public QObject
|
||||||
|
@ -68,6 +90,8 @@ namespace CSVWorld
|
||||||
|
|
||||||
QUndoStack& mUndoStack;
|
QUndoStack& mUndoStack;
|
||||||
|
|
||||||
|
NotEditableSubDelegate mNotEditableDelegate;
|
||||||
|
|
||||||
std::vector<DialogueDelegateDispatcherProxy*> mProxys; //once we move to the C++11 we should use unique_ptr
|
std::vector<DialogueDelegateDispatcherProxy*> mProxys; //once we move to the C++11 we should use unique_ptr
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -190,7 +190,7 @@ bool CSVWorld::CommandDelegate::updateEditorSetting (const QString &settingName,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay)
|
void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const
|
||||||
{
|
{
|
||||||
QVariant v = index.data(Qt::EditRole);
|
QVariant v = index.data(Qt::EditRole);
|
||||||
if (tryDisplay)
|
if (tryDisplay)
|
||||||
|
@ -204,7 +204,7 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor);
|
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor);
|
||||||
if(plainTextEdit)
|
if(plainTextEdit) //for some reason it is easier to brake the loop here
|
||||||
{
|
{
|
||||||
if(plainTextEdit->toPlainText() == v.toString())
|
if(plainTextEdit->toPlainText() == v.toString())
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,7 +113,7 @@ namespace CSVWorld
|
||||||
virtual bool updateEditorSetting (const QString &settingName, const QString &settingValue);
|
virtual bool updateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||||
///< \return Does column require update?
|
///< \return Does column require update?
|
||||||
|
|
||||||
virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false);
|
virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
Loading…
Reference in a new issue