From 6573e3f319e27d7bbcdc3e209f941fae9fb257df Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 21 Jul 2014 14:24:54 +0200 Subject: [PATCH] moved responsibility for getNestedData to the inventory helper --- apps/opencs/model/world/nestedadaptors.hpp | 23 +++++++++++++++++++++ apps/opencs/model/world/refidadapterimp.cpp | 17 +-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/opencs/model/world/nestedadaptors.hpp b/apps/opencs/model/world/nestedadaptors.hpp index c0ca9744c..d5edf3358 100644 --- a/apps/opencs/model/world/nestedadaptors.hpp +++ b/apps/opencs/model/world/nestedadaptors.hpp @@ -10,6 +10,8 @@ #include "refiddata.hpp" #include "refidadapter.hpp" +#include + namespace CSMWorld { template @@ -37,6 +39,27 @@ namespace CSMWorld return new NestedTableWrapper >(getRecord(data, index).get().mInventory.mList); } + QVariant getNestedData(const CSMWorld::RefIdColumn* column, + const CSMWorld::RefIdData& data, + int index, + int subRowIndex, + int subColIndex) const + { + const ESM::ContItem& content = getRecord(data, index).get().mInventory.mList.at(subRowIndex); + + switch (subColIndex) + { + case 0: + return QString::fromUtf8(content.mItem.toString().c_str()); + + case 1: + return content.mCount; + + default: + throw std::logic_error("Trying to access non-existing column in the nested table!"); + } + } + private: const Record& getRecord(const RefIdData& data, int index) const diff --git a/apps/opencs/model/world/refidadapterimp.cpp b/apps/opencs/model/world/refidadapterimp.cpp index 08d890957..3622c77af 100644 --- a/apps/opencs/model/world/refidadapterimp.cpp +++ b/apps/opencs/model/world/refidadapterimp.cpp @@ -329,24 +329,9 @@ QVariant CSMWorld::ContainerRefIdAdapter::getNestedData (const CSMWorld::RefIdCo int subRowIndex, int subColIndex) const { - const Record& record = static_cast&> ( - data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container))); - if (column==mContent) { - const ESM::ContItem& content = record.get().mInventory.mList.at(subRowIndex); - - switch (subColIndex) - { - case 0: - return QString::fromUtf8(content.mItem.toString().c_str()); - - case 1: - return content.mCount; - - default: - throw std::logic_error("Trying to access non-existing column in the nested table!"); - } + return mHelper.getNestedData(column, data, index, subRowIndex, subColIndex); } else { throw std::logic_error("This column does not hold multiple values.");