aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickpathview.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-05-29 15:45:15 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-31 02:23:00 +0200
commit447e5acb880ebda498891623dc4009984cb73bc6 (patch)
tree870885e9fc51779c81df11c962cb34d01f2253d6 /src/quick/items/qquickpathview.cpp
parenta8c137f0e6eabb768f156134b06e022d44993ce2 (diff)
Reset the PathView currentIndex to 0 when all items are removed.
The default currentIndex for an empty PathView is 0, and except when there is no model or an empty model setCurrentIndex won't allow a currentIndex outside the valid index range for the model. This changes the wrapping for negative numbers in setCurrentIndex so that it is consistent with decrementCurrentIndex and forces the currentIndex to 0 if there are no model items. Task-number: QTBUG-21316 Change-Id: Id4d4d78e9832d05baf8a9d148e7f81ee89c9bc61 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/quick/items/qquickpathview.cpp')
-rw-r--r--src/quick/items/qquickpathview.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp
index 08d20ac00c..bf4f9960ce 100644
--- a/src/quick/items/qquickpathview.cpp
+++ b/src/quick/items/qquickpathview.cpp
@@ -689,8 +689,9 @@ int QQuickPathView::currentIndex() const
void QQuickPathView::setCurrentIndex(int idx)
{
Q_D(QQuickPathView);
- if (d->model && d->modelCount)
- idx = qAbs(idx % d->modelCount);
+ idx = d->modelCount
+ ? ((idx % d->modelCount) + d->modelCount) % d->modelCount
+ : 0;
if (d->model && (idx != d->currentIndex || !d->currentItem)) {
if (d->currentItem) {
if (QQuickPathViewAttached *att = d->attached(d->currentItem))
@@ -746,13 +747,8 @@ void QQuickPathView::incrementCurrentIndex()
void QQuickPathView::decrementCurrentIndex()
{
Q_D(QQuickPathView);
- if (d->model && d->modelCount) {
- int idx = currentIndex()-1;
- if (idx < 0)
- idx = d->modelCount - 1;
- d->moveDirection = QQuickPathViewPrivate::Negative;
- setCurrentIndex(idx);
- }
+ d->moveDirection = QQuickPathViewPrivate::Negative;
+ setCurrentIndex(currentIndex()-1);
}
/*!
@@ -1733,7 +1729,6 @@ void QQuickPathView::modelUpdated(const QQuickChangeSet &changeSet, bool reset)
currentChanged = true;
} else if (moveId == -1 && d->currentIndex >= r.index && d->currentIndex < r.index + r.count) {
// current item has been removed.
- d->currentIndex = qMin(r.index, d->modelCount - r.count - 1);
if (r.isMove()) {
moveId = r.moveId;
moveOffset = d->currentIndex - r.index;
@@ -1743,6 +1738,7 @@ void QQuickPathView::modelUpdated(const QQuickChangeSet &changeSet, bool reset)
d->releaseItem(d->currentItem);
d->currentItem = 0;
}
+ d->currentIndex = qMin(r.index, d->modelCount - r.count - 1);
currentChanged = true;
}
@@ -1776,6 +1772,8 @@ void QQuickPathView::modelUpdated(const QQuickChangeSet &changeSet, bool reset)
d->offset = qmlMod(d->offset, d->modelCount);
if (d->offset < 0)
d->offset += d->modelCount;
+ if (d->currentIndex == -1)
+ d->currentIndex = d->calcCurrentIndex();
d->itemCache += d->items;
d->items.clear();
@@ -1832,7 +1830,7 @@ void QQuickPathView::movementEnding()
// find the item closest to the snap position
int QQuickPathViewPrivate::calcCurrentIndex()
{
- int current = -1;
+ int current = 0;
if (modelCount && model && items.count()) {
offset = qmlMod(offset, modelCount);
if (offset < 0)