From 7196ad74557d8c608a9401273a51220fd786f8db Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sun, 10 Jan 2021 21:23:52 +0200 Subject: [PATCH] Implement an override-value when cloning, use when cloning info records --- apps/opencs/model/world/collection.hpp | 8 -------- apps/opencs/model/world/commands.cpp | 9 +++++++++ apps/opencs/model/world/commands.hpp | 3 +++ apps/opencs/view/world/infocreator.cpp | 4 ++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 16ebb3a61..451ef9d0e 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -15,7 +15,6 @@ #include "columnbase.hpp" #include "collectionbase.hpp" -#include "info.hpp" #include "land.hpp" #include "landtexture.hpp" #include "ref.hpp" @@ -265,13 +264,6 @@ namespace CSMWorld CSMWorld::CellRef* ptr = (CSMWorld::CellRef*) ©.mModified; ptr->mRefNum.mIndex = 0; } - if (type == UniversalId::Type_TopicInfo || type == UniversalId::Type_JournalInfo) - { - CSMWorld::Info* ptr = (CSMWorld::Info*) ©.mModified; - std::vector splitStringContainer; - Misc::StringUtils::split(destination, splitStringContainer, "#"); - if (!splitStringContainer.empty()) ptr->mTopicId = splitStringContainer[0]; - } int index = getAppendIndex(destination, type); insertRecord(copy, getAppendIndex(destination, type)); diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index e33be1139..34485a46d 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -397,6 +397,10 @@ void CSMWorld::CloneCommand::redo() { mModel.cloneRecord (mIdOrigin, mId, mType); applyModifications(); + for (auto& value : mOverrideValues) + { + mModel.setData(mModel.getModelIndex (mId, value.first), value.second); + } } void CSMWorld::CloneCommand::undo() @@ -404,6 +408,11 @@ void CSMWorld::CloneCommand::undo() mModel.removeRow (mModel.getModelIndex (mId, 0).row()); } +void CSMWorld::CloneCommand::setOverrideValue(int column, QVariant value) +{ + mOverrideValues.emplace_back(std::make_pair(column, value)); +} + CSMWorld::CreatePathgridCommand::CreatePathgridCommand(IdTable& model, const std::string& id, QUndoCommand *parent) : CreateCommand(model, id, parent) { diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 5776cae36..33608304f 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -183,6 +183,7 @@ namespace CSMWorld class CloneCommand : public CreateCommand { std::string mIdOrigin; + std::vector> mOverrideValues; public: @@ -194,6 +195,8 @@ namespace CSMWorld void redo() override; void undo() override; + + void setOverrideValue(int column, QVariant value); }; class RevertCommand : public QUndoCommand diff --git a/apps/opencs/view/world/infocreator.cpp b/apps/opencs/view/world/infocreator.cpp index 2f1615c87..505de753c 100644 --- a/apps/opencs/view/world/infocreator.cpp +++ b/apps/opencs/view/world/infocreator.cpp @@ -40,10 +40,14 @@ void CSVWorld::InfoCreator::configureCreateCommand (CSMWorld::CreateCommand& com command.addValue (table.findColumnIndex(CSMWorld::Columns::ColumnId_Rank), -1); command.addValue (table.findColumnIndex(CSMWorld::Columns::ColumnId_Gender), -1); command.addValue (table.findColumnIndex(CSMWorld::Columns::ColumnId_PcRank), -1); + CSMWorld::CloneCommand* cloneCommand = dynamic_cast (&command); + if (cloneCommand) cloneCommand->setOverrideValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Topic), mTopic->text()); } else { command.addValue (table.findColumnIndex(CSMWorld::Columns::ColumnId_Journal), mTopic->text()); + CSMWorld::CloneCommand* cloneCommand = dynamic_cast (&command); + if (cloneCommand) cloneCommand->setOverrideValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Journal), mTopic->text()); } }