1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 12:39:55 +00:00

adding new rows works

This commit is contained in:
Marek Kochanowicz 2014-07-02 13:13:03 +02:00
parent c50cecdc64
commit 77afb754e5
4 changed files with 61 additions and 10 deletions

View File

@ -148,10 +148,14 @@ void CSMWorld::IdTable::addNestedRow(const QModelIndex& parent, int position)
assert(parent.isValid()); assert(parent.isValid());
int row = parent.row(); int row = parent.row();
beginInsertRows(parent, position, position);
mIdCollection->addNestedRow(row, parent.column(), position); mIdCollection->addNestedRow(row, parent.column(), position);
emit dataChanged (CSMWorld::IdTable::index (row, 0), emit dataChanged (CSMWorld::IdTable::index (row, 0),
CSMWorld::IdTable::index (row, mIdCollection->getColumns()-1)); CSMWorld::IdTable::index (row, mIdCollection->getColumns()-1));
endInsertRows();
} }
QModelIndex CSMWorld::IdTable::index (int row, int column, const QModelIndex& parent) const QModelIndex CSMWorld::IdTable::index (int row, int column, const QModelIndex& parent) const

View File

@ -2,6 +2,7 @@
#include <cassert> #include <cassert>
#include "./idtable.hpp" #include "./idtable.hpp"
#include <QDebug>
CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
ColumnBase::Display columnId, ColumnBase::Display columnId,
@ -14,6 +15,13 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8()); mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8());
QAbstractProxyModel::setSourceModel(parentModel); QAbstractProxyModel::setSourceModel(parentModel);
connect(mMainModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
this, SLOT(forwardRowsAboutToInserted(const QModelIndex &, int, int)));
connect(mMainModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(forwardRowsInserted(const QModelIndex &, int, int)));
} }
QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const
@ -106,3 +114,31 @@ CSMWorld::IdTable* CSMWorld::NestedTableModel::model() const
{ {
return mMainModel; return mMainModel;
} }
void CSMWorld::NestedTableModel::forwardRowsAboutToInserted(const QModelIndex& parent, int first, int last)
{
if (indexIsParent(parent))
{
qDebug()<<"Adding new rows "<< first<<":"<<last;
beginInsertRows(QModelIndex(), first, last);
}
}
void CSMWorld::NestedTableModel::forwardRowsInserted(const QModelIndex& parent, int first, int last)
{
if (indexIsParent(parent))
{
qDebug()<<"rows added"<< first<<":"<<last;
endInsertRows();
}
}
bool CSMWorld::NestedTableModel::indexIsParent(const QModelIndex& index)
{
qDebug()<<"Testing for parenty";
qDebug()<<index.isValid();
qDebug()<<(index.column() == mParentColumn);
return (index.isValid() &&
index.column() == mParentColumn &&
mMainModel->data(mMainModel->index(index.row(), 0)).toString().toUtf8().constData() == mId);
}

View File

@ -21,6 +21,8 @@ namespace CSMWorld
class NestedTableModel : public QAbstractProxyModel class NestedTableModel : public QAbstractProxyModel
{ {
Q_OBJECT
const int mParentColumn; const int mParentColumn;
IdTable* mMainModel; IdTable* mMainModel;
std::string mId; std::string mId;
@ -57,6 +59,13 @@ namespace CSMWorld
private: private:
void setupHeaderVectors(ColumnBase::Display columnId); void setupHeaderVectors(ColumnBase::Display columnId);
bool indexIsParent(const QModelIndex& index);
private slots:
void forwardRowsAboutToInserted(const QModelIndex & parent, int first, int last);
void forwardRowsInserted(const QModelIndex & parent, int first, int last);
}; };
} }

View File

@ -41,10 +41,12 @@ CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack,
setAcceptDrops(true); setAcceptDrops(true);
mAddNewRowAction = new QAction (tr ("Add new row"), this); mAddNewRowAction = new QAction (tr ("Add new row"), this);
connect(mAddNewRowAction, SIGNAL(triggered()), connect(mAddNewRowAction, SIGNAL(triggered()),
this, SLOT(addNewRowActionTriggered())); this, SLOT(addNewRowActionTriggered()));
mRemoveRowAction = new QAction (tr ("Remove row"), this); mRemoveRowAction = new QAction (tr ("Remove row"), this);
connect(mRemoveRowAction, SIGNAL(triggered()), connect(mRemoveRowAction, SIGNAL(triggered()),
this, SLOT(removeRowActionTriggered())); this, SLOT(removeRowActionTriggered()));
} }