2012-11-29 16:05:28 +01:00
|
|
|
|
|
|
|
#include "commands.hpp"
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
|
2012-12-03 21:44:16 +01:00
|
|
|
#include "idtableproxymodel.hpp"
|
|
|
|
|
2012-11-29 16:05:28 +01:00
|
|
|
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);
|
2012-12-03 21:44:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CSMWorld::CreateCommand::CreateCommand (IdTableProxyModel& model, const std::string& id, QUndoCommand *parent)
|
|
|
|
: QUndoCommand (parent), mModel (model), mId (id)
|
|
|
|
{
|
|
|
|
setText (("Create record " + id).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMWorld::CreateCommand::redo()
|
|
|
|
{
|
|
|
|
mModel.addRecord (mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMWorld::CreateCommand::undo()
|
|
|
|
{
|
|
|
|
mModel.removeRow (mModel.getModelIndex (mId, 0).row());
|
2012-11-29 16:05:28 +01:00
|
|
|
}
|