#include "nestedinfocollection.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace CSMWorld { NestedInfoCollection::~NestedInfoCollection() { for (std::map*>::iterator iter(mAdapters.begin()); iter != mAdapters.end(); ++iter) { delete (*iter).second; } } void NestedInfoCollection::addAdapter(std::pair*> adapter) { mAdapters.insert(adapter); } const NestedColumnAdapter& NestedInfoCollection::getAdapter(const ColumnBase& column) const { std::map*>::const_iterator iter = mAdapters.find(&column); if (iter == mAdapters.end()) throw std::logic_error("No such column in the nestedidadapter"); return *iter->second; } void NestedInfoCollection::addNestedRow(int row, int column, int position) { auto record = std::make_unique>(); record->assign(Collection::getRecord(row)); getAdapter(Collection::getColumn(column)).addRow(*record, position); Collection::setRecord(row, std::move(record)); } void NestedInfoCollection::removeNestedRows(int row, int column, int subRow) { auto record = std::make_unique>(); record->assign(Collection::getRecord(row)); getAdapter(Collection::getColumn(column)).removeRow(*record, subRow); Collection::setRecord(row, std::move(record)); } QVariant NestedInfoCollection::getNestedData(int row, int column, int subRow, int subColumn) const { return getAdapter(Collection::getColumn(column)) .getData(Collection::getRecord(row), subRow, subColumn); } void NestedInfoCollection::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) { auto record = std::make_unique>(); record->assign(Collection::getRecord(row)); getAdapter(Collection::getColumn(column)).setData(*record, data, subRow, subColumn); Collection::setRecord(row, std::move(record)); } CSMWorld::NestedTableWrapperBase* NestedInfoCollection::nestedTable(int row, int column) const { return getAdapter(Collection::getColumn(column)).table(Collection::getRecord(row)); } void NestedInfoCollection::setNestedTable(int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable) { auto record = std::make_unique>(); record->assign(Collection::getRecord(row)); getAdapter(Collection::getColumn(column)).setTable(*record, nestedTable); Collection::setRecord(row, std::move(record)); } int NestedInfoCollection::getNestedRowsCount(int row, int column) const { return getAdapter(Collection::getColumn(column)).getRowsCount(Collection::getRecord(row)); } int NestedInfoCollection::getNestedColumnsCount(int row, int column) const { return getAdapter(Collection::getColumn(column)).getColumnsCount(Collection::getRecord(row)); } CSMWorld::NestableColumn* NestedInfoCollection::getNestableColumn(int column) { return Collection::getNestableColumn(column); } }