mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-24 13:39:43 +00:00
Reduced code duplication through new common base class
This commit is contained in:
parent
87eed066c2
commit
3dd2ca15da
2 changed files with 29 additions and 20 deletions
|
@ -179,7 +179,7 @@ CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTable& model, const std::s
|
||||||
mParentColumn(parentColumn),
|
mParentColumn(parentColumn),
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
mNestedRow(nestedRow),
|
mNestedRow(nestedRow),
|
||||||
mOld (model.nestedTable(model.getModelIndex(id, parentColumn)))
|
NestedTableStoring(model, id, parentColumn)
|
||||||
{
|
{
|
||||||
setText (("Delete nested row in " + mId).c_str());
|
setText (("Delete nested row in " + mId).c_str());
|
||||||
}
|
}
|
||||||
|
@ -196,12 +196,7 @@ void CSMWorld::DeleteNestedCommand::undo()
|
||||||
{
|
{
|
||||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||||
|
|
||||||
mModel.setNestedTable(parentIndex, *mOld);
|
mModel.setNestedTable(parentIndex, getOld());
|
||||||
}
|
|
||||||
|
|
||||||
CSMWorld::DeleteNestedCommand::~DeleteNestedCommand()
|
|
||||||
{
|
|
||||||
delete mOld;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::AddNestedCommand::AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent)
|
CSMWorld::AddNestedCommand::AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent)
|
||||||
|
@ -210,7 +205,7 @@ CSMWorld::AddNestedCommand::AddNestedCommand(IdTable& model, const std::string&
|
||||||
mNewRow(nestedRow),
|
mNewRow(nestedRow),
|
||||||
mParentColumn(parentColumn),
|
mParentColumn(parentColumn),
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
mOld (model.nestedTable(model.getModelIndex(id, parentColumn)))
|
NestedTableStoring(model, id, parentColumn)
|
||||||
{
|
{
|
||||||
setText (("Added nested row in " + mId).c_str());
|
setText (("Added nested row in " + mId).c_str());
|
||||||
}
|
}
|
||||||
|
@ -226,10 +221,18 @@ void CSMWorld::AddNestedCommand::undo()
|
||||||
{
|
{
|
||||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||||
|
|
||||||
mModel.setNestedTable(parentIndex, *mOld);
|
mModel.setNestedTable(parentIndex, getOld());
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::AddNestedCommand::~AddNestedCommand()
|
CSMWorld::NestedTableStoring::NestedTableStoring(const IdTable& model, const std::string& id, int parentColumn)
|
||||||
|
: mOld(model.nestedTable(model.getModelIndex(id, parentColumn))) {}
|
||||||
|
|
||||||
|
CSMWorld::NestedTableStoring::~NestedTableStoring()
|
||||||
{
|
{
|
||||||
delete mOld;
|
delete mOld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CSMWorld::NestedTableWrapperBase& CSMWorld::NestedTableStoring::getOld() const
|
||||||
|
{
|
||||||
|
return *mOld;
|
||||||
|
}
|
||||||
|
|
|
@ -139,14 +139,26 @@ namespace CSMWorld
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeleteNestedCommand : public QUndoCommand
|
class NestedTableStoring
|
||||||
|
{
|
||||||
|
NestedTableWrapperBase* mOld;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NestedTableStoring(const IdTable& model, const std::string& id, int parentColumn);
|
||||||
|
|
||||||
|
~NestedTableStoring();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
const NestedTableWrapperBase& getOld() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeleteNestedCommand : public QUndoCommand, private NestedTableStoring
|
||||||
{
|
{
|
||||||
IdTable& mModel;
|
IdTable& mModel;
|
||||||
|
|
||||||
std::string mId;
|
std::string mId;
|
||||||
|
|
||||||
NestedTableWrapperBase* mOld;
|
|
||||||
|
|
||||||
int mParentColumn;
|
int mParentColumn;
|
||||||
|
|
||||||
int mNestedRow;
|
int mNestedRow;
|
||||||
|
@ -155,21 +167,17 @@ namespace CSMWorld
|
||||||
|
|
||||||
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
||||||
|
|
||||||
~DeleteNestedCommand();
|
|
||||||
|
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
};
|
};
|
||||||
|
|
||||||
class AddNestedCommand : public QUndoCommand
|
class AddNestedCommand : public QUndoCommand, private NestedTableStoring
|
||||||
{
|
{
|
||||||
IdTable& mModel;
|
IdTable& mModel;
|
||||||
|
|
||||||
std::string mId;
|
std::string mId;
|
||||||
|
|
||||||
NestedTableWrapperBase* mOld;
|
|
||||||
|
|
||||||
int mNewRow;
|
int mNewRow;
|
||||||
|
|
||||||
int mParentColumn;
|
int mParentColumn;
|
||||||
|
@ -178,8 +186,6 @@ namespace CSMWorld
|
||||||
|
|
||||||
AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
||||||
|
|
||||||
~AddNestedCommand();
|
|
||||||
|
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
|
Loading…
Reference in a new issue