1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 03:15:34 +00:00

inserted additional class for nested collections

This commit is contained in:
Marek Kochanowicz 2014-07-30 22:08:55 +02:00
parent 13ee469b70
commit c6194e7ea3
5 changed files with 40 additions and 102 deletions

View file

@ -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<typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::getNestedRowsCount(int row, int column) const
{
return 0;
}
template<typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::getNestedColumnsCount(int column) const
{
return 0;
}
template<typename ESXRecordT, typename IdAccessorT>
std::string Collection<ESXRecordT, IdAccessorT>::getId (int index) const
{
@ -302,25 +278,6 @@ namespace CSMWorld
return mColumns.at (column)->get (mRecords.at (index));
}
template<typename ESXRecordT, typename IdAccessorT>
QVariant Collection<ESXRecordT, IdAccessorT>::getNestedData(int row, int column, int subRow, int subColumn) const
{
return QVariant();
}
template<typename ESXRecordT, typename IdAccessorT>
NestedTableWrapperBase* Collection<ESXRecordT, IdAccessorT>::nestedTable(int row, int column) const
{
assert(false);
return new NestedTableWrapperBase();
}
template<typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable)
{
throw std::logic_error("setNestedTable was not overriden");
}
template<typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::setData (int index, int column, const QVariant& data)
{

View file

@ -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);
}

View file

@ -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

View file

@ -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<NestedCollection*>(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<NestedCollection*>(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<int, int> parentAdress(unfoldIndexAdress(index.internalId()));
return mIdCollection->getNestedData(parentAdress.first,
parentAdress.second,
index.row(),
index.column());
return dynamic_cast<NestedCollection*>(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<int, int>& parentAdress(unfoldIndexAdress(index.internalId()));
mIdCollection->setNestedData(parentAdress.first, parentAdress.second, value, index.row(), index.column());
dynamic_cast<NestedCollection*>(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<NestedCollection*>(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<NestedCollection*>(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<NestedCollection*>(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<NestedCollection*>(mIdCollection)->nestedTable(index.row(), index.column());
}

View file

@ -35,7 +35,7 @@ namespace CSMWorld
virtual bool isUserEditable() const;
};
class RefIdCollection : public CollectionBase
class RefIdCollection : public NestedCollection
{
private: