diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 591074372d..252e84c382 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -17,8 +17,6 @@ #include "collectionbase.hpp" -#include "nestedtablewrapper.hpp" - namespace CSMWorld { /// \brief Access to ID field in records @@ -77,10 +75,6 @@ namespace CSMWorld virtual int getSize() const; - virtual int getNestedColumnsCount(int column) const; - - virtual int getNestedRowsCount(int row, int column) const; - virtual std::string getId (int index) const; virtual int getIndex (const std::string& id) const; @@ -89,14 +83,8 @@ namespace CSMWorld virtual QVariant getData (int index, int column) const; - virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const; - virtual void setData (int index, int column, const QVariant& data); - virtual NestedTableWrapperBase* nestedTable(int row, int column) const; - - virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable); - virtual const ColumnBase& getColumn (int column) const; virtual void merge(); @@ -261,18 +249,6 @@ namespace CSMWorld return mRecords.size(); } - template - int Collection::getNestedRowsCount(int row, int column) const - { - return 0; - } - - template - int Collection::getNestedColumnsCount(int column) const - { - return 0; - } - template std::string Collection::getId (int index) const { @@ -302,25 +278,6 @@ namespace CSMWorld return mColumns.at (column)->get (mRecords.at (index)); } - template - QVariant Collection::getNestedData(int row, int column, int subRow, int subColumn) const - { - return QVariant(); - } - - template - NestedTableWrapperBase* Collection::nestedTable(int row, int column) const - { - assert(false); - return new NestedTableWrapperBase(); - } - - template - void Collection::setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) - { - throw std::logic_error("setNestedTable was not overriden"); - } - template void Collection::setData (int index, int column, const QVariant& data) { diff --git a/apps/opencs/model/world/collectionbase.cpp b/apps/opencs/model/world/collectionbase.cpp index a1f4f4a70d..5b0c359c91 100644 --- a/apps/opencs/model/world/collectionbase.cpp +++ b/apps/opencs/model/world/collectionbase.cpp @@ -30,30 +30,3 @@ int CSMWorld::CollectionBase::findColumnIndex (Columns::ColumnId id) const return index; } - -void CSMWorld::CollectionBase::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) -{ - assert(false); //TODO remove and make pure abstract -} - -int CSMWorld::CollectionBase::getNestedColumnsCount(int row, int column) const -{ - assert(false); //TODO remove and make pure abstract - return 0; -} - -int CSMWorld::CollectionBase::getNestedRowsCount(int row, int column) const -{ - assert(false); //TODO, make pure abstract - return 0; -} - -void CSMWorld::CollectionBase::removeNestedRows(int row, int column, int subRow) -{ - assert(false); //todo, make pure abstract -} - -void CSMWorld::CollectionBase::addNestedRow(int row, int col, int position) -{ - assert(false); -} diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index a6ee34e56e..29ac33bc82 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -13,7 +13,7 @@ namespace CSMWorld { struct ColumnBase; struct RecordBase; - class NestedTableWrapperBase; + class NestedTableWrapperBase; /// \brief Base class for record collections /// @@ -35,10 +35,6 @@ namespace CSMWorld virtual int getSize() const = 0; - virtual int getNestedRowsCount(int row, int column) const; - - virtual int getNestedColumnsCount(int row, int column) const; - virtual std::string getId (int index) const = 0; virtual int getIndex (const std::string& id) const = 0; @@ -49,16 +45,8 @@ namespace CSMWorld virtual QVariant getData (int index, int column) const = 0; - virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const = 0; - - virtual NestedTableWrapperBase* nestedTable(int row, int column) const = 0; - - virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) = 0; - virtual void setData (int index, int column, const QVariant& data) = 0; - virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn); - // Not in use. Temporarily removed so that the implementation of RefIdCollection can continue without // these functions for now. // virtual void merge() = 0; @@ -69,10 +57,6 @@ namespace CSMWorld virtual void removeRows (int index, int count) = 0; - virtual void removeNestedRows(int row, int column, int subRow); - - virtual void addNestedRow(int row, int col, int position); - virtual void appendBlankRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None) = 0; ///< \param type Will be ignored, unless the collection supports multiple record types @@ -121,6 +105,28 @@ namespace CSMWorld ///< Return index of column with the given \a id. If no such column exists, an exception is /// thrown. }; + + class NestedCollection : public CollectionBase + { + public: + virtual void addNestedRow(int row, int col, int position) = 0; + + virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const = 0; + + virtual NestedTableWrapperBase* nestedTable(int row, int column) const = 0; + + virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) = 0; + + virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) = 0; + + virtual int getNestedRowsCount(int row, int column) const = 0; + + virtual int getNestedColumnsCount(int row, int column) const = 0; + + virtual void removeNestedRows(int row, int column, int subRow) = 0; + + + }; } #endif diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index be31d05030..4e4ccb1c1b 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -18,7 +18,7 @@ int CSMWorld::IdTable::rowCount (const QModelIndex & parent) const { if (hasChildren(parent)) { - return mIdCollection->getNestedRowsCount(parent.row(), parent.column()); + return dynamic_cast(mIdCollection)->getNestedRowsCount(parent.row(), parent.column()); } return mIdCollection->getSize(); @@ -26,10 +26,9 @@ int CSMWorld::IdTable::rowCount (const QModelIndex & parent) const int CSMWorld::IdTable::columnCount (const QModelIndex & parent) const { - if (parent.isValid() && - parent.data().isValid()) + if (hasChildren(parent)) { - return mIdCollection->getNestedColumnsCount(parent.row(), parent.column()); + return dynamic_cast(mIdCollection)->getNestedColumnsCount(parent.row(), parent.column()); } return mIdCollection->getColumns(); @@ -46,10 +45,10 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const if (index.internalId() != 0) { std::pair parentAdress(unfoldIndexAdress(index.internalId())); - return mIdCollection->getNestedData(parentAdress.first, - parentAdress.second, - index.row(), - index.column()); + return dynamic_cast(mIdCollection)->getNestedData(parentAdress.first, + parentAdress.second, + index.row(), + index.column()); } else { return mIdCollection->getData (index.row(), index.column()); } @@ -101,7 +100,7 @@ bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value { const std::pair& parentAdress(unfoldIndexAdress(index.internalId())); - mIdCollection->setNestedData(parentAdress.first, parentAdress.second, value, index.row(), index.column()); + dynamic_cast(mIdCollection)->setNestedData(parentAdress.first, parentAdress.second, value, index.row(), index.column()); emit dataChanged (CSMWorld::IdTable::index (parentAdress.first, 0), CSMWorld::IdTable::index (parentAdress.second, mIdCollection->getColumns()-1)); @@ -144,7 +143,7 @@ bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& paren { for (int i = 0; i < count; ++i) { - mIdCollection->removeNestedRows(parent.row(), parent.column(), row+i); + dynamic_cast(mIdCollection)->removeNestedRows(parent.row(), parent.column(), row+i); } } else { @@ -164,12 +163,15 @@ bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& paren void CSMWorld::IdTable::addNestedRow(const QModelIndex& parent, int position) { - assert(parent.isValid()); + if (!hasChildren(parent)) + { + throw std::logic_error("Tried to set nested table, but index has no children"); + } int row = parent.row(); beginInsertRows(parent, position, position); - mIdCollection->addNestedRow(row, parent.column(), position); + dynamic_cast(mIdCollection)->addNestedRow(row, parent.column(), position); endInsertRows(); @@ -373,7 +375,7 @@ void CSMWorld::IdTable::setNestedTable(const QModelIndex& index, const CSMWorld: removeRowsMode = true; } - mIdCollection->setNestedTable(index.row(), index.column(), nestedTable); + dynamic_cast(mIdCollection)->setNestedTable(index.row(), index.column(), nestedTable); emit dataChanged (CSMWorld::IdTable::index (index.row(), 0), CSMWorld::IdTable::index (index.row(), mIdCollection->getColumns()-1)); @@ -391,5 +393,5 @@ CSMWorld::NestedTableWrapperBase* CSMWorld::IdTable::nestedTable(const QModelInd throw std::logic_error("Tried to retrive nested table, but index has no children"); } - return mIdCollection->nestedTable(index.row(), index.column()); + return dynamic_cast(mIdCollection)->nestedTable(index.row(), index.column()); } diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index cc7609a587..62616d3697 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -35,7 +35,7 @@ namespace CSMWorld virtual bool isUserEditable() const; }; - class RefIdCollection : public CollectionBase + class RefIdCollection : public NestedCollection { private: