|
|
|
@ -4,10 +4,10 @@
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
|
|
|
|
|
|
#include "idtable.hpp"
|
|
|
|
|
#include "idtable.hpp"
|
|
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
|
|
|
|
|
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_)
|
|
|
|
|
{
|
|
|
|
|
mOld = mModel.data (mIndex, Qt::EditRole);
|
|
|
|
@ -25,7 +25,7 @@ void CSMWorld::ModifyCommand::undo()
|
|
|
|
|
mModel.setData (mIndex, mOld);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent)
|
|
|
|
|
CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand* parent)
|
|
|
|
|
: QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None)
|
|
|
|
|
{
|
|
|
|
|
setText (("Create record " + id).c_str());
|
|
|
|
@ -54,7 +54,7 @@ void CSMWorld::CreateCommand::undo()
|
|
|
|
|
mModel.removeRow (mModel.getModelIndex (mId, 0).row());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand *parent)
|
|
|
|
|
CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand* parent)
|
|
|
|
|
: QUndoCommand (parent), mModel (model), mId (id), mOld (0)
|
|
|
|
|
{
|
|
|
|
|
setText (("Revert record " + id).c_str());
|
|
|
|
@ -89,7 +89,7 @@ void CSMWorld::RevertCommand::undo()
|
|
|
|
|
mModel.setRecord (mId, *mOld);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand *parent)
|
|
|
|
|
CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand* parent)
|
|
|
|
|
: QUndoCommand (parent), mModel (model), mId (id), mOld (0)
|
|
|
|
|
{
|
|
|
|
|
setText (("Delete record " + id).c_str());
|
|
|
|
@ -126,7 +126,7 @@ void CSMWorld::DeleteCommand::undo()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CSMWorld::ReorderRowsCommand::ReorderRowsCommand (IdTable& model, int baseIndex,
|
|
|
|
|
const std::vector<int>& newOrder)
|
|
|
|
|
const std::vector<int>& newOrder)
|
|
|
|
|
: mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
@ -140,8 +140,35 @@ void CSMWorld::ReorderRowsCommand::undo()
|
|
|
|
|
int size = static_cast<int> (mNewOrder.size());
|
|
|
|
|
std::vector<int> reverse (size);
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<size; ++i)
|
|
|
|
|
for (int i=0; i< size; ++i)
|
|
|
|
|
reverse.at (mNewOrder[i]) = i;
|
|
|
|
|
|
|
|
|
|
mModel.reorderRows (mBaseIndex, reverse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model,
|
|
|
|
|
const std::string& idOrigin,
|
|
|
|
|
const std::string& IdDestination,
|
|
|
|
|
const CSMWorld::UniversalId::Type type,
|
|
|
|
|
QUndoCommand* parent) :
|
|
|
|
|
QUndoCommand (parent),
|
|
|
|
|
mModel (model),
|
|
|
|
|
mIdOrigin (idOrigin),
|
|
|
|
|
mIdDestination (Misc::StringUtils::lowerCase (IdDestination)),
|
|
|
|
|
mType (type)
|
|
|
|
|
{
|
|
|
|
|
setText ( ("Clone record " + idOrigin + " to the " + IdDestination).c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSMWorld::CloneCommand::redo()
|
|
|
|
|
{
|
|
|
|
|
mModel.cloneRecord (mIdOrigin, mIdDestination, mType);
|
|
|
|
|
|
|
|
|
|
for (std::map<int, QVariant>::const_iterator iter (mValues.begin()); iter != mValues.end(); ++iter)
|
|
|
|
|
mModel.setData (mModel.getModelIndex (mIdDestination, iter->first), iter->second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSMWorld::CloneCommand::undo()
|
|
|
|
|
{
|
|
|
|
|
mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row());
|
|
|
|
|
}
|