From 50855fc104d810fd37639f4b71146204e43f43d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Mon, 16 Apr 2012 23:12:49 +0200 Subject: [PATCH] Arbitration: give the focus on the first search result after a search --- qt/arbitration_widget.cpp | 14 ++++++++++++-- qt/arbitration_widget.h | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/qt/arbitration_widget.cpp b/qt/arbitration_widget.cpp index 7c305fb..10a98f9 100644 --- a/qt/arbitration_widget.cpp +++ b/qt/arbitration_widget.cpp @@ -470,6 +470,9 @@ void ArbitrationWidget::searchResults() { m_assignmentsWidget->assignDefaultMasterMove(); } + + // Set the focus to the first result + selectAndFocusResult(0, false); } @@ -558,8 +561,15 @@ void ArbitrationWidget::checkWord() lineEditCoords->clear(); // Show the new result and select it - const QModelIndex &index = - m_proxyResultsModel->mapFromSource(m_resultsModel->index(rowNum, 0)); + selectAndFocusResult(rowNum); +} + + +void ArbitrationWidget::selectAndFocusResult(int iRowNum, bool logical) +{ + QModelIndex index = m_resultsModel->index(iRowNum, 0); + if (logical) + index = m_proxyResultsModel->mapFromSource(index); treeViewResults->scrollTo(index); treeViewResults->selectionModel()->clearSelection(); treeViewResults->selectionModel()->select(index, diff --git a/qt/arbitration_widget.h b/qt/arbitration_widget.h index c6dd4b7..e78adbd 100644 --- a/qt/arbitration_widget.h +++ b/qt/arbitration_widget.h @@ -120,6 +120,14 @@ private: /// Clear search results void clearResults(); + /** + * Give the focus to the result corresponding to the given row number. + * If logical is true, the row number is adapted to respect a possible + * user-defined ordering of the table, otherwise it is used unmodified + * (in the latter case, the row number corresponds to visible rows). + */ + void selectAndFocusResult(int iRowNum, bool logical = true); + /** * Add the given move to the results list. * Return the row number of the added item.