Skip to content
Permalink
Browse files

Always select the best result by default, even if good results are

slow to fetch
  • Loading branch information
nyalldawson committed May 17, 2017
1 parent 56c8baa commit 11036e4d058cea5cf44ec432632a8c78f0db8a8d
Showing with 11 additions and 1 deletion.
  1. +10 −1 src/gui/locator/qgslocatorwidget.cpp
  2. +1 −0 src/gui/locator/qgslocatorwidget.h
@@ -145,13 +145,15 @@ bool QgsLocatorWidget::eventFilter( QObject *obj, QEvent *event )
case Qt::Key_PageUp:
case Qt::Key_PageDown:
showList();
mHasSelectedResult = true;
QgsApplication::sendEvent( mResultsView, event );
return true;
case Qt::Key_Home:
case Qt::Key_End:
if ( keyEvent->modifiers() & Qt::ControlModifier )
{
showList();
mHasSelectedResult = true;
QgsApplication::sendEvent( mResultsView, event );
return true;
}
@@ -164,15 +166,21 @@ bool QgsLocatorWidget::eventFilter( QObject *obj, QEvent *event )
mResultsContainer->hide();
return true;
case Qt::Key_Tab:
mHasSelectedResult = true;
mResultsView->selectNextResult();
return true;
case Qt::Key_Backtab:
mHasSelectedResult = true;
mResultsView->selectPreviousResult();
return true;
default:
break;
}
}
else if ( obj == mResultsView && event->type() == QEvent::MouseButtonPress )
{
mHasSelectedResult = true;
}
else if ( event->type() == QEvent::FocusOut && ( obj == mLineEdit || obj == mResultsContainer || obj == mResultsView ) )
{
if ( !mLineEdit->hasFocus() && !mResultsContainer->hasFocus() && !mResultsView->hasFocus() )
@@ -193,7 +201,7 @@ bool QgsLocatorWidget::eventFilter( QObject *obj, QEvent *event )

void QgsLocatorWidget::addResult( const QgsLocatorResult &result )
{
bool selectFirst = mProxyModel->rowCount() == 0;
bool selectFirst = !mHasSelectedResult || mProxyModel->rowCount() == 0;
mLocatorModel->addResult( result );
if ( selectFirst )
mResultsView->setCurrentIndex( mProxyModel->index( 1, 0 ) );
@@ -213,6 +221,7 @@ void QgsLocatorWidget::updateResults( const QString &text )
}
else
{
mHasSelectedResult = false;
mLocatorModel->clear();
if ( !text.isEmpty() )
{
@@ -98,6 +98,7 @@ class GUI_EXPORT QgsLocatorWidget : public QWidget

QString mNextRequestedString;
bool mHasQueuedRequest = false;
bool mHasSelectedResult = false;
QTimer mPopupTimer;

void updateResults( const QString &text );

0 comments on commit 11036e4

Please sign in to comment.