diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index a9c56f9fa..08c105c92 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -25,7 +25,8 @@ opencs_units (model/world opencs_units_noqt (model/world nestedtablewrapper universalid record commands columnbase scriptcontext cell refidcollection - refidadapter refiddata refidadapterimp ref collectionbase refcollection columns infocollection tablemimedata cellcoordinates cellselection resources resourcesmanager + refidadapter refiddata refidadapterimp ref collectionbase refcollection columns infocollection + tablemimedata cellcoordinates cellselection resources resourcesmanager nestedadaptors ) opencs_hdrs_noqt (model/world diff --git a/apps/opencs/model/world/nestedadaptors.cpp b/apps/opencs/model/world/nestedadaptors.cpp new file mode 100644 index 000000000..8ed1819b8 --- /dev/null +++ b/apps/opencs/model/world/nestedadaptors.cpp @@ -0,0 +1 @@ +#include "nestedadaptors.hpp" diff --git a/apps/opencs/model/world/nestedadaptors.hpp b/apps/opencs/model/world/nestedadaptors.hpp new file mode 100644 index 000000000..c0ca9744c --- /dev/null +++ b/apps/opencs/model/world/nestedadaptors.hpp @@ -0,0 +1,56 @@ +#ifndef CSM_WORLD_NESTEDADAPTORS_H +#define CSM_WORLD_NESTEDADAPTORS_H + +#include + +#include "universalid.hpp" +#include "nestedtablewrapper.hpp" +#include +#include "record.hpp" +#include "refiddata.hpp" +#include "refidadapter.hpp" + +namespace CSMWorld +{ + template + class InventoryHelper + { + CSMWorld::UniversalId::Type mType; + + public: + + InventoryHelper(CSMWorld::UniversalId::Type type) : mType(type) {}; + + void setNestedTable(const RefIdColumn* column, + RefIdData& data, + int index, + const NestedTableWrapperBase& nestedTable) + { + getRecord(data, index).get().mInventory.mList = + (static_cast >&>(nestedTable)).mNestedTable; + } + + NestedTableWrapperBase* nestedTable(const RefIdColumn* column, + const RefIdData& data, + int index) const + { + return new NestedTableWrapper >(getRecord(data, index).get().mInventory.mList); + } + + private: + + const Record& getRecord(const RefIdData& data, int index) const + { + return dynamic_cast&> ( + data.getRecord (RefIdData::LocalIndex (index, mType))); + } + + Record& getRecord(RefIdData& data, int index) const + { + return dynamic_cast&> ( + data.getRecord (RefIdData::LocalIndex (index, mType))); + } + }; +} + +#endif diff --git a/apps/opencs/model/world/refidadapterimp.cpp b/apps/opencs/model/world/refidadapterimp.cpp index 173e89f56..08d890957 100644 --- a/apps/opencs/model/world/refidadapterimp.cpp +++ b/apps/opencs/model/world/refidadapterimp.cpp @@ -180,7 +180,7 @@ void CSMWorld::ClothingRefIdAdapter::setData (const RefIdColumn *column, RefIdDa CSMWorld::ContainerRefIdAdapter::ContainerRefIdAdapter (const NameColumns& columns, const RefIdColumn *weight, const RefIdColumn *organic, const RefIdColumn *respawn, const RefIdColumn *content) : NameRefIdAdapter (UniversalId::Type_Container, columns), mWeight (weight), - mOrganic (organic), mRespawn (respawn), mContent(content) + mOrganic (organic), mRespawn (respawn), mContent(content), mHelper(InventoryHelper(UniversalId::Type_Container)) {} int CSMWorld::ContainerRefIdAdapter::getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const @@ -313,20 +313,14 @@ void CSMWorld::ContainerRefIdAdapter::setNestedTable(const RefIdColumn* column, int index, const NestedTableWrapperBase& nestedTable) { - Record& record = dynamic_cast&> ( - data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container))); - - record.get().mInventory.mList = (static_cast >&>(nestedTable)).mNestedTable; + mHelper.setNestedTable(column, data, index, nestedTable); } CSMWorld::NestedTableWrapperBase* CSMWorld::ContainerRefIdAdapter::nestedTable (const RefIdColumn* column, const RefIdData& data, int index) const { - const Record& record = dynamic_cast&> ( - data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container))); - - return new NestedTableWrapper >(record.get().mInventory.mList); + return mHelper.nestedTable(column, data, index); } QVariant CSMWorld::ContainerRefIdAdapter::getNestedData (const CSMWorld::RefIdColumn* column, diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index ab05cfbc5..aac2ba807 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -12,6 +12,7 @@ #include "refiddata.hpp" #include "universalid.hpp" #include "refidadapter.hpp" +#include "nestedadaptors.hpp" namespace CSMWorld { @@ -614,6 +615,8 @@ namespace CSMWorld const RefIdColumn *mOrganic; const RefIdColumn *mRespawn; const RefIdColumn *mContent; + + InventoryHelper mHelper; public: