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:
parent
c50cecdc64
commit
77afb754e5
@ -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
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
@ -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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user