forked from mirror/openmw-tes3mp
moved ref num assingment from instance creation to save procedure
This commit is contained in:
parent
8052225460
commit
1774f6d9bf
8 changed files with 34 additions and 77 deletions
|
@ -272,6 +272,22 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
|
||||||
CSMWorld::Cell cellRecord = cell.get();
|
CSMWorld::Cell cellRecord = cell.get();
|
||||||
bool interior = cellRecord.mId.substr (0, 1)!="#";
|
bool interior = cellRecord.mId.substr (0, 1)!="#";
|
||||||
|
|
||||||
|
// count new references and adjust RefNumCount accordingsly
|
||||||
|
int newRefNum = cellRecord.mRefNumCounter;
|
||||||
|
|
||||||
|
if (references!=mState.getSubRecords().end())
|
||||||
|
{
|
||||||
|
for (std::deque<int>::const_iterator iter (references->second.begin());
|
||||||
|
iter!=references->second.end(); ++iter)
|
||||||
|
{
|
||||||
|
const CSMWorld::Record<CSMWorld::CellRef>& ref =
|
||||||
|
mDocument.getData().getReferences().getRecord (*iter);
|
||||||
|
|
||||||
|
if (ref.get().mNew)
|
||||||
|
++cellRecord.mRefNumCounter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// write cell data
|
// write cell data
|
||||||
writer.startRecord (cellRecord.sRecordId);
|
writer.startRecord (cellRecord.sRecordId);
|
||||||
|
|
||||||
|
@ -309,11 +325,16 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
|
||||||
stream << "#" << index.first << " " << index.second;
|
stream << "#" << index.first << " " << index.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An empty mOriginalCell is meant to indicate that it is the same as
|
if (refRecord.mNew)
|
||||||
// the current cell. It is possible that a moved ref is moved again.
|
{
|
||||||
if ((refRecord.mOriginalCell.empty() ? refRecord.mCell : refRecord.mOriginalCell)
|
refRecord.mRefNum.mIndex = newRefNum++;
|
||||||
|
}
|
||||||
|
else if ((refRecord.mOriginalCell.empty() ? refRecord.mCell : refRecord.mOriginalCell)
|
||||||
!= stream.str() && !interior)
|
!= stream.str() && !interior)
|
||||||
{
|
{
|
||||||
|
// An empty mOriginalCell is meant to indicate that it is the same as
|
||||||
|
// the current cell. It is possible that a moved ref is moved again.
|
||||||
|
|
||||||
ESM::MovedCellRef moved;
|
ESM::MovedCellRef moved;
|
||||||
moved.mRefNum = refRecord.mRefNum;
|
moved.mRefNum = refRecord.mRefNum;
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ void CSMTools::MergeReferencesStage::perform (int stage, CSMDoc::Messages& messa
|
||||||
|
|
||||||
ref.mRefNum.mIndex = mIndex[Misc::StringUtils::lowerCase (ref.mCell)]++;
|
ref.mRefNum.mIndex = mIndex[Misc::StringUtils::lowerCase (ref.mCell)]++;
|
||||||
ref.mRefNum.mContentFile = 0;
|
ref.mRefNum.mContentFile = 0;
|
||||||
|
ref.mNew = false;
|
||||||
|
|
||||||
CSMWorld::Record<CSMWorld::CellRef> newRecord (
|
CSMWorld::Record<CSMWorld::CellRef> newRecord (
|
||||||
CSMWorld::RecordBase::State_ModifiedOnly, 0, &ref);
|
CSMWorld::RecordBase::State_ModifiedOnly, 0, &ref);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "cellcoordinates.hpp"
|
#include "cellcoordinates.hpp"
|
||||||
|
|
||||||
CSMWorld::CellRef::CellRef()
|
CSMWorld::CellRef::CellRef() : mNew (true)
|
||||||
{
|
{
|
||||||
mRefNum.mIndex = 0;
|
mRefNum.mIndex = 0;
|
||||||
mRefNum.mContentFile = 0;
|
mRefNum.mContentFile = 0;
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace CSMWorld
|
||||||
std::string mId;
|
std::string mId;
|
||||||
std::string mCell;
|
std::string mCell;
|
||||||
std::string mOriginalCell;
|
std::string mOriginalCell;
|
||||||
|
bool mNew; // new reference, not counted yet, ref num not assigned yet
|
||||||
|
|
||||||
CellRef();
|
CellRef();
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
||||||
Cell& cell2 = base ? cell.mBase : cell.mModified;
|
Cell& cell2 = base ? cell.mBase : cell.mModified;
|
||||||
|
|
||||||
CellRef ref;
|
CellRef ref;
|
||||||
|
ref.mNew = false;
|
||||||
ESM::MovedCellRef mref;
|
ESM::MovedCellRef mref;
|
||||||
bool isDeleted = false;
|
bool isDeleted = false;
|
||||||
|
|
||||||
|
|
|
@ -421,24 +421,7 @@ void CSVRender::InstanceMode::dropEvent (QDropEvent* event)
|
||||||
CSMWorld::Columns::ColumnId_ReferenceableId),
|
CSMWorld::Columns::ColumnId_ReferenceableId),
|
||||||
QString::fromUtf8 (iter->getId().c_str()));
|
QString::fromUtf8 (iter->getId().c_str()));
|
||||||
|
|
||||||
std::auto_ptr<CSMWorld::ModifyCommand> incrementCommand;
|
document.getUndoStack().push (createCommand.release());
|
||||||
|
|
||||||
if (!noCell)
|
|
||||||
{
|
|
||||||
// increase reference count in cell
|
|
||||||
QModelIndex countIndex = cellTable.getModelIndex (cellId,
|
|
||||||
cellTable.findColumnIndex (CSMWorld::Columns::ColumnId_RefNumCounter));
|
|
||||||
|
|
||||||
int count = cellTable.data (countIndex).toInt();
|
|
||||||
|
|
||||||
incrementCommand.reset (
|
|
||||||
new CSMWorld::ModifyCommand (cellTable, countIndex, count+1));
|
|
||||||
}
|
|
||||||
|
|
||||||
CSMWorld::CommandMacro macro (document.getUndoStack());
|
|
||||||
macro.push (createCommand.release());
|
|
||||||
if (incrementCommand.get())
|
|
||||||
macro.push (incrementCommand.release());
|
|
||||||
|
|
||||||
dropped = true;
|
dropped = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,51 +26,6 @@ void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand
|
||||||
findColumnIndex (CSMWorld::Columns::ColumnId_Cell);
|
findColumnIndex (CSMWorld::Columns::ColumnId_Cell);
|
||||||
|
|
||||||
command.addValue (cellIdColumn, mCell->text());
|
command.addValue (cellIdColumn, mCell->text());
|
||||||
|
|
||||||
// Set RefNum
|
|
||||||
int refNumColumn = dynamic_cast<CSMWorld::IdTable&> (
|
|
||||||
*getData().getTableModel (CSMWorld::UniversalId::Type_References)).
|
|
||||||
findColumnIndex (CSMWorld::Columns::ColumnId_RefNum);
|
|
||||||
|
|
||||||
command.addValue (refNumColumn, getRefNumCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVWorld::ReferenceCreator::pushCommand (std::auto_ptr<CSMWorld::CreateCommand> command,
|
|
||||||
const std::string& id)
|
|
||||||
{
|
|
||||||
// get the old count
|
|
||||||
std::string cellId = mCell->text().toUtf8().constData();
|
|
||||||
|
|
||||||
CSMWorld::IdTable& cellTable = dynamic_cast<CSMWorld::IdTable&> (
|
|
||||||
*getData().getTableModel (CSMWorld::UniversalId::Type_Cells));
|
|
||||||
|
|
||||||
int countColumn = cellTable.findColumnIndex (CSMWorld::Columns::ColumnId_RefNumCounter);
|
|
||||||
|
|
||||||
QModelIndex countIndex = cellTable.getModelIndex (cellId, countColumn);
|
|
||||||
|
|
||||||
int count = cellTable.data (countIndex).toInt();
|
|
||||||
|
|
||||||
// command for incrementing counter
|
|
||||||
std::auto_ptr<CSMWorld::ModifyCommand> increment (new CSMWorld::ModifyCommand
|
|
||||||
(cellTable, countIndex, count+1));
|
|
||||||
|
|
||||||
CSMWorld::CommandMacro macro (getUndoStack(), command->text());
|
|
||||||
GenericCreator::pushCommand (command, id);
|
|
||||||
macro.push (increment.release());
|
|
||||||
}
|
|
||||||
|
|
||||||
int CSVWorld::ReferenceCreator::getRefNumCount() const
|
|
||||||
{
|
|
||||||
std::string cellId = mCell->text().toUtf8().constData();
|
|
||||||
|
|
||||||
CSMWorld::IdTable& cellTable = dynamic_cast<CSMWorld::IdTable&> (
|
|
||||||
*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,
|
CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
|
|
@ -29,11 +29,6 @@ namespace CSVWorld
|
||||||
|
|
||||||
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||||
|
|
||||||
virtual void pushCommand (std::auto_ptr<CSMWorld::CreateCommand> command,
|
|
||||||
const std::string& id);
|
|
||||||
|
|
||||||
int getRefNumCount() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
|
Loading…
Reference in a new issue