Mercurial > hg > syntilista
comparison src/main.cpp @ 209:6f404158ce8c
Get rid of tiny bit of code duplication.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Nov 2017 11:27:15 +0200 |
parents | 2438ea2611f9 |
children | 02aae61e807e |
comparison
equal
deleted
inserted
replaced
208:e6a2658ae096 | 209:6f404158ce8c |
---|---|
947 if (currPerson.id >= 0) | 947 if (currPerson.id >= 0) |
948 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason); | 948 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason); |
949 } | 949 } |
950 | 950 |
951 | 951 |
952 void SyntilistaMainWindow::selectRowDelta(const int delta) | |
953 { | |
954 QItemSelectionModel *sel = ui->tableview_People->selectionModel(); | |
955 int prow = sel->currentIndex().row(); | |
956 int nrow = prow + delta; | |
957 if (nrow < 0) | |
958 nrow = 0; | |
959 else | |
960 if (nrow >= model_People->rowCount()) | |
961 nrow = model_People->rowCount() - 1; | |
962 | |
963 if (nrow != prow) | |
964 { | |
965 sel->setCurrentIndex(model_People->index(nrow, 0), | |
966 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows); | |
967 } | |
968 } | |
969 | |
970 | |
952 void SyntilistaMainWindow::selectRowPrev() | 971 void SyntilistaMainWindow::selectRowPrev() |
953 { | 972 { |
954 QItemSelectionModel *sel = ui->tableview_People->selectionModel(); | 973 selectRowDelta(-1); |
955 int row = sel->currentIndex().row() - 1; | |
956 if (row < 0) | |
957 row = 0; | |
958 | |
959 sel->setCurrentIndex(model_People->index(row, 0), | |
960 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows); | |
961 } | 974 } |
962 | 975 |
963 | 976 |
964 void SyntilistaMainWindow::selectRowNext() | 977 void SyntilistaMainWindow::selectRowNext() |
965 { | 978 { |
966 QItemSelectionModel *sel = ui->tableview_People->selectionModel(); | 979 selectRowDelta(1); |
967 int row = sel->currentIndex().row() + 1; | |
968 if (row >= model_People->rowCount()) | |
969 row = model_People->rowCount() - 1; | |
970 | |
971 sel->setCurrentIndex(model_People->index(row, 0), | |
972 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows); | |
973 } | 980 } |
974 | 981 |
975 | 982 |
976 // | 983 // |
977 // Update visible person list/query based on the current | 984 // Update visible person list/query based on the current |