disconnect(d->model, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(createdItem(int,QQuickItem*)));
for (int i=0; i<d->items.count(); i++){
QQuickItem *p = d->items[i];
- d->model->release(p);
+ d->releaseItem(p);
}
d->items.clear();
}
if (d->modelCount) {
if (moveId == -1 && i.index <= d->currentIndex) {
d->currentIndex += i.count;
+ currentChanged = true;
} else if (d->offset != 0) {
- if (moveId != -1 && moveId == i.moveId)
+ if (moveId != -1 && moveId == i.moveId) {
d->currentIndex = i.index + moveOffset;
+ currentChanged = true;
+ }
d->offset += i.count;
d->offsetAdj += i.count;
}
d->tl.reset(d->moveOffset);
} else if (removed) {
d->regenerate();
- d->updateCurrent();
- if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QQuickPathView::StrictlyEnforceRange)
- d->snapToCurrent();
+ 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);
+ }
} 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();
qreal targetOffset = qmlMod(modelCount - currentIndex, modelCount);
+ if (offset == targetOffset)
+ return;
+
moveReason = Other;
offsetAdj = 0.0;
tl.reset(moveOffset);
void changePreferredHighlight();
void missingPercent();
void creationContext();
+ void currentOffsetOnInsertion();
private:
QQuickView *createView();
QCOMPARE(obj->dragMargin(), 0.);
QCOMPARE(obj->count(), 0);
QCOMPARE(obj->pathItemCount(), -1);
+
+ delete obj;
}
void tst_QQuickPathView::items()
QCOMPARE(obj->dragMargin(), 0.);
QCOMPARE(obj->count(), 8);
QCOMPARE(obj->pathItemCount(), 10);
+
+ delete obj;
}
void tst_QQuickPathView::pathview3()
QCOMPARE(obj->dragMargin(), 24.);
QCOMPARE(obj->count(), 8);
QCOMPARE(obj->pathItemCount(), 4);
+
+ delete obj;
}
void tst_QQuickPathView::path()
QCOMPARE(cubic->control1Y(), 90.);
QCOMPARE(cubic->control2X(), 210.);
QCOMPARE(cubic->control2Y(), 90.);
+
+ delete obj;
}
void tst_QQuickPathView::dataModel()
QCOMPARE(item->property("text").toString(), QString("Hello!"));
}
+// QTBUG-21320
+void tst_QQuickPathView::currentOffsetOnInsertion()
+{
+ QQuickView *canvas = createView();
+ canvas->show();
+
+ TestModel model;
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathline.qml")));
+ qApp->processEvents();
+
+ QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
+ QVERIFY(pathview != 0);
+
+ pathview->setPreferredHighlightBegin(0.5);
+ pathview->setPreferredHighlightEnd(0.5);
+
+ QCOMPARE(pathview->count(), model.count());
+
+ model.addItem("item0", "0");
+
+ QCOMPARE(pathview->count(), model.count());
+
+ QQuickRectangle *item = 0;
+ QTRY_VERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 0));
+
+ QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path());
+ QVERIFY(path);
+
+ QPointF start = path->pointAt(0.5);
+ start = QPointF(qRound(start.x()), qRound(start.y()));
+ QPointF offset;//Center of item is at point, but pos is from corner
+ offset.setX(item->width()/2);
+ offset.setY(item->height()/2);
+ QCOMPARE(item->pos() + offset, start);
+
+ QSignalSpy currentIndexSpy(pathview, SIGNAL(currentIndexChanged()));
+
+ // insert an item at the beginning
+ model.insertItem(0, "item1", "1");
+ qApp->processEvents();
+
+ QCOMPARE(currentIndexSpy.count(), 1);
+
+ // currentIndex is now 1
+ QVERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 1));
+
+ // verify that current item (item 1) is still at offset 0.5
+ QCOMPARE(item->pos() + offset, start);
+
+ // insert another item at the beginning
+ model.insertItem(0, "item2", "2");
+ qApp->processEvents();
+
+ QCOMPARE(currentIndexSpy.count(), 2);
+
+ // currentIndex is now 2
+ QVERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 2));
+
+ // verify that current item (item 2) is still at offset 0.5
+ QCOMPARE(item->pos() + offset, start);
+
+ // verify that remove before current maintains current item
+ model.removeItem(0);
+ qApp->processEvents();
+
+ QCOMPARE(currentIndexSpy.count(), 3);
+
+ // currentIndex is now 1
+ QVERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 1));
+
+ // verify that current item (item 1) is still at offset 0.5
+ QCOMPARE(item->pos() + offset, start);
+
+ delete canvas;
+}
+
QQuickView *tst_QQuickPathView::createView()
{
QQuickView *canvas = new QQuickView(0);