summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-02-08 09:28:00 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-02-08 12:31:02 +0100
commitfbfacd33be482fa3cf0aa5cffaf7006d538a2f92 (patch)
tree92da72786b3740e37004623612c4fc1c9640d30f /src/widgets/itemviews
parentc1f4286a5cbc1794fe7be5bdbbd6a0bf29ef84d4 (diff)
parent74e04d6ace7aa949db97ae2e46c38a4dc0d4d36a (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts: src/android/templates/AndroidManifest.xml src/network/ssl/qsslsocket_mac.cpp src/widgets/styles/qstylesheetstyle.cpp tests/auto/corelib/kernel/qtimer/BLACKLIST tests/auto/testlib/selftests/blacklisted/tst_blacklisted.cpp tests/auto/testlib/selftests/expected_blacklisted.lightxml tests/auto/testlib/selftests/expected_blacklisted.tap tests/auto/testlib/selftests/expected_blacklisted.teamcity tests/auto/testlib/selftests/expected_blacklisted.txt tests/auto/testlib/selftests/expected_blacklisted.xml tests/auto/testlib/selftests/expected_blacklisted.xunitxml tests/auto/testlib/selftests/expected_float.tap tests/auto/testlib/selftests/expected_float.teamcity tests/auto/testlib/selftests/expected_float.txt tests/auto/testlib/selftests/expected_float.xunitxml Done-With: Christian Ehrlicher <ch.ehrlicher@gmx.de> Done-With: Edward Welbourne <edward.welbourne@qt.io> Done-With: Timur Pocheptsov <timur.pocheptsov@qt.io> Change-Id: If93cc432a56ae3ac1b6533d0028e4dc497415a52
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qlistview.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 143b243091..e7b2aaec29 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -1100,19 +1100,45 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie
Q_D(QListView);
Q_UNUSED(modifiers);
- QModelIndex current = currentIndex();
- if (!current.isValid()) {
+ auto findAvailableRowBackward = [d](int row) {
+ while (row >= 0 && d->isHiddenOrDisabled(row))
+ --row;
+ return row;
+ };
+
+ auto findAvailableRowForward = [d](int row) {
int rowCount = d->model->rowCount(d->root);
if (!rowCount)
- return QModelIndex();
- int row = 0;
+ return -1;
while (row < rowCount && d->isHiddenOrDisabled(row))
++row;
if (row >= rowCount)
+ return -1;
+ return row;
+ };
+
+ QModelIndex current = currentIndex();
+ if (!current.isValid()) {
+ int row = findAvailableRowForward(0);
+ if (row == -1)
return QModelIndex();
return d->model->index(row, d->column, d->root);
}
+ if ((d->flow == LeftToRight && cursorAction == MoveLeft) ||
+ (d->flow == TopToBottom && (cursorAction == MoveUp || cursorAction == MovePrevious))) {
+ const int row = findAvailableRowBackward(current.row() - 1);
+ if (row == -1)
+ return current;
+ return d->model->index(row, d->column, d->root);
+ } else if ((d->flow == LeftToRight && cursorAction == MoveRight) ||
+ (d->flow == TopToBottom && (cursorAction == MoveDown || cursorAction == MoveNext))) {
+ const int row = findAvailableRowForward(current.row() + 1);
+ if (row == -1)
+ return current;
+ return d->model->index(row, d->column, d->root);
+ }
+
const QRect initialRect = rectForIndex(current);
QRect rect = initialRect;
if (rect.isEmpty()) {