1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 21:36:45 +00:00

undo works now

This commit is contained in:
Marek Kochanowicz 2014-07-20 22:39:39 +02:00
parent 4d79034dbf
commit 87eed066c2
7 changed files with 56 additions and 5 deletions

View file

@ -19,12 +19,12 @@ opencs_hdrs_noqt (model/doc
opencs_units (model/world opencs_units (model/world
idtable idtableproxymodel regionmap data commanddispatcher idtable idtableproxymodel regionmap data commanddispatcher
idtablebase resourcetable nestedtablemodel nestedtablewrapper idtablebase resourcetable nestedtablemodel
) )
opencs_units_noqt (model/world 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 refidadapter refiddata refidadapterimp ref collectionbase refcollection columns infocollection tablemimedata cellcoordinates cellselection resources resourcesmanager
) )

View file

@ -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"); 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); mIdCollection->setNestedTable(index.row(), index.column(), nestedTable);
emit dataChanged (CSMWorld::IdTable::index (index.row(), 0), emit dataChanged (CSMWorld::IdTable::index (index.row(), 0),
CSMWorld::IdTable::index (index.row(), mIdCollection->getColumns()-1)); 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 CSMWorld::NestedTableWrapperBase* CSMWorld::IdTable::nestedTable(const QModelIndex& index) const

View file

@ -52,9 +52,9 @@ namespace CSMWorld
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 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; QVariant nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
NestedTableWrapperBase* nestedTable(const QModelIndex &index) const; NestedTableWrapperBase* nestedTable(const QModelIndex &index) const;
void setNestedTable(const QModelIndex &index, const NestedTableWrapperBase& nestedTable); void setNestedTable(const QModelIndex &index, const NestedTableWrapperBase& nestedTable);
virtual bool setData ( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); 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; virtual bool isDeleted (const std::string& id) const;
int getColumnId(int column) const; int getColumnId(int column) const;
signals:
void resetStart(const QString& id);
void resetEnd(const QString& id);
}; };
} }

View file

@ -26,6 +26,12 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
connect(mMainModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), connect(mMainModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
this, SLOT(forwardRowsRemoved(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 QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const
@ -157,3 +163,15 @@ void CSMWorld::NestedTableModel::forwardRowsRemoved(const QModelIndex& parent, i
endRemoveRows(); 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();
}

View file

@ -70,6 +70,10 @@ namespace CSMWorld
void forwardRowsAboutToRemoved(const QModelIndex & parent, int first, int last); void forwardRowsAboutToRemoved(const QModelIndex & parent, int first, int last);
void forwardRowsRemoved(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);
}; };
} }

View file

@ -5,3 +5,8 @@ CSMWorld::NestedTableWrapperBase::NestedTableWrapperBase()
CSMWorld::NestedTableWrapperBase::~NestedTableWrapperBase() CSMWorld::NestedTableWrapperBase::~NestedTableWrapperBase()
{} {}
int CSMWorld::NestedTableWrapperBase::size() const
{
return -5;
}

View file

@ -7,9 +7,11 @@ namespace CSMWorld
{ {
virtual ~NestedTableWrapperBase(); virtual ~NestedTableWrapperBase();
virtual int size() const;
NestedTableWrapperBase(); NestedTableWrapperBase();
}; };
template<typename NestedTable> template<typename NestedTable>
struct NestedTableWrapper : public NestedTableWrapperBase struct NestedTableWrapper : public NestedTableWrapperBase
{ {
@ -19,6 +21,11 @@ namespace CSMWorld
: mNestedTable(nestedTable) {} : mNestedTable(nestedTable) {}
virtual ~NestedTableWrapper() {} virtual ~NestedTableWrapper() {}
virtual int size() const
{
return mNestedTable.size(); //i hope that this will be enough
}
}; };
} }
#endif #endif