mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
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 "commands.hpp"
|
||||||
|
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QAbstractProxyModel>
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#include "idtable.hpp"
|
||||||
#include "idtree.hpp"
|
#include "idtree.hpp"
|
||||||
#include <components/misc/stringops.hpp>
|
|
||||||
#include "nestedtablewrapper.hpp"
|
#include "nestedtablewrapper.hpp"
|
||||||
|
|
||||||
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
||||||
const QVariant& new_, QUndoCommand* parent)
|
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()
|
void CSMWorld::ModifyCommand::redo()
|
||||||
{
|
{
|
||||||
mOld = mModel.data (mIndex, Qt::EditRole);
|
mOld = mModel->data (mIndex, Qt::EditRole);
|
||||||
mModel.setData (mIndex, mNew);
|
mModel->setData (mIndex, mNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::ModifyCommand::undo()
|
void CSMWorld::ModifyCommand::undo()
|
||||||
{
|
{
|
||||||
mModel.setData (mIndex, mOld);
|
mModel->setData (mIndex, mOld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
class ModifyCommand : public QUndoCommand
|
class ModifyCommand : public QUndoCommand
|
||||||
{
|
{
|
||||||
QAbstractItemModel& mModel;
|
QAbstractItemModel *mModel;
|
||||||
QModelIndex mIndex;
|
QModelIndex mIndex;
|
||||||
QVariant mNew;
|
QVariant mNew;
|
||||||
QVariant mOld;
|
QVariant mOld;
|
||||||
|
|
Loading…
Reference in a new issue