summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-27 14:50:42 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-12-10 16:45:49 +0000
commit69c7e95da101d4d66d25c4850f3591d4ccd2bbc1 (patch)
tree336225f5f1e8c7dfa44ed4b7cc6a6b1978c45359
parenta9436b597916d5619cbbbbd103bc482ddaf4359a (diff)
downloadqtquickcontrols-69c7e95da101d4d66d25c4850f3591d4ccd2bbc1.tar.gz
Insert before next item when it exists
Something is off about the way the last child of previous item is calculated, but we can work-around that by just using the next element when it exist. In the case there isn't a next element, we will hit the fallback in 'last child of previous' and insert at the end anyway. Fixes: QTBUG-66062 Change-Id: Iced69d52c4587434ffdbb09b08b3441289f34eba Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r--src/controls/Private/qquicktreemodeladaptor.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/controls/Private/qquicktreemodeladaptor.cpp b/src/controls/Private/qquicktreemodeladaptor.cpp
index d2ed42b2..287b388f 100644
--- a/src/controls/Private/qquicktreemodeladaptor.cpp
+++ b/src/controls/Private/qquicktreemodeladaptor.cpp
@@ -362,8 +362,15 @@ void QQuickTreeModelAdaptor1::showModelChildItems(const TreeItem &parentItem, in
if (start == 0) {
startIdx = rowIdx;
} else {
- const QModelIndex &prevSiblingIdx = m_model->index(start - 1, 0, parentIndex);
- startIdx = lastChildIndex(prevSiblingIdx) + 1;
+ // Prefer to insert before next sibling instead of after last child of previous, as
+ // the latter is potentially buggy, see QTBUG-66062
+ const QModelIndex &nextSiblingIdx = m_model->index(end + 1, 0, parentIndex);
+ if (nextSiblingIdx.isValid()) {
+ startIdx = itemIndex(nextSiblingIdx);
+ } else {
+ const QModelIndex &prevSiblingIdx = m_model->index(start - 1, 0, parentIndex);
+ startIdx = lastChildIndex(prevSiblingIdx) + 1;
+ }
}
int rowDepth = rowIdx == 0 ? 0 : parentItem.depth + 1;