use commands for modifying globals
parent
8a09e03d5c
commit
4086b556d2
@ -0,0 +1,23 @@
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
||||
const QVariant& new_, QUndoCommand *parent)
|
||||
: QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_)
|
||||
{
|
||||
mOld = mModel.data (mIndex, Qt::EditRole);
|
||||
|
||||
setText ("Modify " + mModel.headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyCommand::redo()
|
||||
{
|
||||
mModel.setData (mIndex, mNew);
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyCommand::undo()
|
||||
{
|
||||
mModel.setData (mIndex, mOld);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#ifndef CSM_WOLRD_COMMANDS_H
|
||||
#define CSM_WOLRD_COMMANDS_H
|
||||
|
||||
#include "record.hpp"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QUndoCommand>
|
||||
#include <QModelIndex>
|
||||
|
||||
class QModelIndex;
|
||||
class QAbstractItemModel;
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class ModifyCommand : public QUndoCommand
|
||||
{
|
||||
QAbstractItemModel& mModel;
|
||||
QModelIndex mIndex;
|
||||
QVariant mNew;
|
||||
QVariant mOld;
|
||||
|
||||
public:
|
||||
|
||||
ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_,
|
||||
QUndoCommand *parent = 0);
|
||||
|
||||
virtual void redo();
|
||||
|
||||
virtual void undo();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue