mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-22 19:09:40 +00:00
made CloneCommand a subclass of CreateCommand
This commit is contained in:
parent
3add4bdf35
commit
7733df239e
2 changed files with 41 additions and 37 deletions
|
@ -24,6 +24,13 @@ void CSMWorld::ModifyCommand::undo()
|
||||||
mModel.setData (mIndex, mOld);
|
mModel.setData (mIndex, mOld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CSMWorld::CreateCommand::applyModifications()
|
||||||
|
{
|
||||||
|
for (std::map<int, QVariant>::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter)
|
||||||
|
mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second);
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
: QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None)
|
||||||
{
|
{
|
||||||
|
@ -43,9 +50,7 @@ void CSMWorld::CreateCommand::setType (UniversalId::Type type)
|
||||||
void CSMWorld::CreateCommand::redo()
|
void CSMWorld::CreateCommand::redo()
|
||||||
{
|
{
|
||||||
mModel.addRecord (mId, mType);
|
mModel.addRecord (mId, mType);
|
||||||
|
applyModifications();
|
||||||
for (std::map<int, QVariant>::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter)
|
|
||||||
mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::CreateCommand::undo()
|
void CSMWorld::CreateCommand::undo()
|
||||||
|
@ -147,27 +152,22 @@ void CSMWorld::ReorderRowsCommand::undo()
|
||||||
|
|
||||||
CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model,
|
CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model,
|
||||||
const std::string& idOrigin,
|
const std::string& idOrigin,
|
||||||
const std::string& IdDestination,
|
const std::string& idDestination,
|
||||||
const CSMWorld::UniversalId::Type type,
|
const CSMWorld::UniversalId::Type type,
|
||||||
QUndoCommand* parent) :
|
QUndoCommand* parent)
|
||||||
QUndoCommand (parent),
|
: CreateCommand (model, idDestination, parent), mIdOrigin (idOrigin)
|
||||||
mModel (model),
|
|
||||||
mIdOrigin (idOrigin),
|
|
||||||
mIdDestination (Misc::StringUtils::lowerCase (IdDestination)),
|
|
||||||
mType (type)
|
|
||||||
{
|
{
|
||||||
setText ( ("Clone record " + idOrigin + " to the " + IdDestination).c_str());
|
setType (type);
|
||||||
|
setText ( ("Clone record " + idOrigin + " to the " + idDestination).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::CloneCommand::redo()
|
void CSMWorld::CloneCommand::redo()
|
||||||
{
|
{
|
||||||
mModel.cloneRecord (mIdOrigin, mIdDestination, mType);
|
mModel.cloneRecord (mIdOrigin, mId, mType);
|
||||||
|
applyModifications();
|
||||||
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()
|
void CSMWorld::CloneCommand::undo()
|
||||||
{
|
{
|
||||||
mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row());
|
mModel.removeRow (mModel.getModelIndex (mId, 0).row());
|
||||||
}
|
}
|
|
@ -39,32 +39,20 @@ namespace CSMWorld
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
};
|
};
|
||||||
|
|
||||||
class CloneCommand : public QUndoCommand
|
|
||||||
{
|
|
||||||
IdTable& mModel;
|
|
||||||
std::string mIdOrigin;
|
|
||||||
std::string mIdDestination;
|
|
||||||
UniversalId::Type mType;
|
|
||||||
std::map<int, QVariant> mValues;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
CloneCommand (IdTable& model, const std::string& idOrigin,
|
|
||||||
const std::string& IdDestination,
|
|
||||||
const UniversalId::Type type,
|
|
||||||
QUndoCommand* parent = 0);
|
|
||||||
|
|
||||||
virtual void redo();
|
|
||||||
|
|
||||||
virtual void undo();
|
|
||||||
};
|
|
||||||
|
|
||||||
class CreateCommand : public QUndoCommand
|
class CreateCommand : public QUndoCommand
|
||||||
{
|
{
|
||||||
|
std::map<int, QVariant> mValues;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
IdTable& mModel;
|
IdTable& mModel;
|
||||||
std::string mId;
|
std::string mId;
|
||||||
UniversalId::Type mType;
|
UniversalId::Type mType;
|
||||||
std::map<int, QVariant> mValues;
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/// Apply modifications set via addValue.
|
||||||
|
void applyModifications();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -79,6 +67,22 @@ namespace CSMWorld
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CloneCommand : public CreateCommand
|
||||||
|
{
|
||||||
|
std::string mIdOrigin;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CloneCommand (IdTable& model, const std::string& idOrigin,
|
||||||
|
const std::string& IdDestination,
|
||||||
|
const UniversalId::Type type,
|
||||||
|
QUndoCommand* parent = 0);
|
||||||
|
|
||||||
|
virtual void redo();
|
||||||
|
|
||||||
|
virtual void undo();
|
||||||
|
};
|
||||||
|
|
||||||
class RevertCommand : public QUndoCommand
|
class RevertCommand : public QUndoCommand
|
||||||
{
|
{
|
||||||
IdTable& mModel;
|
IdTable& mModel;
|
||||||
|
|
Loading…
Reference in a new issue