diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index bcc64b60a..a9c56f9fa 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -19,12 +19,12 @@ opencs_hdrs_noqt (model/doc opencs_units (model/world idtable idtableproxymodel regionmap data commanddispatcher - idtablebase resourcetable nestedtablemodel nestedtablewrapper + idtablebase resourcetable nestedtablemodel ) opencs_units_noqt (model/world - universalid record commands columnbase scriptcontext cell refidcollection + nestedtablewrapper universalid record commands columnbase scriptcontext cell refidcollection refidadapter refiddata refidadapterimp ref collectionbase refcollection columns infocollection tablemimedata cellcoordinates cellselection resources resourcesmanager ) diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index dd045cb78..be31d0503 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -366,10 +366,22 @@ void CSMWorld::IdTable::setNestedTable(const QModelIndex& index, const CSMWorld: throw std::logic_error("Tried to set nested table, but index has no children"); } + bool removeRowsMode = false; + if (nestedTable.size() != this->nestedTable(index)->size()) + { + emit resetStart(this->index(index.row(), 0).data().toString()); + removeRowsMode = true; + } + mIdCollection->setNestedTable(index.row(), index.column(), nestedTable); emit dataChanged (CSMWorld::IdTable::index (index.row(), 0), CSMWorld::IdTable::index (index.row(), mIdCollection->getColumns()-1)); + + if (removeRowsMode) + { + emit resetEnd(this->index(index.row(), 0).data().toString()); + } } CSMWorld::NestedTableWrapperBase* CSMWorld::IdTable::nestedTable(const QModelIndex& index) const diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index b7ba8c342..d755822b5 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -52,9 +52,9 @@ namespace CSMWorld virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - + NestedTableWrapperBase* nestedTable(const QModelIndex &index) const; - + void setNestedTable(const QModelIndex &index, const NestedTableWrapperBase& nestedTable); virtual bool setData ( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); @@ -105,6 +105,11 @@ namespace CSMWorld virtual bool isDeleted (const std::string& id) const; int getColumnId(int column) const; + + signals: + void resetStart(const QString& id); + + void resetEnd(const QString& id); }; } diff --git a/apps/opencs/model/world/nestedtablemodel.cpp b/apps/opencs/model/world/nestedtablemodel.cpp index f0b510244..734047b8d 100644 --- a/apps/opencs/model/world/nestedtablemodel.cpp +++ b/apps/opencs/model/world/nestedtablemodel.cpp @@ -26,6 +26,12 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, connect(mMainModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(forwardRowsRemoved(const QModelIndex &, int, int))); + + connect(mMainModel, SIGNAL(resetStart(const QString&)), + this, SLOT(forwardResetStart(const QString&))); + + connect(mMainModel, SIGNAL(resetEnd(const QString&)), + this, SLOT(forwardResetEnd(const QString&))); } QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const @@ -157,3 +163,15 @@ void CSMWorld::NestedTableModel::forwardRowsRemoved(const QModelIndex& parent, i endRemoveRows(); } } + +void CSMWorld::NestedTableModel::forwardResetStart(const QString& id) +{ + if (id.toUtf8() == mId.c_str()) + beginResetModel(); +} + +void CSMWorld::NestedTableModel::forwardResetEnd(const QString& id) +{ + if (id.toUtf8() == mId.c_str()) + endResetModel(); +} diff --git a/apps/opencs/model/world/nestedtablemodel.hpp b/apps/opencs/model/world/nestedtablemodel.hpp index dfb231124..5fea5c006 100644 --- a/apps/opencs/model/world/nestedtablemodel.hpp +++ b/apps/opencs/model/world/nestedtablemodel.hpp @@ -70,6 +70,10 @@ namespace CSMWorld void forwardRowsAboutToRemoved(const QModelIndex & parent, int first, int last); void forwardRowsRemoved(const QModelIndex & parent, int first, int last); + + void forwardResetStart(const QString& id); + + void forwardResetEnd(const QString& id); }; } diff --git a/apps/opencs/model/world/nestedtablewrapper.cpp b/apps/opencs/model/world/nestedtablewrapper.cpp index 387bc6e7b..3966dbc57 100644 --- a/apps/opencs/model/world/nestedtablewrapper.cpp +++ b/apps/opencs/model/world/nestedtablewrapper.cpp @@ -5,3 +5,8 @@ CSMWorld::NestedTableWrapperBase::NestedTableWrapperBase() CSMWorld::NestedTableWrapperBase::~NestedTableWrapperBase() {} + +int CSMWorld::NestedTableWrapperBase::size() const +{ + return -5; +} diff --git a/apps/opencs/model/world/nestedtablewrapper.hpp b/apps/opencs/model/world/nestedtablewrapper.hpp index 70e35f68a..f0ca00dbe 100644 --- a/apps/opencs/model/world/nestedtablewrapper.hpp +++ b/apps/opencs/model/world/nestedtablewrapper.hpp @@ -7,9 +7,11 @@ namespace CSMWorld { virtual ~NestedTableWrapperBase(); + virtual int size() const; + NestedTableWrapperBase(); }; - + template struct NestedTableWrapper : public NestedTableWrapperBase { @@ -19,6 +21,11 @@ namespace CSMWorld : mNestedTable(nestedTable) {} virtual ~NestedTableWrapper() {} + + virtual int size() const + { + return mNestedTable.size(); //i hope that this will be enough + } }; } #endif