From 0f40b1fb5c3597a265400eefd94a51890077bbb3 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Wed, 6 Feb 2019 10:10:36 +0100 Subject: [PATCH] ClangTools: Fix "Go to next/previous diagnostic" action ...for some corner cases: (1) Prev: If the very first diagnostic is selected, select the very last diagnostic instead of doing nothing. (2) Prev: If the first child diagnostic is selected, select the main diagnostic and not the previous main diagnostic. (3) Next: In case a file path item is selected, select the very first diagnostic for that file path and not the next file path. Change-Id: If5ec573911a92c5cfcc1f49ef26ed4dcf82d034b Reviewed-by: Ivan Donchevskii --- .../clangtools/clangtoolsdiagnosticview.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/plugins/clangtools/clangtoolsdiagnosticview.cpp b/src/plugins/clangtools/clangtoolsdiagnosticview.cpp index 7469aa618b1..07bc7f397f4 100644 --- a/src/plugins/clangtools/clangtoolsdiagnosticview.cpp +++ b/src/plugins/clangtools/clangtoolsdiagnosticview.cpp @@ -152,27 +152,29 @@ void DiagnosticView::goBack() QModelIndex DiagnosticView::getIndex(const QModelIndex &index, Direction direction) const { - QModelIndex parentIndex = index.parent(); + const QModelIndex parentIndex = index.parent(); + QModelIndex followingTopIndex = index; - // Use direct sibling for level 2 and 3 items if possible if (parentIndex.isValid()) { - const QModelIndex followingIndex = index.sibling(index.row() + direction, index.column()); + // Use direct sibling for level 2 and 3 items + const QModelIndex followingIndex = index.sibling(index.row() + direction, 0); if (followingIndex.isValid()) return followingIndex; + + // First/Last level 3 item? Continue on level 2 item. + if (parentIndex.parent().isValid()) + return direction == Previous ? parentIndex : getIndex(parentIndex, direction); + + followingTopIndex = getTopLevelIndex(parentIndex, direction); } - // Last level 3 item? Continue on level 2 item - if (parentIndex.parent().isValid()) - return getIndex(parentIndex, direction); - - // Find following level 2 item - QModelIndex followingTopIndex = getTopLevelIndex(parentIndex.isValid() ? parentIndex : index, - direction); + // Skip top level items without children while (!model()->hasChildren(followingTopIndex)) followingTopIndex = getTopLevelIndex(followingTopIndex, direction); - return model()->index(direction == Next ? 0 : model()->rowCount(followingTopIndex) - 1, - 0, - followingTopIndex); + + // Select first/last level 2 item + const int row = direction == Next ? 0 : model()->rowCount(followingTopIndex) - 1; + return model()->index(row, 0, followingTopIndex); } QModelIndex DiagnosticView::getTopLevelIndex(const QModelIndex &index, Direction direction) const @@ -180,7 +182,8 @@ QModelIndex DiagnosticView::getTopLevelIndex(const QModelIndex &index, Direction QModelIndex following = index.sibling(index.row() + direction, 0); if (following.isValid()) return following; - return model()->index(direction == Next ? 0 : model()->rowCount(index) - 1, 0); + const int row = direction == Next ? 0 : model()->rowCount() - 1; + return model()->index(row, 0); } QList DiagnosticView::customActions() const