forked from qt-creator/qt-creator
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 <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -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<QAction *> DiagnosticView::customActions() const
|
||||
|
Reference in New Issue
Block a user