diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index b60ffeb29c..019a3d3976 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,4 +1,3 @@ - #include "commands.hpp" #include @@ -171,4 +170,44 @@ void CSMWorld::CloneCommand::redo() void CSMWorld::CloneCommand::undo() { mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); -} \ No newline at end of file +} + +CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent) + : mId(id), + mModel(model), + mParentColumn(parentColumn), + QUndoCommand(parent), + mNestedRow(nestedRow) +{ + setText (("Delete nested row in " + mId).c_str()); + + const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn); + + const int columnsCount = mModel.columnCount(parentIndex); + + for (int i = 0; i < columnsCount; ++i) + { + const QModelIndex& childIndex = mModel.index(nestedRow, i, parentIndex); + + QVariant data = childIndex.data(); + if (!data.isValid()) + { + data = childIndex.data(Qt::DisplayRole); + } + + mOld.push_back(data); + } +} + +void CSMWorld::DeleteNestedCommand::redo() +{ + const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn); + + mModel.removeRows (mNestedRow, 1, parentIndex); +} + + +void CSMWorld::DeleteNestedCommand::undo() +{ + //TODO +} diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index ec6350658f..192b161ef0 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "universalid.hpp" @@ -49,7 +50,7 @@ namespace CSMWorld public: - CloneCommand (IdTable& model, const std::string& idOrigin, + CloneCommand (IdTable& model, const std::string& idOrigin, const std::string& IdDestination, const UniversalId::Type type, QUndoCommand* parent = 0); @@ -135,6 +136,27 @@ namespace CSMWorld virtual void undo(); }; + + class DeleteNestedCommand : public QUndoCommand + { + IdTable& mModel; + + std::string mId; + + std::vector mOld; + + int mParentColumn; + + int mNestedRow; + + public: + + DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent); + + virtual void redo(); + + virtual void undo(); + }; } -#endif \ No newline at end of file +#endif