mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
create modify commands through command dispatcher
This commit is contained in:
parent
320b994aef
commit
7615cbafce
@ -131,6 +131,14 @@ std::vector<CSMWorld::UniversalId> CSMWorld::CommandDispatcher::getExtendedTypes
|
|||||||
return tables;
|
return tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::CommandDispatcher::executeModify (QAbstractItemModel *model, const QModelIndex& index, const QVariant& new_)
|
||||||
|
{
|
||||||
|
if (mLocked)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mDocument.getUndoStack().push (new CSMWorld::ModifyCommand (*model, index, new_));
|
||||||
|
}
|
||||||
|
|
||||||
void CSMWorld::CommandDispatcher::executeDelete()
|
void CSMWorld::CommandDispatcher::executeDelete()
|
||||||
{
|
{
|
||||||
if (mLocked)
|
if (mLocked)
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
|
||||||
|
class QModelIndex;
|
||||||
|
class QAbstractItemModel;
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
class Document;
|
class Document;
|
||||||
@ -53,6 +56,12 @@ namespace CSMWorld
|
|||||||
/// the extended mode, the returned vector will be empty instead.
|
/// the extended mode, the returned vector will be empty instead.
|
||||||
std::vector<UniversalId> getExtendedTypes() const;
|
std::vector<UniversalId> getExtendedTypes() const;
|
||||||
|
|
||||||
|
/// Add a modify command to the undo stack.
|
||||||
|
///
|
||||||
|
/// \attention model must either be a model for the table operated on by this
|
||||||
|
/// dispatcher or a proxy of it.
|
||||||
|
void executeModify (QAbstractItemModel *model, const QModelIndex& index, const QVariant& new_);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void executeDelete();
|
void executeDelete();
|
||||||
|
@ -79,8 +79,8 @@ CSVTools::ReportTable::ReportTable (CSMDoc::Document& document,
|
|||||||
setModel (mModel);
|
setModel (mModel);
|
||||||
setColumnHidden (2, true);
|
setColumnHidden (2, true);
|
||||||
|
|
||||||
mIdTypeDelegate = CSVWorld::IdTypeDelegateFactory().makeDelegate (
|
mIdTypeDelegate = CSVWorld::IdTypeDelegateFactory().makeDelegate (0,
|
||||||
document, this);
|
mDocument, this);
|
||||||
|
|
||||||
setItemDelegateForColumn (0, mIdTypeDelegate);
|
setItemDelegateForColumn (0, mIdTypeDelegate);
|
||||||
|
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
|
|
||||||
CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList &values,
|
CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList &values,
|
||||||
const IconList &icons,
|
const IconList &icons,
|
||||||
|
CSMWorld::CommandDispatcher *dispatcher,
|
||||||
CSMDoc::Document& document,
|
CSMDoc::Document& document,
|
||||||
const QString &pageName,
|
const QString &pageName,
|
||||||
const QString &settingName,
|
const QString &settingName,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
: EnumDelegate (values, document, parent), mDisplayMode (Mode_TextOnly),
|
: EnumDelegate (values, dispatcher, document, parent), mDisplayMode (Mode_TextOnly),
|
||||||
mIcons (icons), mIconSize (QSize(16, 16)), mIconLeftOffset(3),
|
mIcons (icons), mIconSize (QSize(16, 16)), mIconLeftOffset(3),
|
||||||
mTextLeftOffset(8), mSettingKey (pageName + '/' + settingName)
|
mTextLeftOffset(8), mSettingKey (pageName + '/' + settingName)
|
||||||
{
|
{
|
||||||
@ -136,9 +137,9 @@ void CSVWorld::DataDisplayDelegateFactory::add (int enumValue, QString enumName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate *CSVWorld::DataDisplayDelegateFactory::makeDelegate (
|
CSVWorld::CommandDelegate *CSVWorld::DataDisplayDelegateFactory::makeDelegate (
|
||||||
CSMDoc::Document& document, QObject *parent) const
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const
|
||||||
{
|
{
|
||||||
return new DataDisplayDelegate (mValues, mIcons, document, "", "", parent);
|
return new DataDisplayDelegate (mValues, mIcons, dispatcher, document, "", "", parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,12 +38,9 @@ namespace CSVWorld
|
|||||||
QString mSettingKey;
|
QString mSettingKey;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DataDisplayDelegate (const ValueList & values,
|
DataDisplayDelegate (const ValueList & values, const IconList & icons,
|
||||||
const IconList & icons,
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document,
|
||||||
CSMDoc::Document& document,
|
const QString &pageName, const QString &settingName, QObject *parent);
|
||||||
const QString &pageName,
|
|
||||||
const QString &settingName,
|
|
||||||
QObject *parent);
|
|
||||||
|
|
||||||
~DataDisplayDelegate();
|
~DataDisplayDelegate();
|
||||||
|
|
||||||
@ -82,7 +79,7 @@ namespace CSVWorld
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual CommandDelegate *makeDelegate (CSMDoc::Document& document, QObject *parent) const;
|
virtual CommandDelegate *makeDelegate (CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const;
|
||||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -167,10 +167,10 @@ void CSVWorld::DialogueDelegateDispatcherProxy::tableMimeDataDropped(const std::
|
|||||||
==============================DialogueDelegateDispatcher==========================================
|
==============================DialogueDelegateDispatcher==========================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, CSMDoc::Document& document) :
|
CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, CSMWorld::CommandDispatcher& commandDispatcher, CSMDoc::Document& document) :
|
||||||
mParent(parent),
|
mParent(parent),
|
||||||
mTable(table),
|
mTable(table),
|
||||||
mDocument (document),
|
mCommandDispatcher (commandDispatcher), mDocument (document),
|
||||||
mNotEditableDelegate(table, parent)
|
mNotEditableDelegate(table, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ CSVWorld::CommandDelegate* CSVWorld::DialogueDelegateDispatcher::makeDelegate(CS
|
|||||||
if (delegateIt == mDelegates.end())
|
if (delegateIt == mDelegates.end())
|
||||||
{
|
{
|
||||||
delegate = CommandDelegateFactoryCollection::get().makeDelegate (
|
delegate = CommandDelegateFactoryCollection::get().makeDelegate (
|
||||||
display, mDocument, mParent);
|
display, &mCommandDispatcher, mDocument, mParent);
|
||||||
mDelegates.insert(std::make_pair(display, delegate));
|
mDelegates.insert(std::make_pair(display, delegate));
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@ -309,12 +309,12 @@ CSVWorld::DialogueDelegateDispatcher::~DialogueDelegateDispatcher()
|
|||||||
=============================================================EditWidget=====================================================
|
=============================================================EditWidget=====================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CSVWorld::EditWidget::EditWidget(QWidget *parent, int row, CSMWorld::IdTable* table, CSMDoc::Document& document, bool createAndDelete) :
|
CSVWorld::EditWidget::EditWidget(QWidget *parent, int row, CSMWorld::IdTable* table, CSMWorld::CommandDispatcher& commandDispatcher, CSMDoc::Document& document, bool createAndDelete) :
|
||||||
mDispatcher(this, table, document),
|
mDispatcher(this, table, commandDispatcher, document),
|
||||||
QScrollArea(parent),
|
QScrollArea(parent),
|
||||||
mWidgetMapper(NULL),
|
mWidgetMapper(NULL),
|
||||||
mMainWidget(NULL),
|
mMainWidget(NULL),
|
||||||
mDocument (document),
|
mCommandDispatcher (commandDispatcher),
|
||||||
mTable(table)
|
mTable(table)
|
||||||
{
|
{
|
||||||
remake (row);
|
remake (row);
|
||||||
@ -471,7 +471,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
|
|||||||
|
|
||||||
mMainLayout = new QVBoxLayout(mainWidget);
|
mMainLayout = new QVBoxLayout(mainWidget);
|
||||||
|
|
||||||
mEditWidget = new EditWidget(mainWidget, mRow, mTable, document, false);
|
mEditWidget = new EditWidget(mainWidget, mRow, mTable, mCommandDispatcher, document, false);
|
||||||
connect(mEditWidget, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
|
connect(mEditWidget, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
|
||||||
this, SLOT(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
|
this, SLOT(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
|
||||||
|
|
||||||
|
@ -101,14 +101,16 @@ namespace CSVWorld
|
|||||||
|
|
||||||
CSMWorld::IdTable* mTable;
|
CSMWorld::IdTable* mTable;
|
||||||
|
|
||||||
CSMDoc::Document& mDocument;
|
CSMWorld::CommandDispatcher& mCommandDispatcher;
|
||||||
|
CSMDoc::Document& mDocument;
|
||||||
|
|
||||||
NotEditableSubDelegate mNotEditableDelegate;
|
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:
|
||||||
DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, CSMDoc::Document& document);
|
DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table,
|
||||||
|
CSMWorld::CommandDispatcher& commandDispatcher, CSMDoc::Document& document);
|
||||||
|
|
||||||
~DialogueDelegateDispatcher();
|
~DialogueDelegateDispatcher();
|
||||||
|
|
||||||
@ -145,11 +147,11 @@ namespace CSVWorld
|
|||||||
DialogueDelegateDispatcher mDispatcher;
|
DialogueDelegateDispatcher mDispatcher;
|
||||||
QWidget* mMainWidget;
|
QWidget* mMainWidget;
|
||||||
CSMWorld::IdTable* mTable;
|
CSMWorld::IdTable* mTable;
|
||||||
CSMDoc::Document& mDocument;
|
CSMWorld::CommandDispatcher& mCommandDispatcher;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table, CSMDoc::Document& document, bool createAndDelete = false);
|
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table, CSMWorld::CommandDispatcher& commandDispatcher, CSMDoc::Document& document, bool createAndDelete = false);
|
||||||
|
|
||||||
void remake(int row);
|
void remake(int row);
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ void CSVWorld::EnumDelegate::addCommands (QAbstractItemModel *model,
|
|||||||
|
|
||||||
|
|
||||||
CSVWorld::EnumDelegate::EnumDelegate (const std::vector<std::pair<int, QString> >& values,
|
CSVWorld::EnumDelegate::EnumDelegate (const std::vector<std::pair<int, QString> >& values,
|
||||||
CSMDoc::Document& document, QObject *parent)
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent)
|
||||||
: CommandDelegate (document, parent), mValues (values)
|
: CommandDelegate (dispatcher, document, parent), mValues (values)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -141,9 +141,9 @@ CSVWorld::EnumDelegateFactory::EnumDelegateFactory (const std::vector<std::strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate *CSVWorld::EnumDelegateFactory::makeDelegate (
|
CSVWorld::CommandDelegate *CSVWorld::EnumDelegateFactory::makeDelegate (
|
||||||
CSMDoc::Document& document, QObject *parent) const
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const
|
||||||
{
|
{
|
||||||
return new EnumDelegate (mValues, document, parent);
|
return new EnumDelegate (mValues, dispatcher, document, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::EnumDelegateFactory::add (int value, const QString& name)
|
void CSVWorld::EnumDelegateFactory::add (int value, const QString& name)
|
||||||
|
@ -30,7 +30,7 @@ namespace CSVWorld
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
EnumDelegate (const std::vector<std::pair<int, QString> >& values,
|
EnumDelegate (const std::vector<std::pair<int, QString> >& values,
|
||||||
CSMDoc::Document& document, QObject *parent);
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent);
|
||||||
|
|
||||||
virtual QWidget *createEditor(QWidget *parent,
|
virtual QWidget *createEditor(QWidget *parent,
|
||||||
const QStyleOptionViewItem& option,
|
const QStyleOptionViewItem& option,
|
||||||
@ -64,7 +64,7 @@ namespace CSVWorld
|
|||||||
EnumDelegateFactory (const std::vector<std::string>& names, bool allowNone = false);
|
EnumDelegateFactory (const std::vector<std::string>& names, bool allowNone = false);
|
||||||
/// \param allowNone Use value of -1 for "none selected" (empty string)
|
/// \param allowNone Use value of -1 for "none selected" (empty string)
|
||||||
|
|
||||||
virtual CommandDelegate *makeDelegate (CSMDoc::Document& document, QObject *parent) const;
|
virtual CommandDelegate *makeDelegate (CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const;
|
||||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
|
|
||||||
void add (int value, const QString& name);
|
void add (int value, const QString& name);
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
|
|
||||||
CSVWorld::IdTypeDelegate::IdTypeDelegate
|
CSVWorld::IdTypeDelegate::IdTypeDelegate
|
||||||
(const ValueList &values, const IconList &icons, CSMDoc::Document& document, QObject *parent)
|
(const ValueList &values, const IconList &icons, CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent)
|
||||||
: DataDisplayDelegate (values, icons, document,
|
: DataDisplayDelegate (values, icons, dispatcher, document,
|
||||||
"records", "type-format",
|
"records", "type-format",
|
||||||
parent)
|
parent)
|
||||||
{}
|
{}
|
||||||
@ -21,7 +21,7 @@ CSVWorld::IdTypeDelegateFactory::IdTypeDelegateFactory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate *CSVWorld::IdTypeDelegateFactory::makeDelegate (
|
CSVWorld::CommandDelegate *CSVWorld::IdTypeDelegateFactory::makeDelegate (
|
||||||
CSMDoc::Document& document, QObject *parent) const
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const
|
||||||
{
|
{
|
||||||
return new IdTypeDelegate (mValues, mIcons, document, parent);
|
return new IdTypeDelegate (mValues, mIcons, dispatcher, document, parent);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace CSVWorld
|
|||||||
class IdTypeDelegate : public DataDisplayDelegate
|
class IdTypeDelegate : public DataDisplayDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IdTypeDelegate (const ValueList &mValues, const IconList &icons, CSMDoc::Document& document, QObject *parent);
|
IdTypeDelegate (const ValueList &mValues, const IconList &icons, CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IdTypeDelegateFactory : public DataDisplayDelegateFactory
|
class IdTypeDelegateFactory : public DataDisplayDelegateFactory
|
||||||
@ -20,7 +20,7 @@ namespace CSVWorld
|
|||||||
|
|
||||||
IdTypeDelegateFactory();
|
IdTypeDelegateFactory();
|
||||||
|
|
||||||
virtual CommandDelegate *makeDelegate (CSMDoc::Document& document, QObject *parent) const;
|
virtual CommandDelegate *makeDelegate (CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const;
|
||||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,16 +9,16 @@
|
|||||||
|
|
||||||
CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values,
|
CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values,
|
||||||
const IconList & icons,
|
const IconList & icons,
|
||||||
CSMDoc::Document& document, QObject *parent)
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent)
|
||||||
: DataDisplayDelegate (values, icons, document,
|
: DataDisplayDelegate (values, icons, dispatcher, document,
|
||||||
"records", "status-format",
|
"records", "status-format",
|
||||||
parent)
|
parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (
|
CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (
|
||||||
CSMDoc::Document& document, QObject *parent) const
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const
|
||||||
{
|
{
|
||||||
return new RecordStatusDelegate (mValues, mIcons, document, parent);
|
return new RecordStatusDelegate (mValues, mIcons, dispatcher, document, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::RecordStatusDelegateFactory::RecordStatusDelegateFactory()
|
CSVWorld::RecordStatusDelegateFactory::RecordStatusDelegateFactory()
|
||||||
|
@ -17,9 +17,9 @@ namespace CSVWorld
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit RecordStatusDelegate(const ValueList& values,
|
RecordStatusDelegate (const ValueList& values, const IconList& icons,
|
||||||
const IconList& icons,
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document,
|
||||||
CSMDoc::Document& document, QObject *parent = 0);
|
QObject *parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
class RecordStatusDelegateFactory : public DataDisplayDelegateFactory
|
class RecordStatusDelegateFactory : public DataDisplayDelegateFactory
|
||||||
@ -28,7 +28,7 @@ namespace CSVWorld
|
|||||||
|
|
||||||
RecordStatusDelegateFactory();
|
RecordStatusDelegateFactory();
|
||||||
|
|
||||||
virtual CommandDelegate *makeDelegate (CSMDoc::Document& document, QObject *parent) const;
|
virtual CommandDelegate *makeDelegate (CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const;
|
||||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -281,7 +281,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id,
|
|||||||
mModel->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
mModel->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
||||||
|
|
||||||
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate (display,
|
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate (display,
|
||||||
mDocument, this);
|
mDispatcher, document, this);
|
||||||
|
|
||||||
mDelegates.push_back (delegate);
|
mDelegates.push_back (delegate);
|
||||||
setItemDelegateForColumn (i, delegate);
|
setItemDelegateForColumn (i, delegate);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "../../model/world/commands.hpp"
|
#include "../../model/world/commands.hpp"
|
||||||
#include "../../model/world/tablemimedata.hpp"
|
#include "../../model/world/tablemimedata.hpp"
|
||||||
|
#include "../../model/world/commanddispatcher.hpp"
|
||||||
|
|
||||||
#include "scriptedit.hpp"
|
#include "scriptedit.hpp"
|
||||||
|
|
||||||
@ -82,15 +83,15 @@ void CSVWorld::CommandDelegateFactoryCollection::add (CSMWorld::ColumnBase::Disp
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate *CSVWorld::CommandDelegateFactoryCollection::makeDelegate (
|
CSVWorld::CommandDelegate *CSVWorld::CommandDelegateFactoryCollection::makeDelegate (
|
||||||
CSMWorld::ColumnBase::Display display, CSMDoc::Document& document, QObject *parent) const
|
CSMWorld::ColumnBase::Display display, CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const
|
||||||
{
|
{
|
||||||
std::map<CSMWorld::ColumnBase::Display, CommandDelegateFactory *>::const_iterator iter =
|
std::map<CSMWorld::ColumnBase::Display, CommandDelegateFactory *>::const_iterator iter =
|
||||||
mFactories.find (display);
|
mFactories.find (display);
|
||||||
|
|
||||||
if (iter!=mFactories.end())
|
if (iter!=mFactories.end())
|
||||||
return iter->second->makeDelegate (document, parent);
|
return iter->second->makeDelegate (dispatcher, document, parent);
|
||||||
|
|
||||||
return new CommandDelegate (document, parent);
|
return new CommandDelegate (dispatcher, document, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSVWorld::CommandDelegateFactoryCollection& CSVWorld::CommandDelegateFactoryCollection::get()
|
const CSVWorld::CommandDelegateFactoryCollection& CSVWorld::CommandDelegateFactoryCollection::get()
|
||||||
@ -115,17 +116,22 @@ CSMDoc::Document& CSVWorld::CommandDelegate::getDocument() const
|
|||||||
void CSVWorld::CommandDelegate::setModelDataImp (QWidget *editor, QAbstractItemModel *model,
|
void CSVWorld::CommandDelegate::setModelDataImp (QWidget *editor, QAbstractItemModel *model,
|
||||||
const QModelIndex& index) const
|
const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
|
if (!mCommandDispatcher)
|
||||||
|
return;
|
||||||
|
|
||||||
NastyTableModelHack hack (*model);
|
NastyTableModelHack hack (*model);
|
||||||
QStyledItemDelegate::setModelData (editor, &hack, index);
|
QStyledItemDelegate::setModelData (editor, &hack, index);
|
||||||
|
|
||||||
QVariant new_ = hack.getData();
|
QVariant new_ = hack.getData();
|
||||||
|
|
||||||
if (model->data (index)!=new_)
|
if (model->data (index)!=new_)
|
||||||
getUndoStack().push (new CSMWorld::ModifyCommand (*model, index, new_));
|
mCommandDispatcher->executeModify (model, index, new_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate::CommandDelegate (CSMDoc::Document& document, QObject *parent)
|
CSVWorld::CommandDelegate::CommandDelegate (CSMWorld::CommandDispatcher *commandDispatcher,
|
||||||
: QStyledItemDelegate (parent), mDocument (document), mEditLock (false)
|
CSMDoc::Document& document, QObject *parent)
|
||||||
|
: QStyledItemDelegate (parent), mEditLock (false),
|
||||||
|
mCommandDispatcher (commandDispatcher), mDocument (document)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemModel *model,
|
void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemModel *model,
|
||||||
|
@ -16,6 +16,7 @@ namespace CSMWorld
|
|||||||
{
|
{
|
||||||
class TableMimeData;
|
class TableMimeData;
|
||||||
class UniversalId;
|
class UniversalId;
|
||||||
|
class CommandDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
@ -51,7 +52,8 @@ namespace CSVWorld
|
|||||||
|
|
||||||
virtual ~CommandDelegateFactory();
|
virtual ~CommandDelegateFactory();
|
||||||
|
|
||||||
virtual CommandDelegate *makeDelegate (CSMDoc::Document& document, QObject *parent)
|
virtual CommandDelegate *makeDelegate (CSMWorld::CommandDispatcher *dispatcher,
|
||||||
|
CSMDoc::Document& document, QObject *parent)
|
||||||
const = 0;
|
const = 0;
|
||||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
};
|
};
|
||||||
@ -78,7 +80,8 @@ namespace CSVWorld
|
|||||||
///
|
///
|
||||||
/// This function must not be called more than once per value of \a display.
|
/// This function must not be called more than once per value of \a display.
|
||||||
|
|
||||||
CommandDelegate *makeDelegate (CSMWorld::ColumnBase::Display display, CSMDoc::Document& document,
|
CommandDelegate *makeDelegate (CSMWorld::ColumnBase::Display display,
|
||||||
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document,
|
||||||
QObject *parent) const;
|
QObject *parent) const;
|
||||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
///
|
///
|
||||||
@ -111,8 +114,9 @@ namespace CSVWorld
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
CSMDoc::Document& mDocument;
|
|
||||||
bool mEditLock;
|
bool mEditLock;
|
||||||
|
CSMWorld::CommandDispatcher *mCommandDispatcher;
|
||||||
|
CSMDoc::Document& mDocument;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -125,7 +129,9 @@ namespace CSVWorld
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CommandDelegate (CSMDoc::Document& document, QObject *parent);
|
/// \param commandDispatcher If CommandDelegate will be only be used on read-only
|
||||||
|
/// cells, a 0-pointer can be passed here.
|
||||||
|
CommandDelegate (CSMWorld::CommandDispatcher *commandDispatcher, CSMDoc::Document& document, QObject *parent);
|
||||||
|
|
||||||
virtual void setModelData (QWidget *editor, QAbstractItemModel *model,
|
virtual void setModelData (QWidget *editor, QAbstractItemModel *model,
|
||||||
const QModelIndex& index) const;
|
const QModelIndex& index) const;
|
||||||
|
@ -47,8 +47,8 @@ void CSVWorld::VarTypeDelegate::addCommands (QAbstractItemModel *model, const QM
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::VarTypeDelegate::VarTypeDelegate (const std::vector<std::pair<int, QString> >& values,
|
CSVWorld::VarTypeDelegate::VarTypeDelegate (const std::vector<std::pair<int, QString> >& values,
|
||||||
CSMDoc::Document& document, QObject *parent)
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent)
|
||||||
: EnumDelegate (values, document, parent)
|
: EnumDelegate (values, dispatcher, document, parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -69,9 +69,9 @@ CSVWorld::VarTypeDelegateFactory::VarTypeDelegateFactory (ESM::VarType type0,
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate *CSVWorld::VarTypeDelegateFactory::makeDelegate (
|
CSVWorld::CommandDelegate *CSVWorld::VarTypeDelegateFactory::makeDelegate (
|
||||||
CSMDoc::Document& document, QObject *parent) const
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const
|
||||||
{
|
{
|
||||||
return new VarTypeDelegate (mValues, document, parent);
|
return new VarTypeDelegate (mValues, dispatcher, document, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::VarTypeDelegateFactory::add (ESM::VarType type)
|
void CSVWorld::VarTypeDelegateFactory::add (ESM::VarType type)
|
||||||
|
@ -17,7 +17,7 @@ namespace CSVWorld
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
VarTypeDelegate (const std::vector<std::pair<int, QString> >& values,
|
VarTypeDelegate (const std::vector<std::pair<int, QString> >& values,
|
||||||
CSMDoc::Document& document, QObject *parent);
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
class VarTypeDelegateFactory : public CommandDelegateFactory
|
class VarTypeDelegateFactory : public CommandDelegateFactory
|
||||||
@ -30,7 +30,8 @@ namespace CSVWorld
|
|||||||
ESM::VarType type1 = ESM::VT_Unknown, ESM::VarType type2 = ESM::VT_Unknown,
|
ESM::VarType type1 = ESM::VT_Unknown, ESM::VarType type2 = ESM::VT_Unknown,
|
||||||
ESM::VarType type3 = ESM::VT_Unknown);
|
ESM::VarType type3 = ESM::VT_Unknown);
|
||||||
|
|
||||||
virtual CommandDelegate *makeDelegate (CSMDoc::Document& document, QObject *parent) const;
|
virtual CommandDelegate *makeDelegate (CSMWorld::CommandDispatcher *dispatcher,
|
||||||
|
CSMDoc::Document& document, QObject *parent) const;
|
||||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
|
|
||||||
void add (ESM::VarType type);
|
void add (ESM::VarType type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user