From b129ff96729fdf7424a44ec6d497aaf32107ccc4 Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Tue, 3 May 2016 07:24:33 -0400 Subject: [PATCH] Editor: Add PathgridCreator to find duplicate IDs --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/world/pathgridcreator.cpp | 29 ++++++++++++++++++++++ apps/opencs/view/world/pathgridcreator.hpp | 26 +++++++++++++++++++ apps/opencs/view/world/subviews.cpp | 9 +++++-- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 apps/opencs/view/world/pathgridcreator.cpp create mode 100644 apps/opencs/view/world/pathgridcreator.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 816b8d732..e7312d0ba 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -67,7 +67,7 @@ opencs_hdrs_noqt (view/doc opencs_units (view/world table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator - cellcreator referenceablecreator startscriptcreator referencecreator scenesubview + cellcreator pathgridcreator referenceablecreator startscriptcreator referencecreator scenesubview infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable dialoguespinbox recordbuttonbar tableeditidaction scripterrortable extendedcommandconfigurator ) diff --git a/apps/opencs/view/world/pathgridcreator.cpp b/apps/opencs/view/world/pathgridcreator.cpp new file mode 100644 index 000000000..a305b1249 --- /dev/null +++ b/apps/opencs/view/world/pathgridcreator.cpp @@ -0,0 +1,29 @@ +#include "pathgridcreator.hpp" + +#include "../../model/world/data.hpp" + +CSVWorld::PathgridCreator::PathgridCreator( + CSMWorld::Data& data, + QUndoStack& undoStack, + const CSMWorld::UniversalId& id, + bool relaxedIdRules +) : GenericCreator(data, undoStack, id, relaxedIdRules) +{} + +std::string CSVWorld::PathgridCreator::getErrors() const +{ + std::string pathgridId = getId(); + + // Check user input for any errors. + std::string errors; + if (pathgridId.empty()) + { + errors = "No Pathgrid ID entered"; + } + else if (getData().getPathgrids().searchId(pathgridId) > -1) + { + errors = "Pathgrid with this ID already exists"; + } + + return errors; +} diff --git a/apps/opencs/view/world/pathgridcreator.hpp b/apps/opencs/view/world/pathgridcreator.hpp new file mode 100644 index 000000000..10f64a0a7 --- /dev/null +++ b/apps/opencs/view/world/pathgridcreator.hpp @@ -0,0 +1,26 @@ +#ifndef PATHGRIDCREATOR_HPP +#define PATHGRIDCREATOR_HPP + +#include "genericcreator.hpp" + +namespace CSVWorld +{ + /// \brief Record creator for pathgrids. + class PathgridCreator : public GenericCreator + { + Q_OBJECT + + public: + + PathgridCreator( + CSMWorld::Data& data, + QUndoStack& undoStack, + const CSMWorld::UniversalId& id, + bool relaxedIdRules = false); + + /// \return Error description for current user input. + virtual std::string getErrors() const; + }; +} + +#endif // PATHGRIDCREATOR_HPP diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index 650f344ed..69c0c01cc 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -14,6 +14,7 @@ #include "scenesubview.hpp" #include "dialoguecreator.hpp" #include "infocreator.hpp" +#include "pathgridcreator.hpp" #include "previewsubview.hpp" void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) @@ -42,7 +43,6 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) CSMWorld::UniversalId::Type_Enchantments, CSMWorld::UniversalId::Type_BodyParts, CSMWorld::UniversalId::Type_SoundGens, - CSMWorld::UniversalId::Type_Pathgrids, CSMWorld::UniversalId::Type_None // end marker }; @@ -75,6 +75,9 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) manager.add (CSMWorld::UniversalId::Type_JournalInfos, new CSVDoc::SubViewFactoryWithCreator); + manager.add (CSMWorld::UniversalId::Type_Pathgrids, + new CSVDoc::SubViewFactoryWithCreator >); + // Subviews for resources tables manager.add (CSMWorld::UniversalId::Type_Meshes, new CSVDoc::SubViewFactoryWithCreator); @@ -125,7 +128,6 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) CSMWorld::UniversalId::Type_Enchantment, CSMWorld::UniversalId::Type_BodyPart, CSMWorld::UniversalId::Type_SoundGen, - CSMWorld::UniversalId::Type_Pathgrid, CSMWorld::UniversalId::Type_None // end marker }; @@ -168,6 +170,9 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) manager.add (CSMWorld::UniversalId::Type_Journal, new CSVDoc::SubViewFactoryWithCreator (false)); + manager.add (CSMWorld::UniversalId::Type_Pathgrid, + new CSVDoc::SubViewFactoryWithCreator > (false)); + manager.add (CSMWorld::UniversalId::Type_DebugProfile, new CSVDoc::SubViewFactoryWithCreator > (false));