diff options
author | Sérgio Martins <sergio.martins@kdab.com> | 2014-09-30 13:23:56 +0100 |
---|---|---|
committer | Sérgio Martins <sergio.martins@kdab.com> | 2014-10-10 11:30:06 +0200 |
commit | 2b5e9534450404fba3bdf89f304d0504ae8587dd (patch) | |
tree | 93e869bf0e2e70fdf96c325c45bc5d859a520a2d | |
parent | 9e71faae038de4c41c206f1321da1b37ab6ca8b1 (diff) |
PathView: Fix QML engine thinking currentItem is null when it's not
QML didn't re-evaluate any bindings using currentItem because a
notification was missing.
Change-Id: Icdaa3022e0b01644a060e577d87f011b4ea9fabb
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
-rw-r--r-- | src/quick/items/qquickpathview.cpp | 5 | ||||
-rw-r--r-- | tests/auto/quick/qquickpathview/data/pathview4.qml | 20 | ||||
-rw-r--r-- | tests/auto/quick/qquickpathview/tst_qquickpathview.cpp | 22 |
3 files changed, 47 insertions, 0 deletions
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index 00a5400eb2..825845eca9 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -1987,12 +1987,14 @@ void QQuickPathView::refill() } } + bool currentChanged = false; if (!currentVisible) { d->currentItemOffset = 1.0; if (d->currentItem) { d->updateItem(d->currentItem, 1.0); } else if (!waiting && d->currentIndex >= 0 && d->currentIndex < d->modelCount) { if ((d->currentItem = d->getItem(d->currentIndex, d->currentIndex))) { + currentChanged = true; d->updateItem(d->currentItem, 1.0); if (QQuickPathViewAttached *att = d->attached(d->currentItem)) att->setIsCurrentItem(true); @@ -2000,6 +2002,7 @@ void QQuickPathView::refill() } } else if (!waiting && !d->currentItem) { if ((d->currentItem = d->getItem(d->currentIndex, d->currentIndex))) { + currentChanged = true; d->currentItem->setFocus(true); if (QQuickPathViewAttached *att = d->attached(d->currentItem)) att->setIsCurrentItem(true); @@ -2019,6 +2022,8 @@ void QQuickPathView::refill() d->releaseItem(d->itemCache.takeLast()); d->inRefill = false; + if (currentChanged) + emit currentItemChanged(); } void QQuickPathView::modelUpdated(const QQmlChangeSet &changeSet, bool reset) diff --git a/tests/auto/quick/qquickpathview/data/pathview4.qml b/tests/auto/quick/qquickpathview/data/pathview4.qml new file mode 100644 index 0000000000..c42986d5a3 --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/pathview4.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 + +Item { + id: root + property bool currentItemIsNull: view.currentItem === null + + PathView { + id: view + objectName: "view" + model: testModel + delegate: Item {} + + path: Path { + PathLine { + y: 0 + x: 0 + } + } + } +} diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index fd6dc4da60..0e9994899f 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -90,6 +90,7 @@ private slots: void pathview2(); void pathview3(); void initialCurrentIndex(); + void initialCurrentItem(); void insertModel_data(); void insertModel(); void removeModel_data(); @@ -237,6 +238,27 @@ void tst_QQuickPathView::items() QCOMPARE(pathview->highlightItem()->position() + offset, start); } +void tst_QQuickPathView::initialCurrentItem() +{ + QScopedPointer<QQuickView> window(createView()); + + QaimModel model; + model.addItem("Jules", "12345"); + model.addItem("Vicent", "2345"); + model.addItem("Marvin", "54321"); + + QQmlContext *ctxt = window->rootContext(); + ctxt->setContextProperty("testModel", &model); + + window->setSource(testFileUrl("pathview4.qml")); + qApp->processEvents(); + + QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view"); + QVERIFY(pathview != 0); + QVERIFY(pathview->currentIndex() != -1); + QVERIFY(!window->rootObject()->property("currentItemIsNull").toBool()); +} + void tst_QQuickPathView::pathview2() { QQmlEngine engine; |