1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 23:49:55 +00:00

Changes needed to add new nested row.

This commit is contained in:
Marek Kochanowicz 2014-06-24 19:03:29 +02:00
parent befdeb1889
commit 7b5bf637ab
9 changed files with 50 additions and 0 deletions

View file

@ -52,3 +52,8 @@ void CSMWorld::CollectionBase::removeNestedRows(int row, int column, int subRow)
{
assert(false); //todo, make pure abstract
}
void CSMWorld::CollectionBase::addNestedRow(int row, int col, int position)
{
assert(false);
}

View file

@ -66,6 +66,8 @@ namespace CSMWorld
virtual void removeNestedRows(int row, int column, int subRow);
virtual void addNestedRow(int row, int col, int position);
virtual void appendBlankRecord (const std::string& id,
UniversalId::Type type = UniversalId::Type_None) = 0;
///< \param type Will be ignored, unless the collection supports multiple record types

View file

@ -145,6 +145,13 @@ bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& paren
return true;
}
void CSMWorld::IdTable::addNestedRow(const QModelIndex& parent, int position)
{
assert(parent.isValid());
mIdCollection->addNestedRow(parent.row(), parent.column(), position);
}
QModelIndex CSMWorld::IdTable::index (int row, int column, const QModelIndex& parent) const
{
unsigned int encodedId = 0;

View file

@ -80,6 +80,8 @@ namespace CSMWorld
virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex());
void addNestedRow (const QModelIndex& parent, int position);
virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex())
const;

View file

@ -53,6 +53,8 @@ namespace CSMWorld
virtual int getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const = 0;
virtual void removeNestedRow (const RefIdColumn *column, RefIdData& data, int index, int rowToRemove) const = 0;
virtual void addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const = 0;
};
}

View file

@ -227,6 +227,25 @@ void CSMWorld::ContainerRefIdAdapter::removeNestedRow (const RefIdColumn *column
list.erase (list.begin () + rowToRemove);
}
void CSMWorld::ContainerRefIdAdapter::addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const
{
assert(column==mContent);
std::vector<ESM::ContItem>& list = static_cast<Record<ESM::Container>&> (
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container))).get().mInventory.mList;
ESM::ContItem newRow = {0, ""};
if (position >= (int)list.size())
{
list.push_back(newRow);
return;
}
list.insert(list.begin()+position, newRow);
return;
}
void CSMWorld::ContainerRefIdAdapter::setData (const RefIdColumn *column, RefIdData& data, int index,
const QVariant& value) const
{

View file

@ -635,6 +635,8 @@ namespace CSMWorld
virtual int getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const;
virtual void removeNestedRow (const RefIdColumn *column, RefIdData& data, int index, int rowToRemove) const;
virtual void addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const;
};
struct CreatureColumns : public ActorColumns

View file

@ -625,3 +625,12 @@ int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const
return adaptor.getNestedColumnsCount(&mColumns.at(column), mData);
}
void CSMWorld::RefIdCollection::addNestedRow(int row, int col, int position)
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdaptor (localIndex.second));
adaptor.addNestedRow(&mColumns.at(col), mData, localIndex.first, position);
}

View file

@ -79,6 +79,8 @@ namespace CSMWorld
virtual void removeNestedRows(int row, int column, int subRow);
virtual void addNestedRow(int row, int col, int position);
virtual void cloneRecord(const std::string& origin,
const std::string& destination,
const UniversalId::Type type);