From 39545670a887fb29266964e6c4506dd2a1cc2c02 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 25 Jul 2014 12:09:25 +0200 Subject: [PATCH] Added spells table (and it works!) --- apps/opencs/model/world/columnbase.hpp | 1 + apps/opencs/model/world/nestedadaptors.hpp | 87 +++++++++++++++++++++ apps/opencs/model/world/refidadapterimp.hpp | 4 + apps/opencs/model/world/refidcollection.cpp | 4 +- 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/columnbase.hpp b/apps/opencs/model/world/columnbase.hpp index 096491f1ec..5e4dac3ce0 100644 --- a/apps/opencs/model/world/columnbase.hpp +++ b/apps/opencs/model/world/columnbase.hpp @@ -94,6 +94,7 @@ namespace CSMWorld //Those are top level columns that nest other columns Display_NestedItemList, + Display_NestedSpellList, Display_EnchantmentType, Display_BodyPartType, diff --git a/apps/opencs/model/world/nestedadaptors.hpp b/apps/opencs/model/world/nestedadaptors.hpp index 0bb998316f..095bcdf951 100644 --- a/apps/opencs/model/world/nestedadaptors.hpp +++ b/apps/opencs/model/world/nestedadaptors.hpp @@ -2,6 +2,7 @@ #define CSM_WORLD_NESTEDADAPTORS_H #include +#include #include #include "universalid.hpp" @@ -85,6 +86,92 @@ namespace CSMWorld } }; + template + class SpellsHelper : public CastableHelper + { + public: + + SpellsHelper(CSMWorld::UniversalId::Type type) + : CastableHelper(type) {} + + virtual void setNestedTable(RefIdData& data, + int index, + const NestedTableWrapperBase& nestedTable) + { + CastableHelper::getRecord(data, index).get().mSpells.mList = + (static_cast >&>(nestedTable)).mNestedTable; + } + + virtual NestedTableWrapperBase* nestedTable(const RefIdData& data, + int index) const + { + return new NestedTableWrapper >(CastableHelper::getRecord(data, index).get().mSpells.mList); + } + + virtual QVariant getNestedData(const CSMWorld::RefIdData& data, + int index, + int subRowIndex, + int subColIndex) const + { + const std::string& content = CastableHelper::getRecord(data, index).get().mSpells.mList.at(subRowIndex); + + if (subColIndex == 0) + { + return QString::fromUtf8(content.c_str()); + } + + throw std::logic_error("Trying to access non-existing column in the nested table!"); + } + + virtual void removeNestedRow (RefIdData& data, int index, int rowToRemove) const + { + std::vector& list = CastableHelper::getRecord(data, index).get().mSpells.mList; + + list.erase (list.begin () + rowToRemove); + } + + void setNestedData (RefIdData& data, + int index, + const QVariant& value, + int subRowIndex, + int subColIndex) const + { + if (subColIndex == 0) + { + CastableHelper::getRecord(data, index).get().mSpells.mList.at(subRowIndex) = std::string(value.toString().toUtf8()); + } + + throw std::logic_error("Trying to access non-existing column in the nested table!"); + } + + virtual void addNestedRow (RefIdData& data, int index, int position) const + { + std::vector& list = CastableHelper::getRecord(data, index).get().mSpells.mList; + + std::string newString; + if (position >= (int)list.size()) + { + list.push_back(newString); + return; + } + + list.insert(list.begin()+position, newString); + } + + virtual int getNestedColumnsCount(const RefIdData& data) const + { + return 1; + } + + + virtual int getNestedRowsCount(const RefIdData& data, + int index) const + { + return CastableHelper::getRecord(data, index).get().mSpells.mList.size(); + } + + }; + template class InventoryHelper : public CastableHelper { diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index ee2a586243..4c65da85c4 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -478,6 +478,7 @@ namespace CSMWorld std::vector > assoCol; assoCol.push_back(std::make_pair(mActors.mInventory, new InventoryHelper(type))); + assoCol.push_back(std::make_pair(mActors.mSpells, new SpellsHelper(type))); setAssocColumns(assoCol); } @@ -507,6 +508,9 @@ namespace CSMWorld if (column==mActors.mInventory) return true; + if (column==mActors.mSpells) + return true; + std::map::const_iterator iter = mActors.mServices.find (column); diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 89469feac3..eb25b277e9 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -1,4 +1,3 @@ - #include "refidcollection.hpp" #include @@ -99,6 +98,7 @@ CSMWorld::RefIdCollection::RefIdCollection() actorsColumns.mFight = &mColumns.back(); mColumns.push_back (RefIdColumn (Columns::ColumnId_AiAlarm, ColumnBase::Display_Integer)); actorsColumns.mAlarm = &mColumns.back(); + mColumns.push_back(RefIdColumn (Columns::ColumnId_ActorInventory, ColumnBase::Display_NestedItemList, ColumnBase::Flag_Dialogue, true, true, true)); actorsColumns.mInventory = &mColumns.back(); mColumns.back().addNestedColumn(Columns::ColumnId_InventoryItemId, CSMWorld::ColumnBase::Display_String); @@ -665,6 +665,6 @@ CSMWorld::NestedTableWrapperBase* CSMWorld::RefIdCollection::nestedTable(int row RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast(findAdaptor (localIndex.second)); - + return adaptor.nestedTable(&mColumns.at(column), mData, localIndex.first); }