From 8d4441bb5ef95bba7ed2cc7d12a7411e490107a5 Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Sun, 26 Mar 2017 09:05:05 -0400 Subject: [PATCH 1/3] Editor: document subclasses without ID checks - Removes ID validation for PathgridCreator. - Adds comments explaining why ID validation isn't used in some cases. --- apps/opencs/view/world/infocreator.cpp | 2 ++ apps/opencs/view/world/pathgridcreator.cpp | 10 +++------- apps/opencs/view/world/pathgridcreator.hpp | 3 +-- apps/opencs/view/world/referencecreator.cpp | 2 ++ apps/opencs/view/world/startscriptcreator.cpp | 3 ++- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/opencs/view/world/infocreator.cpp b/apps/opencs/view/world/infocreator.cpp index 243b7d879..d3bc29ab7 100644 --- a/apps/opencs/view/world/infocreator.cpp +++ b/apps/opencs/view/world/infocreator.cpp @@ -48,6 +48,8 @@ CSVWorld::InfoCreator::InfoCreator (CSMWorld::Data& data, QUndoStack& undoStack, QLabel *label = new QLabel ("Topic", this); insertBeforeButtons (label, false); + // Add topic/journal ID input with auto-completion. + // Only existing topic/journal IDs are accepted so no ID validation is performed. CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Topic; if (getCollectionId().getType() == CSMWorld::UniversalId::Type_JournalInfos) { diff --git a/apps/opencs/view/world/pathgridcreator.cpp b/apps/opencs/view/world/pathgridcreator.cpp index 7d2f46b91..26523f0c3 100644 --- a/apps/opencs/view/world/pathgridcreator.cpp +++ b/apps/opencs/view/world/pathgridcreator.cpp @@ -10,7 +10,6 @@ #include "../../model/world/idtable.hpp" #include "../widget/droplineedit.hpp" -#include "idvalidator.hpp" std::string CSVWorld::PathgridCreator::getId() const { @@ -28,9 +27,8 @@ CSVWorld::PathgridCreator::PathgridCreator( CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, - CSMWorld::IdCompletionManager& completionManager, - bool relaxedIdRules -) : GenericCreator(data, undoStack, id, relaxedIdRules) + CSMWorld::IdCompletionManager& completionManager +) : GenericCreator(data, undoStack, id) { setManualEditing(false); @@ -38,10 +36,10 @@ CSVWorld::PathgridCreator::PathgridCreator( insertBeforeButtons(label, false); // Add cell ID input with auto-completion. + // Only existing cell IDs are accepted so no ID validation is performed. CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Cell; mCell = new CSVWidget::DropLineEdit(displayType, this); mCell->setCompleter(completionManager.getCompleter(displayType).get()); - mCell->setValidator(new IdValidator(relaxedIdRules, this)); insertBeforeButtons(mCell, true); connect(mCell, SIGNAL (textChanged(const QString&)), this, SLOT (cellChanged())); @@ -65,8 +63,6 @@ std::string CSVWorld::PathgridCreator::getErrors() const std::string cellId = getId(); // Check user input for any errors. - // The last two checks, cell with existing pathgrid and non-existent cell, - // shouldn't be needed but we absolutely want to make sure they never happen. std::string errors; if (cellId.empty()) { diff --git a/apps/opencs/view/world/pathgridcreator.hpp b/apps/opencs/view/world/pathgridcreator.hpp index c2ae20fc0..7e82155f6 100644 --- a/apps/opencs/view/world/pathgridcreator.hpp +++ b/apps/opencs/view/world/pathgridcreator.hpp @@ -44,8 +44,7 @@ namespace CSVWorld CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, - CSMWorld::IdCompletionManager& completionManager, - bool relaxedIdRules = false); + CSMWorld::IdCompletionManager& completionManager); /// \brief Set cell ID input widget to ID of record to be cloned. /// \param originId Cell ID to be cloned. diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index cc7ae545a..1363f489a 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -35,6 +35,8 @@ CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& QLabel *label = new QLabel ("Cell", this); insertBeforeButtons (label, false); + // Add cell ID input with auto-completion. + // Only existing cell IDs are accepted so no ID validation is performed. mCell = new CSVWidget::DropLineEdit(CSMWorld::ColumnBase::Display_Cell, this); mCell->setCompleter(completionManager.getCompleter(CSMWorld::ColumnBase::Display_Cell).get()); insertBeforeButtons (mCell, true); diff --git a/apps/opencs/view/world/startscriptcreator.cpp b/apps/opencs/view/world/startscriptcreator.cpp index 891199027..00c485224 100644 --- a/apps/opencs/view/world/startscriptcreator.cpp +++ b/apps/opencs/view/world/startscriptcreator.cpp @@ -29,7 +29,7 @@ CSVWorld::StartScriptCreator::StartScriptCreator( QUndoStack &undoStack, const CSMWorld::UniversalId &id, CSMWorld::IdCompletionManager& completionManager -) : GenericCreator(data, undoStack, id, true) +) : GenericCreator(data, undoStack, id) { setManualEditing(false); @@ -38,6 +38,7 @@ CSVWorld::StartScriptCreator::StartScriptCreator( insertBeforeButtons(label, false); // Add script ID input with auto-completion. + // Only existing script IDs are accepted so no ID validation is performed. CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Script; mScript = new CSVWidget::DropLineEdit(displayType, this); mScript->setCompleter(completionManager.getCompleter(displayType).get()); From 77bf1efc1ad9293d1dd2ce6a0dc1c453fb3eaa98 Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Sun, 26 Mar 2017 09:14:32 -0400 Subject: [PATCH 2/3] Editor: Fix labels for creator user inputs --- apps/opencs/view/world/infocreator.cpp | 14 +++++++++----- apps/opencs/view/world/pathgridcreator.cpp | 2 +- apps/opencs/view/world/startscriptcreator.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/world/infocreator.cpp b/apps/opencs/view/world/infocreator.cpp index d3bc29ab7..f68c69094 100644 --- a/apps/opencs/view/world/infocreator.cpp +++ b/apps/opencs/view/world/infocreator.cpp @@ -45,16 +45,20 @@ CSVWorld::InfoCreator::InfoCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, CSMWorld::IdCompletionManager& completionManager) : GenericCreator (data, undoStack, id) { - QLabel *label = new QLabel ("Topic", this); - insertBeforeButtons (label, false); - - // Add topic/journal ID input with auto-completion. - // Only existing topic/journal IDs are accepted so no ID validation is performed. + // Determine if we're dealing with topics or journals. CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Topic; + QString labelText = "Topic"; if (getCollectionId().getType() == CSMWorld::UniversalId::Type_JournalInfos) { displayType = CSMWorld::ColumnBase::Display_Journal; + labelText = "Journal"; } + + QLabel *label = new QLabel (labelText, this); + insertBeforeButtons (label, false); + + // Add topic/journal ID input with auto-completion. + // Only existing topic/journal IDs are accepted so no ID validation is performed. mTopic = new CSVWidget::DropLineEdit(displayType, this); mTopic->setCompleter(completionManager.getCompleter(displayType).get()); insertBeforeButtons (mTopic, true); diff --git a/apps/opencs/view/world/pathgridcreator.cpp b/apps/opencs/view/world/pathgridcreator.cpp index 26523f0c3..95628a5d9 100644 --- a/apps/opencs/view/world/pathgridcreator.cpp +++ b/apps/opencs/view/world/pathgridcreator.cpp @@ -32,7 +32,7 @@ CSVWorld::PathgridCreator::PathgridCreator( { setManualEditing(false); - QLabel *label = new QLabel("Cell ID", this); + QLabel *label = new QLabel("Cell", this); insertBeforeButtons(label, false); // Add cell ID input with auto-completion. diff --git a/apps/opencs/view/world/startscriptcreator.cpp b/apps/opencs/view/world/startscriptcreator.cpp index 00c485224..0eb6bae40 100644 --- a/apps/opencs/view/world/startscriptcreator.cpp +++ b/apps/opencs/view/world/startscriptcreator.cpp @@ -34,7 +34,7 @@ CSVWorld::StartScriptCreator::StartScriptCreator( setManualEditing(false); // Add script ID input label. - QLabel *label = new QLabel("Script ID", this); + QLabel *label = new QLabel("Script", this); insertBeforeButtons(label, false); // Add script ID input with auto-completion. From 343f2cb81db77de82f27ee1ac93923d1d58c7066 Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Thu, 30 Mar 2017 08:20:43 -0400 Subject: [PATCH 3/3] Editor: add creator for body parts Added creator subclass for body parts to allow adding first person parts. IDs for first person body parts are expected to end with ".1st". --- apps/opencs/CMakeLists.txt | 1 + apps/opencs/view/world/bodypartcreator.cpp | 54 ++++++++++++++++++++++ apps/opencs/view/world/bodypartcreator.hpp | 47 +++++++++++++++++++ apps/opencs/view/world/subviews.cpp | 9 +++- 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 apps/opencs/view/world/bodypartcreator.cpp create mode 100644 apps/opencs/view/world/bodypartcreator.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index e7e19be94..8a3d3c1c8 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -70,6 +70,7 @@ opencs_units (view/world cellcreator pathgridcreator referenceablecreator startscriptcreator referencecreator scenesubview infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable dialoguespinbox recordbuttonbar tableeditidaction scripterrortable extendedcommandconfigurator + bodypartcreator ) opencs_units_noqt (view/world diff --git a/apps/opencs/view/world/bodypartcreator.cpp b/apps/opencs/view/world/bodypartcreator.cpp new file mode 100644 index 000000000..a9fc3e063 --- /dev/null +++ b/apps/opencs/view/world/bodypartcreator.cpp @@ -0,0 +1,54 @@ +#include "bodypartcreator.hpp" + +#include + +#include "../../model/world/data.hpp" +#include "../../model/world/universalid.hpp" + +std::string CSVWorld::BodyPartCreator::getId() const +{ + std::string id = CSVWorld::GenericCreator::getId(); + + if (mFirstPerson->isChecked()) + { + id += ".1st"; + } + + return id; +} + +CSVWorld::BodyPartCreator::BodyPartCreator( + CSMWorld::Data& data, + QUndoStack& undoStack, + const CSMWorld::UniversalId& id +) : GenericCreator(data, undoStack, id) +{ + mFirstPerson = new QCheckBox("First Person", this); + insertBeforeButtons(mFirstPerson, false); + + connect(mFirstPerson, SIGNAL(clicked(bool)), this, SLOT(checkboxClicked())); +} + +std::string CSVWorld::BodyPartCreator::getErrors() const +{ + std::string errors; + + std::string id = getId(); + if (getData().hasId(id)) + { + errors = "ID is already in use"; + } + + return errors; +} + +void CSVWorld::BodyPartCreator::reset() +{ + CSVWorld::GenericCreator::reset(); + mFirstPerson->setChecked(false); +} + +void CSVWorld::BodyPartCreator::checkboxClicked() +{ + update(); +} diff --git a/apps/opencs/view/world/bodypartcreator.hpp b/apps/opencs/view/world/bodypartcreator.hpp new file mode 100644 index 000000000..3c27136dd --- /dev/null +++ b/apps/opencs/view/world/bodypartcreator.hpp @@ -0,0 +1,47 @@ +#ifndef BODYPARTCREATOR_HPP +#define BODYPARTCREATOR_HPP + +class QCheckBox; + +#include "genericcreator.hpp" + +namespace CSMWorld +{ + class Data; + class UniversalId; +} + +namespace CSVWorld +{ + /// \brief Record creator for body parts. + class BodyPartCreator : public GenericCreator + { + Q_OBJECT + + QCheckBox *mFirstPerson; + + private: + + /// \return ID entered by user. + virtual std::string getId() const; + + public: + + BodyPartCreator( + CSMWorld::Data& data, + QUndoStack& undoStack, + const CSMWorld::UniversalId& id); + + /// \return Error description for current user input. + virtual std::string getErrors() const; + + /// \brief Clear ID and checkbox input widgets. + virtual void reset(); + + private slots: + + void checkboxClicked(); + }; +} + +#endif // BODYPARTCREATOR_HPP diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index 93e105106..7c27bdf7a 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -17,6 +17,7 @@ #include "infocreator.hpp" #include "pathgridcreator.hpp" #include "previewsubview.hpp" +#include "bodypartcreator.hpp" void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) { @@ -41,7 +42,6 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) CSMWorld::UniversalId::Type_Birthsigns, CSMWorld::UniversalId::Type_Spells, CSMWorld::UniversalId::Type_Enchantments, - CSMWorld::UniversalId::Type_BodyParts, CSMWorld::UniversalId::Type_SoundGens, CSMWorld::UniversalId::Type_None // end marker @@ -51,6 +51,9 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) manager.add (sTableTypes[i], new CSVDoc::SubViewFactoryWithCreator >); + manager.add (CSMWorld::UniversalId::Type_BodyParts, + new CSVDoc::SubViewFactoryWithCreator >); + manager.add (CSMWorld::UniversalId::Type_StartScripts, new CSVDoc::SubViewFactoryWithCreator); @@ -129,7 +132,6 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) CSMWorld::UniversalId::Type_Sound, CSMWorld::UniversalId::Type_Faction, CSMWorld::UniversalId::Type_Enchantment, - CSMWorld::UniversalId::Type_BodyPart, CSMWorld::UniversalId::Type_SoundGen, CSMWorld::UniversalId::Type_None // end marker @@ -140,6 +142,9 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) new CSVDoc::SubViewFactoryWithCreator > (false)); + manager.add (CSMWorld::UniversalId::Type_BodyPart, + new CSVDoc::SubViewFactoryWithCreator > (false)); + manager.add (CSMWorld::UniversalId::Type_StartScript, new CSVDoc::SubViewFactoryWithCreator(false));