From 615069e0f1d3904d84db8ac36fcfd6e12e87ccd3 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Aug 2021 10:17:33 +1000 Subject: [PATCH] Fix crash when holding tab key in some circumstances Fixes #44669 --- src/gui/locator/qgslocatorwidget.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/locator/qgslocatorwidget.cpp b/src/gui/locator/qgslocatorwidget.cpp index 657fe5a833b2..c6ae515d48fc 100644 --- a/src/gui/locator/qgslocatorwidget.cpp +++ b/src/gui/locator/qgslocatorwidget.cpp @@ -388,16 +388,24 @@ void QgsLocatorResultsView::recalculateSize() void QgsLocatorResultsView::selectNextResult() { + const int rowCount = model()->rowCount( QModelIndex() ); + if ( rowCount == 0 ) + return; + int nextRow = currentIndex().row() + 1; - nextRow = nextRow % model()->rowCount( QModelIndex() ); + nextRow = nextRow % rowCount; setCurrentIndex( model()->index( nextRow, 0 ) ); } void QgsLocatorResultsView::selectPreviousResult() { + const int rowCount = model()->rowCount( QModelIndex() ); + if ( rowCount == 0 ) + return; + int previousRow = currentIndex().row() - 1; if ( previousRow < 0 ) - previousRow = model()->rowCount( QModelIndex() ) - 1; + previousRow = rowCount - 1; setCurrentIndex( model()->index( previousRow, 0 ) ); }