Changed over inventory adapters. Fixed a few places where modified records were not set properly.

test
cc9cii 10 years ago
parent 25261a60e5
commit 7ccf53e750

@ -81,13 +81,17 @@ namespace CSMWorld
void PathgridPointListAdapter::setNestedTable(Record<Pathgrid>& record,
const NestedTableWrapperBase& nestedTable) const
{
record.get().mPoints =
Pathgrid pathgrid = record.get();
pathgrid.mPoints =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mPoints;
record.get().mData.mS2 =
pathgrid.mData.mS2 =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mData.mS2;
// also update edges in case points were added/removed
record.get().mEdges =
pathgrid.mEdges =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mEdges;
record.setModified (pathgrid);
}
NestedTableWrapperBase* PathgridPointListAdapter::nestedTable(const Record<Pathgrid>& record) const
@ -180,8 +184,12 @@ namespace CSMWorld
void PathgridEdgeListAdapter::setNestedTable(Record<Pathgrid>& record,
const NestedTableWrapperBase& nestedTable) const
{
record.get().mEdges =
Pathgrid pathgrid = record.get();
pathgrid.mEdges =
static_cast<const NestedTableWrapper<ESM::Pathgrid::EdgeList> &>(nestedTable).mNestedTable;
record.setModified (pathgrid);
}
NestedTableWrapperBase* PathgridEdgeListAdapter::nestedTable(const Record<Pathgrid>& record) const
@ -277,8 +285,12 @@ namespace CSMWorld
void FactionReactionsAdapter::setNestedTable(Record<ESM::Faction>& record,
const NestedTableWrapperBase& nestedTable) const
{
record.get().mReactions =
ESM::Faction faction = record.get();
faction.mReactions =
static_cast<const NestedTableWrapper<std::map<std::string, int> >&>(nestedTable).mNestedTable;
record.setModified (faction);
}
NestedTableWrapperBase* FactionReactionsAdapter::nestedTable(const Record<ESM::Faction>& record) const
@ -393,8 +405,12 @@ namespace CSMWorld
void RegionSoundListAdapter::setNestedTable(Record<ESM::Region>& record,
const NestedTableWrapperBase& nestedTable) const
{
record.get().mSoundList =
ESM::Region region = record.get();
region.mSoundList =
static_cast<const NestedTableWrapper<std::vector<ESM::Region::SoundRef> >&>(nestedTable).mNestedTable;
record.setModified (region);
}
NestedTableWrapperBase* RegionSoundListAdapter::nestedTable(const Record<ESM::Region>& record) const

@ -173,8 +173,12 @@ namespace CSMWorld
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
record.get().mPowers.mList =
ESXRecordT raceOrBthSgn = record.get();
raceOrBthSgn.mPowers.mList =
static_cast<const NestedTableWrapper<std::vector<std::string> >&>(nestedTable).mNestedTable;
record.setModified (raceOrBthSgn);
}
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const
@ -277,8 +281,12 @@ namespace CSMWorld
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
record.get().mEffects.mList =
ESXRecordT magic = record.get();
magic.mEffects.mList =
static_cast<const NestedTableWrapper<std::vector<ESM::ENAMstruct> >&>(nestedTable).mNestedTable;
record.setModified (magic);
}
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const

