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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,23 +28,25 @@ CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack,
|
|||||||
{
|
{
|
||||||
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display> (
|
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display> (
|
||||||
model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
||||||
|
|
||||||
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate(display,
|
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate(display,
|
||||||
undoStack,
|
undoStack,
|
||||||
this);
|
this);
|
||||||
|
|
||||||
setItemDelegateForColumn(i, delegate);
|
setItemDelegateForColumn(i, delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
setModel(model);
|
setModel(model);
|
||||||
|
|
||||||
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()));
|
||||||
}
|
}
|
||||||
@ -60,21 +62,21 @@ void CSVWorld::NestedTable::dragMoveEvent(QDragMoveEvent *event)
|
|||||||
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
|
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||||
|
|
||||||
QMenu menu(this);
|
QMenu menu(this);
|
||||||
|
|
||||||
if (selectionModel()->selectedRows().size() == 1)
|
if (selectionModel()->selectedRows().size() == 1)
|
||||||
menu.addAction(mRemoveRowAction);
|
menu.addAction(mRemoveRowAction);
|
||||||
|
|
||||||
menu.addAction(mAddNewRowAction);
|
menu.addAction(mAddNewRowAction);
|
||||||
|
|
||||||
menu.exec (event->globalPos());
|
menu.exec (event->globalPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::NestedTable::removeRowActionTriggered()
|
void CSVWorld::NestedTable::removeRowActionTriggered()
|
||||||
{
|
{
|
||||||
mUndoStack.push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
|
mUndoStack.push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
|
||||||
mModel->getParentId(),
|
mModel->getParentId(),
|
||||||
selectionModel()->selectedRows().begin()->row(),
|
selectionModel()->selectedRows().begin()->row(),
|
||||||
mModel->getParentColumn()));
|
mModel->getParentColumn()));
|
||||||
}
|
}
|
||||||
@ -82,7 +84,7 @@ void CSVWorld::NestedTable::removeRowActionTriggered()
|
|||||||
void CSVWorld::NestedTable::addNewRowActionTriggered()
|
void CSVWorld::NestedTable::addNewRowActionTriggered()
|
||||||
{
|
{
|
||||||
mUndoStack.push(new CSMWorld::AddNestedCommand(*(mModel->model()),
|
mUndoStack.push(new CSMWorld::AddNestedCommand(*(mModel->model()),
|
||||||
mModel->getParentId(),
|
mModel->getParentId(),
|
||||||
selectionModel()->selectedRows().size(),
|
selectionModel()->selectedRows().size(),
|
||||||
mModel->getParentColumn()));
|
mModel->getParentColumn()));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user