diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 097e83f7c..f8c72a390 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -68,9 +68,6 @@ void CSMWorld::ModifyCommand::undo() void CSMWorld::CreateCommand::applyModifications() { - for (std::map::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter) - mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second); - if (!mNestedValues.empty()) { CSMWorld::IdTree *tree = dynamic_cast(&mModel); @@ -114,7 +111,7 @@ void CSMWorld::CreateCommand::setType (UniversalId::Type type) void CSMWorld::CreateCommand::redo() { - mModel.addRecord (mId, mType); + mModel.addRecordWithData (mId, mValues, mType); applyModifications(); } diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index bd1179cea..4d8a0842f 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -149,6 +149,21 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type endInsertRows(); } +void CSMWorld::IdTable::addRecordWithData (const std::string& id, + const std::map& data, UniversalId::Type type) +{ + int index = mIdCollection->getAppendIndex (id, type); + + beginInsertRows (QModelIndex(), index, index); + + mIdCollection->appendBlankRecord (id, type); + + for (std::map::const_iterator iter (data.begin()); iter!=data.end(); ++iter) + mIdCollection->setData (index, iter->first, iter->second); + + endInsertRows(); +} + void CSMWorld::IdTable::cloneRecord(const std::string& origin, const std::string& destination, CSMWorld::UniversalId::Type type) diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index 9ecba0214..8c2f8a46d 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -53,6 +53,10 @@ 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 addRecordWithData (const std::string& id, const std::map& data, + 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);