In ModifyCommand replace proxy model with the source model (Fixes #2498)

test
Marc Zinnschlag 10 years ago
parent 82bc666e00
commit 6fcf4ea9e3

@ -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…
Cancel
Save