diff --git a/qt/widgets/common/src/Batch/JobTreeView.cpp b/qt/widgets/common/src/Batch/JobTreeView.cpp index 1ccc2e72cbc1534854d0834c407005cab8eb4eaa..558b852cf808fb4f2f54ab344781687edf591e7f 100644 --- a/qt/widgets/common/src/Batch/JobTreeView.cpp +++ b/qt/widgets/common/src/Batch/JobTreeView.cpp @@ -506,14 +506,22 @@ QModelIndex JobTreeView::applyNavigationResult(QtTreeCursorNavigationResult const &result) { auto shouldMakeNewRowBelow = result.first; if (shouldMakeNewRowBelow) { + // `newCellIndex` is the model index of the cell in the new row with a column which matches + // the column currently selected by the user. To correctly get the RowLocation we need the + // model index of the first cell in the new row. auto newCellIndex = m_adaptedMainModel.appendEmptySiblingRow( mapToMainModel(fromFilteredModel(result.second))); auto newRowIndex = fromMainModel(firstCellOnRowOf(newCellIndex.untyped())); + + // Resetting the filter ensures that the new row is visible and has a corresponding index in + // the filtered model. resetFilter(); - auto newRowLocation = rowLocation().atIndex(newRowIndex); + auto newRowLocation = rowLocation().atIndex(newRowIndex); m_notifyee->notifyRowInserted(newRowLocation); + // The subscriber is entitled to remove the row at `newRowIndex` when we call + // `notifyRowInserted` hence we have to assume they did and try to get the index again. auto maybeIndexOfNewRow = rowLocation().indexIfExistsAt(newRowLocation); if (maybeIndexOfNewRow.is_initialized()) { return expanded(mapToFilteredModel(maybeIndexOfNewRow.get())).untyped();