diff options
author | Wang Chuan <ouchuanm@outlook.com> | 2020-02-26 21:14:50 +0800 |
---|---|---|
committer | Wang Chuan <ouchuanm@outlook.com> | 2020-03-03 01:48:24 +0800 |
commit | 254a56252874b63430701351dcd8c9bef8507353 (patch) | |
tree | a5ef2b04e4c1adb4119312d90f9eb63a2787da1b /src/quick/items/qquickitem.cpp | |
parent | 46162c304195db2376706f2e1a9da2b2c938e97b (diff) |
QQuickItem: prevent endless loop in focus tab chain
Since the commit a18ab2a3822e0d, we promote the [startItem] in focus
tab chain when it is invisible to prevent endless loop. However the
problem still happen if the [startItem] is equal to [firstFromItem]
Fixes it by compare the [current] item with the original start item
Fixes: QTBUG-81510
Change-Id: Iae0207f39e2b8c4fc6ed0cf36f0a855668accfba
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Liang Qi <liang.qi@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r-- | src/quick/items/qquickitem.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 3785abc450..11c1f12e75 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -2568,6 +2568,7 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo bool skip = false; QQuickItem *startItem = item; + QQuickItem *originalStartItem = startItem; // Protect from endless loop: // If we start on an invisible item we will not find it again. // If there is no other item which can become the focus item, we have a forever loop, @@ -2643,7 +2644,12 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo } } from = last; - if (current == startItem && from == firstFromItem) { + // if [from] item is equal to [firstFromItem], means we have traversed one path and + // jump back to parent of the chain, and then we have to check whether we have + // traversed all of the chain (by compare the [current] item with [startItem]) + // Since the [startItem] might be promoted to its parent if it is invisible, + // we still have to check [current] item with original start item + if ((current == startItem || current == originalStartItem) && from == firstFromItem) { // wrapped around, avoid endless loops if (item == contentItem) { qCDebug(DBG_FOCUS) << "QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem"; |