@ -26,7 +26,7 @@ QVariant CSMWorld::PotionRefIdAdapter::getData (const RefIdColumn *column, const
return record.get().mData.mAutoCalc!=0;
if (column==mColumns.mEffects)
return true; // Required to show nested tables in dialogue subview
return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
return InventoryRefIdAdapter<ESM::Potion>::getData (column, data, index);
}
@ -213,7 +213,7 @@ QVariant CSMWorld::ContainerRefIdAdapter::getData (const RefIdColumn *column,
return (record.get().mFlags & ESM::Container::Respawn)!=0;
if (column==mContent)
return true; // required by IdTree::hasChildren()
return true; // Required to show nested tables in dialogue subview
return NameRefIdAdapter<ESM::Container>::getData (column, data, index);
}
@ -497,7 +497,7 @@ QVariant CSMWorld::NpcRefIdAdapter::getData (const RefIdColumn *column, const Re
return QString::fromUtf8 (record.get().mHead.c_str());
if (column==mColumns.mDestinations)
return true; // required by IdTree::hasChildren()
return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
std::map<const RefIdColumn *, unsigned int>::const_iterator iter =
mColumns.mFlags.find (column);

@ -8,6 +8,9 @@
#include <components/esm/loadalch.hpp>
#include <components/esm/loadench.hpp>
#include <components/esm/loadappa.hpp>
#include <components/esm/loadnpc.hpp>
#include <components/esm/loadcrea.hpp>
#include <components/esm/loadcont.hpp>
#include "record.hpp"
#include "refiddata.hpp"
@ -545,10 +548,10 @@ namespace CSMWorld
return record.get().mAiData.mAlarm;
if (column==mActors.mInventory)
return true; // required by IdTree::hasChildren()
return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
if (column==mActors.mSpells)
return true; // required by IdTree::hasChildren()
return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
std::map<const RefIdColumn *, unsigned int>::const_iterator iter =
mActors.mServices.find (column);
@ -908,7 +911,7 @@ namespace CSMWorld
virtual int getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const
{
const Record<ESXRecordT> record;
const Record<ESXRecordT> record; // not used, just a dummy
return EffectsListAdapter<ESXRecordT>::getNestedColumnsCount(record);
}
@ -919,6 +922,144 @@ namespace CSMWorld
return EffectsListAdapter<ESXRecordT>::getNestedRowsCount(record);
}
};
template <typename ESXRecordT>
class NestedInventoryRefIdAdapter : public NestedRefIdAdapterBase
{
UniversalId::Type mType;
// not implemented
NestedInventoryRefIdAdapter (const NestedInventoryRefIdAdapter&);
NestedInventoryRefIdAdapter& operator= (const NestedInventoryRefIdAdapter&);
public:
NestedInventoryRefIdAdapter(UniversalId::Type type) :mType(type) {}
virtual ~NestedInventoryRefIdAdapter() {}
virtual void addNestedRow (const RefIdColumn *column,
RefIdData& data, int index, int position) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
ESXRecordT container = record.get();
std::vector<ESM::ContItem>& list = container.mInventory.mList;
ESM::ContItem newRow = {0, {""}};
if (position >= (int)list.size())
list.push_back(newRow);
else
list.insert(list.begin()+position, newRow);
record.setModified (container);
}
virtual void removeNestedRow (const RefIdColumn *column,
RefIdData& data, int index, int rowToRemove) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
ESXRecordT container = record.get();
std::vector<ESM::ContItem>& list = container.mInventory.mList;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (list.size()))
throw std::runtime_error ("index out of range");
list.erase (list.begin () + rowToRemove);
record.setModified (container);
}
virtual void setNestedTable (const RefIdColumn* column,
RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
ESXRecordT container = record.get();
container.mInventory.mList =
static_cast<const NestedTableWrapper<std::vector<ESM::ContItem> >&>(nestedTable).mNestedTable;
record.setModified (container);
}
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column,
const RefIdData& data, int index) const
{
const Record<ESXRecordT>& record =
static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::vector<ESM::ContItem> >(record.get().mInventory.mList);
}
virtual QVariant getNestedData (const RefIdColumn *column,
const RefIdData& data, int index, int subRowIndex, int subColIndex) const
{
const Record<ESXRecordT>& record =
static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
const std::vector<ESM::ContItem>& list = record.get().mInventory.mList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (list.size()))
throw std::runtime_error ("index out of range");
const ESM::ContItem& content = list.at(subRowIndex);
switch (subColIndex)
{
case 0: return QString::fromUtf8(content.mItem.toString().c_str());
case 1: return content.mCount;
default:
throw std::runtime_error("Trying to access non-existing column in the nested table!");
}
}
virtual void setNestedData (const RefIdColumn *column,
RefIdData& data, int row, const QVariant& value, int subRowIndex, int subColIndex) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (row, mType)));
ESXRecordT container = record.get();
std::vector<ESM::ContItem>& list = container.mInventory.mList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (list.size()))
throw std::runtime_error ("index out of range");
switch(subColIndex)
{
case 0:
list.at(subRowIndex).mItem.assign(std::string(value.toString().toUtf8().constData()));
break;
case 1:
list.at(subRowIndex).mCount = value.toInt();
break;
default:
throw std::runtime_error("Trying to access non-existing column in the nested table!");
}
record.setModified (container);
}
virtual int getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const
{
return 2;
}
virtual int getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const
{
const Record<ESXRecordT>& record =
static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
return static_cast<int>(record.get().mInventory.mList.size());
}
};
}
#endif

@ -76,7 +76,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
mColumns.push_back (RefIdColumn (Columns::ColumnId_EffectList, ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
potionColumns.mEffects = &mColumns.back(); // see refidadapterimp.hpp
mNestedAdapters.insert (std::make_pair(&mColumns.back(),
new EffectsRefIdAdapter<ESM::Potion> (UniversalId::Type_Potion)));
new EffectsRefIdAdapter<ESM::Potion> (UniversalId::Type_Potion)));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_EffectId, ColumnBase::Display_String/*, false*/));
mColumns.back().addColumn(
@ -124,6 +124,10 @@ CSMWorld::RefIdCollection::RefIdCollection()
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_ActorInventory, ColumnBase::Display_NestedItemList, ColumnBase::Flag_Dialogue));
actorsColumns.mInventory = &mColumns.back();
mNestedAdapters.insert (std::make_pair(&mColumns.back(),
new NestedInventoryRefIdAdapter<ESM::NPC> (UniversalId::Type_Npc)));
mNestedAdapters.insert (std::make_pair(&mColumns.back(),
new NestedInventoryRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature)));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_InventoryItemId, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
@ -205,6 +209,8 @@ CSMWorld::RefIdCollection::RefIdCollection()
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_ContainerContent, ColumnBase::Display_NestedItemList, ColumnBase::Flag_Dialogue));
const RefIdColumn *content = &mColumns.back();
mNestedAdapters.insert (std::make_pair(&mColumns.back(),
new NestedInventoryRefIdAdapter<ESM::Container> (UniversalId::Type_Container)));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_InventoryItemId, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(

Loading…
Cancel
Save