aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2017-06-23 14:55:59 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2017-08-30 08:20:42 +0000
commitd031e8f7b51a28a9c609f40a6245657f303277f2 (patch)
tree44d82d91661ac925566d962bfca223e58682c70e
parentb4491c46fd9754a1c799978529574037a55a55aa (diff)
QQuickListView: ensure we re-layout when a delegate is placed at the last visible pos
The current implementation would only return true if the added delegate was positioned below the last visible pixel. This caused a problem when the position ended up at exactly the last visible position, since then we would return false, meaning that a re-layout would not be done. Since we use the same calculations several places, this patch will factor it out into lastVisiblePos, and also fix up the places where we test on it. Especially this includes making sure that we set visibleAffected to true if we actually enter the for-loop that adds the item to visibleItems. To make the code more readable (and to ensure that we are consistent), we set it to true inside the for-loop. Task-number: QTBUG-61537 Change-Id: Ie697b5b6d9f4236ee856bde75fd9bc0a07dda7ea Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/quick/items/qquicklistview.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index edfa970035..a6236d9801 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -3208,6 +3208,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch
qreal tempPos = isContentFlowReversed() ? -position()-size() : position();
int index = visibleItems.count() ? mapFromModel(modelIndex) : 0;
+ qreal lastVisiblePos = buffer + displayMarginEnd + tempPos + size();
if (index < 0) {
int i = visibleItems.count() - 1;
@@ -3217,7 +3218,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch
// there are no visible items except items marked for removal
index = visibleItems.count();
} else if (visibleItems.at(i)->index + 1 == modelIndex
- && visibleItems.at(i)->endPosition() <= buffer+displayMarginEnd+tempPos+size()) {
+ && visibleItems.at(i)->endPosition() <= lastVisiblePos) {
// Special case of appending an item to the model.
index = visibleItems.count();
} else {
@@ -3305,11 +3306,8 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch
}
} else {
- qreal to = buffer + displayMarginEnd + tempPos + size();
-
- visibleAffected = count > 0 && pos < to;
-
- for (int i = 0; i < count && pos <= to; ++i) {
+ for (int i = 0; i < count && pos <= lastVisiblePos; ++i) {
+ visibleAffected = true;
FxViewItem *item = 0;
if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i))))
item->index = modelIndex + i;