From b9c46e204a3fe1b3bcab44e868dc8bbfcfb96b93 Mon Sep 17 00:00:00 2001 From: Edward Brown <edward.brown@stfc.ac.uk> Date: Wed, 23 May 2018 12:10:02 +0100 Subject: [PATCH] Added expositionary comments to JobTreeView. Re #22263 --- qt/widgets/common/src/Batch/JobTreeView.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qt/widgets/common/src/Batch/JobTreeView.cpp b/qt/widgets/common/src/Batch/JobTreeView.cpp index 1ccc2e72cbc..558b852cf80 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(); -- GitLab