Arbitration: give the focus on the first search result after a search

This commit is contained in:
Olivier Teulière 2012-04-16 23:12:49 +02:00
parent 27a7cc6846
commit 50855fc104
2 changed files with 20 additions and 2 deletions

View file

@ -470,6 +470,9 @@ void ArbitrationWidget::searchResults()
{ {
m_assignmentsWidget->assignDefaultMasterMove(); m_assignmentsWidget->assignDefaultMasterMove();
} }
// Set the focus to the first result
selectAndFocusResult(0, false);
} }
@ -558,8 +561,15 @@ void ArbitrationWidget::checkWord()
lineEditCoords->clear(); lineEditCoords->clear();
// Show the new result and select it // Show the new result and select it
const QModelIndex &index = selectAndFocusResult(rowNum);
m_proxyResultsModel->mapFromSource(m_resultsModel->index(rowNum, 0)); }
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->scrollTo(index);
treeViewResults->selectionModel()->clearSelection(); treeViewResults->selectionModel()->clearSelection();
treeViewResults->selectionModel()->select(index, treeViewResults->selectionModel()->select(index,

View file

@ -120,6 +120,14 @@ private:
/// Clear search results /// Clear search results
void clearResults(); 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. * Add the given move to the results list.
* Return the row number of the added item. * Return the row number of the added item.