From d73f4cbd7bf3829ee277caaadcc0bd609f32fa4b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 24 Jun 2014 19:19:40 +0200 Subject: [PATCH] added add nested command --- apps/opencs/model/world/commands.cpp | 24 ++++++++++++++++++++++++ apps/opencs/model/world/commands.hpp | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 019a3d3976..42a5a7f7ea 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -211,3 +211,27 @@ void CSMWorld::DeleteNestedCommand::undo() { //TODO } + +CSMWorld::AddNestedCommand::AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent) + : mModel(model), + mId(id), + mNewRow(nestedRow), + mParentColumn(parentColumn), + QUndoCommand(parent) +{ + setText (("Added nested row in " + mId).c_str()); +} + +void CSMWorld::AddNestedCommand::redo() +{ + const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn); + + mModel.addNestedRow (parentIndex, mNewRow); +} + +void CSMWorld::AddNestedCommand::undo() +{ + const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn); + + mModel.removeRows(mNewRow, 1, parentIndex); +} diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 192b161ef0..9cfc0b293b 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -157,6 +157,25 @@ namespace CSMWorld virtual void undo(); }; + + class AddNestedCommand : public QUndoCommand + { + IdTable& mModel; + + std::string mId; + + int mNewRow; + + int mParentColumn; + + public: + + AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent); + + virtual void redo(); + + virtual void undo(); + }; } #endif