From 0ea2bb7c4cc835f969fdfe92bba153fd9f3bebdc Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 19 Jan 2014 16:49:39 +0100 Subject: [PATCH] Working on commands --- apps/opencs/model/world/commands.cpp | 21 +++++++++++++++++++++ apps/opencs/model/world/commands.hpp | 20 ++++++++++++++++++++ apps/opencs/model/world/idtable.cpp | 8 ++++++++ apps/opencs/model/world/idtable.hpp | 2 ++ apps/opencs/view/world/genericcreator.cpp | 2 ++ 5 files changed, 53 insertions(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 21feb14be..281afb15f 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -25,6 +25,27 @@ void CSMWorld::ModifyCommand::undo() mModel.setData (mIndex, mOld); } +CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + CSMWorld::UniversalId::Type type, + QUndoCommand* parent) : + QUndoCommand(parent), + mModel(model), + mIdOrigin(idOrigin), + mIdDestination(IdDestination), + mType(type) +{ + setText (("Clone record " + idOrigin + " to the " + IdDestination).c_str()); +} + + +void CSMWorld::CloneCommand::redo() +{ + mModel.cloneRecord(mIdOrigin, mIdDestination, mType); +} + + CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent) : QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) { diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index f0480a369..1af4bd919 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -39,6 +39,26 @@ namespace CSMWorld virtual void undo(); }; + class CloneCommand : public QUndoCommand + { + IdTable& mModel; + std::string mIdOrigin; + std::string mIdDestination; + UniversalId::Type mType; + std::map mValues; + + public: + + CloneCommand (IdTable& model, const std::string& idOrigin, + const std::string& IdDestination, + UniversalId::Type type, + QUndoCommand* parent = 0); + + virtual void redo(); + +// virtual void undo(); + }; + class CreateCommand : public QUndoCommand { IdTable& mModel; diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 809d64339..b90bf1a9b 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -124,6 +124,14 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type endInsertRows(); } +void CSMWorld::IdTable::cloneRecord(const std::string& origin, + const std::string& destination, + CSMWorld::UniversalId::Type type) +{ + +} + + QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column) const { return index (mIdCollection->getIndex (id), column); diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index e4ae58fd0..dfbc04134 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -63,6 +63,8 @@ namespace CSMWorld void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types + void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None); + QModelIndex getModelIndex (const std::string& id, int column) const; void setRecord (const std::string& id, const RecordBase& record); diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index b89c2dccf..f21a62d97 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -125,6 +125,8 @@ void CSVWorld::GenericCreator::create() if (mCloneMode) { std::string id = getId(); + std::auto_ptr command (new CSMWorld::CloneCommand ( + dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType)); } else { std::string id = getId();