| 286 | } |
| 287 | |
| 288 | void ItemViewWalker::selectIndex(Direction direction) |
| 289 | { |
| 290 | if (!m_selectionModel) { |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | const QModelIndexList list = m_selectionModel->selectedRows(); |
| 295 | |
| 296 | constexpr auto selectionCommand = QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows; |
| 297 | |
| 298 | const QModelIndex currentIndex = list.value(0); |
| 299 | if (!currentIndex.isValid()) { |
| 300 | /// no selection yet, just select the first |
| 301 | const QModelIndex firstIndex = m_selectionModel->model()->index(0, 0); |
| 302 | m_selectionModel->setCurrentIndex(firstIndex, selectionCommand); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | const int nextRow = currentIndex.row() + (direction == NextIndex ? 1 : -1); |
| 307 | const QModelIndex nextIndex = currentIndex.sibling(nextRow, 0); |
| 308 | if (!nextIndex.isValid()) { |
| 309 | return; /// never invalidate the selection |
| 310 | } |
| 311 | |
| 312 | m_selectionModel->setCurrentIndex(nextIndex, selectionCommand); |
| 313 | } |
| 314 | |
| 315 | ProblemsView::ProblemsView(QWidget* parent) |
| 316 | : QWidget(parent) |