From 3add4bdf358cfe10419cf988e10feb52afd56b9f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 18 Sep 2014 13:41:29 +0200 Subject: [PATCH] rewrote refnum handling code (fixes broken reference creation, but not reference cloning yet) --- apps/opencs/view/world/referencecreator.cpp | 36 ++++++++++++++------- apps/opencs/view/world/referencecreator.hpp | 3 ++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 5e680b97d..561ac87da 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -16,11 +16,19 @@ std::string CSVWorld::ReferenceCreator::getId() const void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const { - int index = + // Set cellID + int cellIdColumn = dynamic_cast (*getData().getTableModel (getCollectionId())). findColumnIndex (CSMWorld::Columns::ColumnId_Cell); - command.addValue (index, mCell->text()); + command.addValue (cellIdColumn, mCell->text()); + + // Set RefNum + int refNumColumn = dynamic_cast ( + *getData().getTableModel (CSMWorld::UniversalId::Type_References)). + findColumnIndex (CSMWorld::Columns::ColumnId_RefNum); + + command.addValue (refNumColumn, getRefNumCount()); } void CSVWorld::ReferenceCreator::pushCommand (std::auto_ptr command, @@ -38,26 +46,30 @@ void CSVWorld::ReferenceCreator::pushCommand (std::auto_ptr comman int count = cellTable.data (countIndex).toInt(); - // command for setting the refnum in the newly created reference - CSMWorld::IdTable& referenceTable = dynamic_cast ( - *getData().getTableModel (CSMWorld::UniversalId::Type_References)); - - int refNumColumn = referenceTable.findColumnIndex (CSMWorld::Columns::ColumnId_RefNum); - - std::auto_ptr setRefNum (new CSMWorld::ModifyCommand - (referenceTable, referenceTable.getModelIndex (id, refNumColumn), count)); - // command for incrementing counter std::auto_ptr increment (new CSMWorld::ModifyCommand (cellTable, countIndex, count+1)); getUndoStack().beginMacro (command->text()); GenericCreator::pushCommand (command, id); - getUndoStack().push (setRefNum.release()); getUndoStack().push (increment.release()); getUndoStack().endMacro(); } +int CSVWorld::ReferenceCreator::getRefNumCount() const +{ + std::string cellId = mCell->text().toUtf8().constData(); + + CSMWorld::IdTable& cellTable = dynamic_cast ( + *getData().getTableModel (CSMWorld::UniversalId::Type_Cells)); + + int countColumn = cellTable.findColumnIndex (CSMWorld::Columns::ColumnId_RefNumCounter); + + QModelIndex countIndex = cellTable.getModelIndex (cellId, countColumn); + + return cellTable.data (countIndex).toInt(); +} + CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id) : GenericCreator (data, undoStack, id) diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index a0e98a9a4..c463469e4 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -23,6 +23,9 @@ namespace CSVWorld virtual void pushCommand (std::auto_ptr command, const std::string& id); + /// Return next available RefNum for the cell the creator is currently operating on + int getRefNumCount() const; + public: ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,