forked from mirror/openmw-tes3mp
In ModifyCommand replace proxy model with the source model (Fixes #2498)
This commit is contained in:
parent
82bc666e00
commit
6fcf4ea9e3
2 changed files with 16 additions and 7 deletions
|
@ -1,28 +1,37 @@
|
|||
#include "commands.hpp"
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractProxyModel>
|
||||
|
||||
#include "idtable.hpp"
|
||||
#include "idtree.hpp"
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include "nestedtablewrapper.hpp"
|
||||
|
||||
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
||||
const QVariant& new_, QUndoCommand* parent)
|
||||
: QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_)
|
||||
: QUndoCommand (parent), mModel (&model), mIndex (index), mNew (new_)
|
||||
{
|
||||
setText ("Modify " + mModel.headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
if (QAbstractProxyModel *proxy = dynamic_cast<QAbstractProxyModel *> (&model))
|
||||
{
|
||||
// Replace proxy with actual model
|
||||
mIndex = proxy->mapToSource (index);
|
||||
mModel = proxy->sourceModel();
|
||||
}
|
||||
|
||||
setText ("Modify " + mModel->headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyCommand::redo()
|
||||
{
|
||||
mOld = mModel.data (mIndex, Qt::EditRole);
|
||||
mModel.setData (mIndex, mNew);
|
||||
mOld = mModel->data (mIndex, Qt::EditRole);
|
||||
mModel->setData (mIndex, mNew);
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyCommand::undo()
|
||||
{
|
||||
mModel.setData (mIndex, mOld);
|
||||
mModel->setData (mIndex, mOld);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace CSMWorld
|
|||
|
||||
class ModifyCommand : public QUndoCommand
|
||||
{
|
||||
QAbstractItemModel& mModel;
|
||||
QAbstractItemModel *mModel;
|
||||
QModelIndex mIndex;
|
||||
QVariant mNew;
|
||||
QVariant mOld;
|
||||
|
|
Loading…
Reference in a new issue