1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-01 20:36:40 +00:00

Don't do mapToSource at executeModify

This commit is contained in:
unelsson 2021-08-20 22:32:41 +03:00
parent 298db2ef76
commit 7801f42005
2 changed files with 9 additions and 18 deletions

View file

@ -137,7 +137,7 @@ std::vector<CSMWorld::UniversalId> CSMWorld::CommandDispatcher::getExtendedTypes
return tables;
}
void CSMWorld::CommandDispatcher::executeModify (QAbstractItemModel *sourceModel, const QModelIndex& sourceIndex, const QVariant& new_)
void CSMWorld::CommandDispatcher::executeModify (QAbstractItemModel *model, const QModelIndex& index, const QVariant& new_)
{
if (mLocked)
return;
@ -150,26 +150,17 @@ void CSMWorld::CommandDispatcher::executeModify (QAbstractItemModel *sourceModel
std::unique_ptr<CSMWorld::ModifyCommand> modifyData;
std::unique_ptr<CSMWorld::UpdateCellCommand> modifyCell;
QAbstractItemModel *model(nullptr);
QModelIndex index;
QAbstractItemModel* sourceModel = model;
if (IdTableProxyModel* proxy = dynamic_cast<IdTableProxyModel*> (model))
sourceModel = proxy->sourceModel();
if (QAbstractProxyModel *proxy = dynamic_cast<QAbstractProxyModel *> (sourceModel))
{
// Replace proxy with actual model
index = proxy->mapToSource (sourceIndex);
model = proxy->sourceModel();
}
if (!model) return;
CSMWorld::IdTable& table = dynamic_cast<CSMWorld::IdTable&>(*sourceModel); // for getId()
int stateColumn = table.findColumnIndex(Columns::ColumnId_Modification);
QModelIndex stateIndex = table.getModelIndex(table.getId(index.row()), stateColumn);
RecordBase::State state = static_cast<RecordBase::State> (sourceModel->data(stateIndex).toInt());
int columnId = model->data (index, ColumnBase::Role_ColumnId).toInt();
int stateColumn = dynamic_cast<CSMWorld::IdTable&>(*model).findColumnIndex(Columns::ColumnId_Modification);
CSMWorld::IdTable& table = dynamic_cast<CSMWorld::IdTable&>(*model); // for getId()
QModelIndex stateIndex = table.getModelIndex(table.getId(index.row()), stateColumn);
RecordBase::State state = static_cast<RecordBase::State> (model->data(stateIndex).toInt());
// This is not guaranteed to be the same as \a model, since a proxy could be used.
IdTable& model2 = dynamic_cast<IdTable&> (*mDocument.getData().getTableModel(mId));

View file

@ -60,7 +60,7 @@ namespace CSMWorld
///
/// \attention model must either be a model for the table operated on by this
/// dispatcher or a proxy of it.
void executeModify (QAbstractItemModel *sourceModel, const QModelIndex& sourceIndex, const QVariant& new_);
void executeModify (QAbstractItemModel *model, const QModelIndex& index, const QVariant& new_);
public slots: