forked from mirror/openmw-tes3mp
some IdCollection and IdTable cleanup
This commit is contained in:
parent
e7bf1d230c
commit
236751ec45
4 changed files with 30 additions and 28 deletions
|
@ -71,7 +71,7 @@ void CSMWorld::RevertCommand::redo()
|
|||
|
||||
void CSMWorld::RevertCommand::undo()
|
||||
{
|
||||
mModel.setRecord (*mOld);
|
||||
mModel.setRecord (mId, *mOld);
|
||||
}
|
||||
|
||||
CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand *parent)
|
||||
|
@ -104,5 +104,5 @@ void CSMWorld::DeleteCommand::redo()
|
|||
|
||||
void CSMWorld::DeleteCommand::undo()
|
||||
{
|
||||
mModel.setRecord (*mOld);
|
||||
mModel.setRecord (mId, *mOld);
|
||||
}
|
|
@ -66,15 +66,12 @@ namespace CSMWorld
|
|||
///< If the record type does not match, an exception is thrown.
|
||||
///
|
||||
/// \attention \a record must not change the ID.
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
|
||||
virtual void appendRecord (const RecordBase& record) = 0;
|
||||
virtual void appendRecord (const RecordBase& record,
|
||||
UniversalId::Type type = UniversalId::Type_None) = 0;
|
||||
///< If the record type does not match, an exception is thrown.
|
||||
|
||||
virtual std::string getId (const RecordBase& record) const = 0;
|
||||
///< Return ID for \a record.
|
||||
///
|
||||
/// \attention Throws an exception, if the type of \a record does not match.
|
||||
|
||||
virtual const RecordBase& getRecord (const std::string& id) const = 0;
|
||||
|
||||
virtual const RecordBase& getRecord (int index) const = 0;
|
||||
|
@ -82,6 +79,9 @@ namespace CSMWorld
|
|||
virtual void load (ESM::ESMReader& reader, bool base,
|
||||
UniversalId::Type type = UniversalId::Type_None) = 0;
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
|
||||
virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0;
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
};
|
||||
|
||||
///< \brief Access to ID field in records
|
||||
|
@ -161,13 +161,10 @@ namespace CSMWorld
|
|||
///
|
||||
/// \attention \a record must not change the ID.
|
||||
|
||||
virtual void appendRecord (const RecordBase& record);
|
||||
virtual void appendRecord (const RecordBase& record,
|
||||
UniversalId::Type type = UniversalId::Type_None);
|
||||
///< If the record type does not match, an exception is thrown.
|
||||
|
||||
virtual std::string getId (const RecordBase& record) const;
|
||||
///< Return ID for \a record.
|
||||
///
|
||||
/// \attention Throw san exception, if the type of \a record does not match.
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
|
||||
virtual const Record<ESXRecordT>& getRecord (const std::string& id) const;
|
||||
|
||||
|
@ -177,6 +174,9 @@ namespace CSMWorld
|
|||
UniversalId::Type type = UniversalId::Type_None);
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
|
||||
virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const;
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
|
||||
void addColumn (Column<ESXRecordT> *column);
|
||||
};
|
||||
|
||||
|
@ -344,17 +344,13 @@ namespace CSMWorld
|
|||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
void IdCollection<ESXRecordT, IdAccessorT>::appendRecord (const RecordBase& record)
|
||||
void IdCollection<ESXRecordT, IdAccessorT>::appendRecord (const RecordBase& record,
|
||||
UniversalId::Type type)
|
||||
{
|
||||
mRecords.push_back (dynamic_cast<const Record<ESXRecordT>&> (record));
|
||||
mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (getId (record)), mRecords.size()-1));
|
||||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
std::string IdCollection<ESXRecordT, IdAccessorT>::getId (const RecordBase& record) const
|
||||
{
|
||||
const Record<ESXRecordT>& record2 = dynamic_cast<const Record<ESXRecordT>&> (record);
|
||||
return IdAccessorT().getId (record2.isModified() ? record2.mModified : record2.mBase);
|
||||
mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (
|
||||
dynamic_cast<const ESXRecordT&> (record))),
|
||||
mRecords.size()-1));
|
||||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
|
@ -416,6 +412,12 @@ namespace CSMWorld
|
|||
}
|
||||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
int IdCollection<ESXRecordT, IdAccessorT>::getAppendIndex (UniversalId::Type type) const
|
||||
{
|
||||
return static_cast<int> (mRecords.size());
|
||||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
const Record<ESXRecordT>& IdCollection<ESXRecordT, IdAccessorT>::getRecord (const std::string& id) const
|
||||
{
|
||||
|
|
|
@ -117,7 +117,7 @@ QModelIndex CSMWorld::IdTable::parent (const QModelIndex& index) const
|
|||
|
||||
void CSMWorld::IdTable::addRecord (const std::string& id)
|
||||
{
|
||||
int index = mIdCollection->getSize();
|
||||
int index = mIdCollection->getAppendIndex();
|
||||
|
||||
beginInsertRows (QModelIndex(), index, index);
|
||||
|
||||
|
@ -131,13 +131,13 @@ QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column)
|
|||
return index (mIdCollection->getIndex (id), column);
|
||||
}
|
||||
|
||||
void CSMWorld::IdTable::setRecord (const RecordBase& record)
|
||||
void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& record)
|
||||
{
|
||||
int index = mIdCollection->searchId (mIdCollection->getId (record));
|
||||
int index = mIdCollection->searchId (id);
|
||||
|
||||
if (index==-1)
|
||||
{
|
||||
int index = mIdCollection->getSize();
|
||||
int index = mIdCollection->getAppendIndex();
|
||||
|
||||
beginInsertRows (QModelIndex(), index, index);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace CSMWorld
|
|||
|
||||
QModelIndex getModelIndex (const std::string& id, int column) const;
|
||||
|
||||
void setRecord (const RecordBase& record);
|
||||
void setRecord (const std::string& id, const RecordBase& record);
|
||||
///< Add record or overwrite existing recrod.
|
||||
|
||||
const RecordBase& getRecord (const std::string& id) const;
|
||||
|
|
Loading…
Reference in a new issue