diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-01-21 15:03:35 +1000 |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-01-21 15:03:35 +1000 |
commit | c3dd455b03a6c03011e2446f69fc262230e91639 (patch) | |
tree | 4400e080dc56d85012f063eea7178681eda505b4 | |
parent | 8c3086aa36b51a9731fce8eb8146b33ab8196aed (diff) | |
download | qt4-tools-c3dd455b03a6c03011e2446f69fc262230e91639.tar.gz |
positionViewAtIndex can fail when positioned near end of list.
We positioned the view beyond the bounds, which in some cases resulted
in only one item being created. Combined with a bug in the bounds
fixup very many items were created.
Task-number: QT-4441
Reviewed-by: Michael Brasser
4 files changed, 18 insertions, 5 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 4aaec38d4d..dc7536e460 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -299,7 +299,7 @@ void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal timeline.move(data.move, maxExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); } else { - timeline.set(data.move, minExtent); + timeline.set(data.move, maxExtent); } } vTime = timeline.time(); diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 89d74930d1..4c04a6b66b 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -2165,6 +2165,7 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) if (d->layoutScheduled) d->layout(); qreal pos = d->position(); + qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent(); FxGridItem *item = d->visibleItem(index); if (!item) { int itemPos = d->rowPosAt(index); @@ -2172,7 +2173,7 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) QList<FxGridItem*> oldVisible = d->visibleItems; d->visibleItems.clear(); d->visibleIndex = index - index % d->columns; - d->setPosition(itemPos); + d->setPosition(qMin(qreal(itemPos), maxExtent)); // now release the reference to all the old visible items. for (int i = 0; i < oldVisible.count(); ++i) d->releaseItem(oldVisible.at(i)); @@ -2202,7 +2203,6 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) if (itemPos < pos) pos = itemPos; } - qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent(); pos = qMin(pos, maxExtent); qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent(); pos = qMax(pos, minExtent); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index b4fd57134c..b4b3fa70cb 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -2603,6 +2603,7 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) d->layout(); qreal pos = d->position(); FxListItem *item = d->visibleItem(index); + qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent(); if (!item) { int itemPos = d->positionAt(index); // save the currently visible items in case any of them end up visible again @@ -2610,7 +2611,7 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) d->visibleItems.clear(); d->visiblePos = itemPos; d->visibleIndex = index; - d->setPosition(itemPos); + d->setPosition(qMin(qreal(itemPos), maxExtent)); // now release the reference to all the old visible items. for (int i = 0; i < oldVisible.count(); ++i) d->releaseItem(oldVisible.at(i)); @@ -2640,7 +2641,6 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) if (itemPos < pos) pos = itemPos; } - qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent(); pos = qMin(pos, maxExtent); qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent(); pos = qMax(pos, minExtent); diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index b3430109ba..9b6f04c826 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -1329,6 +1329,19 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(item->y(), i*20.); } + // Position at End using last index + listview->positionViewAtIndex(model.count()-1, QDeclarativeListView::End); + QTRY_COMPARE(listview->contentY(), 480.); + + // Confirm items positioned correctly + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); + for (int i = 24; i < model.count(); ++i) { + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.); + } + // Position at End listview->positionViewAtIndex(20, QDeclarativeListView::End); QTRY_COMPARE(listview->contentY(), 100.); |