aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-11-22 17:26:49 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-23 08:48:41 +0100
commit371b2f6947779272494b34ec44445aaad0613756 (patch)
treef14f88910dfbceade13201ce2df3633fd433de1a /src
parent54a547549cb095ec31168ae529458e539a43922d (diff)
Fix PathView insertion/removal/move item offset
Fix item positioning post model changes and add auto tests. Also fixes crash when inserting items before currentIndex, causing offset to increase beyond item count. Task-number: TBUG-22785 Change-Id: I17000ba497a190554c8b137a72b7e6551e8a0e56 Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/qquickpathview.cpp43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/declarative/items/qquickpathview.cpp b/src/declarative/items/qquickpathview.cpp
index f7e58eae6f..1963307a1e 100644
--- a/src/declarative/items/qquickpathview.cpp
+++ b/src/declarative/items/qquickpathview.cpp
@@ -843,6 +843,10 @@ void QQuickPathView::setHighlightRangeMode(HighlightRangeMode mode)
return;
d->highlightRangeMode = mode;
d->haveHighlightRange = d->highlightRangeMode != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
+ if (d->haveHighlightRange) {
+ d->regenerate();
+ d->snapToCurrent();
+ }
emit highlightRangeModeChanged();
}
@@ -1502,10 +1506,7 @@ void QQuickPathView::modelUpdated(const QDeclarativeChangeSet &changeSet, bool r
int moveOffset;
bool currentChanged = false;
bool changedOffset = false;
- bool removed = false;
- bool inserted = false;
foreach (const QDeclarativeChangeSet::Remove &r, changeSet.removes()) {
- removed = true;
if (moveId == -1 && d->currentIndex >= r.index + r.count) {
d->currentIndex -= r.count;
currentChanged = true;
@@ -1525,32 +1526,36 @@ void QQuickPathView::modelUpdated(const QDeclarativeChangeSet &changeSet, bool r
}
if (r.index > d->currentIndex) {
- if (d->offset >= r.count) {
- changedOffset = true;
- d->offset -= r.count;
- d->offsetAdj -= r.count;
- }
+ changedOffset = true;
+ d->offset -= r.count;
+ d->offsetAdj -= r.count;
}
d->modelCount -= r.count;
}
foreach (const QDeclarativeChangeSet::Insert &i, changeSet.inserts()) {
- inserted = true;
if (d->modelCount) {
if (moveId == -1 && i.index <= d->currentIndex) {
d->currentIndex += i.count;
currentChanged = true;
- } else if (d->offset != 0) {
+ } else {
if (moveId != -1 && moveId == i.moveId) {
d->currentIndex = i.index + moveOffset;
currentChanged = true;
}
- d->offset += i.count;
- d->offsetAdj += i.count;
+ if (i.index > d->currentIndex) {
+ d->offset += i.count;
+ d->offsetAdj += i.count;
+ changedOffset = true;
+ }
}
}
d->modelCount += i.count;
}
+ d->offset = qmlMod(d->offset, d->modelCount);
+ if (d->offset < 0)
+ d->offset += d->modelCount;
+
d->itemCache += d->items;
d->items.clear();
@@ -1560,22 +1565,14 @@ void QQuickPathView::modelUpdated(const QDeclarativeChangeSet &changeSet, bool r
d->offset = 0;
changedOffset = true;
d->tl.reset(d->moveOffset);
- } else if (removed) {
- d->regenerate();
+ } else {
if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QQuickPathView::StrictlyEnforceRange) {
- qreal targetOffset = qmlMod(d->modelCount - d->currentIndex, d->modelCount);
- if (targetOffset != d->offset)
- d->tl.set(d->moveOffset, targetOffset);
+ d->offset = qmlMod(d->modelCount - d->currentIndex, d->modelCount);
+ changedOffset = true;
}
- } else if (inserted) {
d->firstIndex = -1;
d->updateMappedRange();
d->scheduleLayout();
- if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QQuickPathView::StrictlyEnforceRange) {
- qreal targetOffset = qmlMod(d->modelCount - d->currentIndex, d->modelCount);
- if (targetOffset != d->offset)
- d->tl.set(d->moveOffset, targetOffset);
- }
}
if (changedOffset)
emit offsetChanged();