mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-24 00:39:49 +00:00
set refnum and increment refnum counter when creating a new reference
This commit is contained in:
parent
33243c8c16
commit
e93ab383ea
@ -284,20 +284,6 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
|
|||||||
// write references
|
// write references
|
||||||
if (references!=mState.getSubRecords().end())
|
if (references!=mState.getSubRecords().end())
|
||||||
{
|
{
|
||||||
// first pass: find highest RefNum
|
|
||||||
int lastRefNum = -1;
|
|
||||||
|
|
||||||
for (std::vector<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().mRefNum.mContentFile==0 && ref.get().mRefNum.mIndex>lastRefNum)
|
|
||||||
lastRefNum = ref.get().mRefNum.mIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// second pass: write
|
|
||||||
for (std::vector<int>::const_iterator iter (references->second.begin());
|
for (std::vector<int>::const_iterator iter (references->second.begin());
|
||||||
iter!=references->second.end(); ++iter)
|
iter!=references->second.end(); ++iter)
|
||||||
{
|
{
|
||||||
@ -307,19 +293,6 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
|
|||||||
if (ref.mState==CSMWorld::RecordBase::State_Modified ||
|
if (ref.mState==CSMWorld::RecordBase::State_Modified ||
|
||||||
ref.mState==CSMWorld::RecordBase::State_ModifiedOnly)
|
ref.mState==CSMWorld::RecordBase::State_ModifiedOnly)
|
||||||
{
|
{
|
||||||
if (ref.get().mRefNum.mContentFile==-2)
|
|
||||||
{
|
|
||||||
if (lastRefNum>=0xffffff)
|
|
||||||
throw std::runtime_error (
|
|
||||||
"RefNums exhausted in cell: " + cell.get().mId);
|
|
||||||
|
|
||||||
ESM::CellRef ref2 = ref.get();
|
|
||||||
ref2.mRefNum.mContentFile = 0;
|
|
||||||
ref2.mRefNum.mIndex = ++lastRefNum;
|
|
||||||
|
|
||||||
ref2.save (mState.getWriter());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ref.get().save (mState.getWriter());
|
ref.get().save (mState.getWriter());
|
||||||
}
|
}
|
||||||
else if (ref.mState==CSMWorld::RecordBase::State_Deleted)
|
else if (ref.mState==CSMWorld::RecordBase::State_Deleted)
|
||||||
|
@ -4,7 +4,5 @@
|
|||||||
CSMWorld::CellRef::CellRef()
|
CSMWorld::CellRef::CellRef()
|
||||||
{
|
{
|
||||||
mRefNum.mIndex = 0;
|
mRefNum.mIndex = 0;
|
||||||
|
mRefNum.mContentFile = 0;
|
||||||
// special marker: This reference does not have a RefNum assign to it yet.
|
|
||||||
mRefNum.mContentFile = -2;
|
|
||||||
}
|
}
|
@ -61,6 +61,11 @@ CSMWorld::Data& CSVWorld::GenericCreator::getData() const
|
|||||||
return mData;
|
return mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUndoStack& CSVWorld::GenericCreator::getUndoStack()
|
||||||
|
{
|
||||||
|
return mUndoStack;
|
||||||
|
}
|
||||||
|
|
||||||
const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const
|
const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const
|
||||||
{
|
{
|
||||||
return mListId;
|
return mListId;
|
||||||
|
@ -67,6 +67,8 @@ namespace CSVWorld
|
|||||||
|
|
||||||
CSMWorld::Data& getData() const;
|
CSMWorld::Data& getData() const;
|
||||||
|
|
||||||
|
QUndoStack& getUndoStack();
|
||||||
|
|
||||||
const CSMWorld::UniversalId& getCollectionId() const;
|
const CSMWorld::UniversalId& getCollectionId() const;
|
||||||
|
|
||||||
std::string getNamespace() const;
|
std::string getNamespace() const;
|
||||||
|
@ -23,6 +23,41 @@ void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand
|
|||||||
command.addValue (index, mCell->text());
|
command.addValue (index, mCell->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ReferenceCreator::pushCommand (std::auto_ptr<QUndoCommand> 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 setting the refnum in the newly created reference
|
||||||
|
CSMWorld::IdTable& referenceTable = dynamic_cast<CSMWorld::IdTable&> (
|
||||||
|
*getData().getTableModel (CSMWorld::UniversalId::Type_References));
|
||||||
|
|
||||||
|
int refNumColumn = referenceTable.findColumnIndex (CSMWorld::Columns::ColumnId_RefNum);
|
||||||
|
|
||||||
|
std::auto_ptr<CSMWorld::ModifyCommand> setRefNum (new CSMWorld::ModifyCommand
|
||||||
|
(referenceTable, referenceTable.getModelIndex (id, refNumColumn), count));
|
||||||
|
|
||||||
|
// command for incrementing counter
|
||||||
|
std::auto_ptr<CSMWorld::ModifyCommand> 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();
|
||||||
|
}
|
||||||
|
|
||||||
CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
const CSMWorld::UniversalId& id)
|
const CSMWorld::UniversalId& id)
|
||||||
: GenericCreator (data, undoStack, id)
|
: GenericCreator (data, undoStack, id)
|
||||||
|
@ -20,6 +20,9 @@ namespace CSVWorld
|
|||||||
|
|
||||||
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||||
|
|
||||||
|
virtual void pushCommand (std::auto_ptr<QUndoCommand> command,
|
||||||
|
const std::string& id);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user