mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 00:35:23 +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());
|
||||
|
||||
int row = parent.row();
|
||||
|
||||
beginInsertRows(parent, position, position);
|
||||
mIdCollection->addNestedRow(row, parent.column(), position);
|
||||
|
||||
emit dataChanged (CSMWorld::IdTable::index (row, 0),
|
||||
CSMWorld::IdTable::index (row, mIdCollection->getColumns()-1));
|
||||
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
QModelIndex CSMWorld::IdTable::index (int row, int column, const QModelIndex& parent) const
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include "./idtable.hpp"
|
||||
#include <QDebug>
|
||||
|
||||
CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
|
||||
ColumnBase::Display columnId,
|
||||
@ -14,6 +15,13 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
|
||||
mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8());
|
||||
|
||||
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
|
||||
@ -106,3 +114,31 @@ CSMWorld::IdTable* CSMWorld::NestedTableModel::model() const
|
||||
{
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
const int mParentColumn;
|
||||
IdTable* mMainModel;
|
||||
std::string mId;
|
||||
@ -57,6 +59,13 @@ namespace CSMWorld
|
||||
|
||||
private:
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -28,23 +28,25 @@ CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack,
|
||||
{
|
||||
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display> (
|
||||
model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
||||
|
||||
|
||||
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate(display,
|
||||
undoStack,
|
||||
this);
|
||||
|
||||
|
||||
setItemDelegateForColumn(i, delegate);
|
||||
}
|
||||
|
||||
setModel(model);
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
|
||||
mAddNewRowAction = new QAction (tr ("Add new row"), this);
|
||||
connect(mAddNewRowAction, SIGNAL(triggered()),
|
||||
|
||||
connect(mAddNewRowAction, SIGNAL(triggered()),
|
||||
this, SLOT(addNewRowActionTriggered()));
|
||||
|
||||
|
||||
mRemoveRowAction = new QAction (tr ("Remove row"), this);
|
||||
|
||||
connect(mRemoveRowAction, SIGNAL(triggered()),
|
||||
this, SLOT(removeRowActionTriggered()));
|
||||
}
|
||||
@ -60,21 +62,21 @@ void CSVWorld::NestedTable::dragMoveEvent(QDragMoveEvent *event)
|
||||
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
|
||||
{
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
|
||||
QMenu menu(this);
|
||||
|
||||
if (selectionModel()->selectedRows().size() == 1)
|
||||
menu.addAction(mRemoveRowAction);
|
||||
|
||||
menu.addAction(mAddNewRowAction);
|
||||
|
||||
|
||||
menu.exec (event->globalPos());
|
||||
}
|
||||
|
||||
void CSVWorld::NestedTable::removeRowActionTriggered()
|
||||
{
|
||||
mUndoStack.push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
|
||||
mModel->getParentId(),
|
||||
mUndoStack.push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
|
||||
mModel->getParentId(),
|
||||
selectionModel()->selectedRows().begin()->row(),
|
||||
mModel->getParentColumn()));
|
||||
}
|
||||
@ -82,7 +84,7 @@ void CSVWorld::NestedTable::removeRowActionTriggered()
|
||||
void CSVWorld::NestedTable::addNewRowActionTriggered()
|
||||
{
|
||||
mUndoStack.push(new CSMWorld::AddNestedCommand(*(mModel->model()),
|
||||
mModel->getParentId(),
|
||||
mModel->getParentId(),
|
||||
selectionModel()->selectedRows().size(),
|
||||
mModel->getParentColumn()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user