diff --git a/apps/opencs/model/world/commanddispatcher.cpp b/apps/opencs/model/world/commanddispatcher.cpp index 13e66fd5cd..3da3e3d22c 100644 --- a/apps/opencs/model/world/commanddispatcher.cpp +++ b/apps/opencs/model/world/commanddispatcher.cpp @@ -137,7 +137,7 @@ std::vector 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 modifyData; std::unique_ptr modifyCell; - QAbstractItemModel *model(nullptr); - QModelIndex index; + QAbstractItemModel* sourceModel = model; + if (IdTableProxyModel* proxy = dynamic_cast (model)) + sourceModel = proxy->sourceModel(); - if (QAbstractProxyModel *proxy = dynamic_cast (sourceModel)) - { - // Replace proxy with actual model - index = proxy->mapToSource (sourceIndex); - model = proxy->sourceModel(); - } - - if (!model) return; + CSMWorld::IdTable& table = dynamic_cast(*sourceModel); // for getId() + int stateColumn = table.findColumnIndex(Columns::ColumnId_Modification); + QModelIndex stateIndex = table.getModelIndex(table.getId(index.row()), stateColumn); + RecordBase::State state = static_cast (sourceModel->data(stateIndex).toInt()); int columnId = model->data (index, ColumnBase::Role_ColumnId).toInt(); - int stateColumn = dynamic_cast(*model).findColumnIndex(Columns::ColumnId_Modification); - - CSMWorld::IdTable& table = dynamic_cast(*model); // for getId() - QModelIndex stateIndex = table.getModelIndex(table.getId(index.row()), stateColumn); - RecordBase::State state = static_cast (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 (*mDocument.getData().getTableModel(mId)); diff --git a/apps/opencs/model/world/commanddispatcher.hpp b/apps/opencs/model/world/commanddispatcher.hpp index 13724f5dbd..538fd7f188 100644 --- a/apps/opencs/model/world/commanddispatcher.hpp +++ b/apps/opencs/model/world/commanddispatcher.hpp @@ -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: