From 2533a40cf26ded5b777aae6b3c49813a044ab735 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 25 May 2012 11:41:17 +1000 Subject: [PATCH] Fix PathView not updating after all items are removed from the model. Always clear the layoutScheduled flag on a refill even if there are no items to create, otherwise future layouts won't be scheduled because it appears one is already pending. Fixes an issue in the dragselection example where items that should have moved to the PathView instead disappeared. Change-Id: I4302b5b43184c697a78f5c09dc3811326e2271ca Reviewed-by: Martin Jones --- src/quick/items/qquickpathview.cpp | 4 +- .../quick/qquicklistview/tst_qquicklistview.cpp | 1 - .../quick/qquickpathview/tst_qquickpathview.cpp | 124 +++++++++++++++++++++ .../quick/qquickpositioners/qquickpositioners.pro | 2 +- tests/auto/quick/shared/util.pri | 2 + tests/auto/quick/shared/viewtestutil.h | 3 +- tests/auto/quick/shared/visualtestutil.h | 6 +- 7 files changed, 137 insertions(+), 5 deletions(-) diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index 1561dbc..08d20ac 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -1573,10 +1573,12 @@ void QQuickPathView::componentComplete() void QQuickPathView::refill() { Q_D(QQuickPathView); + + d->layoutScheduled = false; + if (!d->isValid() || !isComponentComplete()) return; - d->layoutScheduled = false; bool currentVisible = false; // first move existing items and remove items off path diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 2a67405..8d4453a 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 057eb2c..ec863d8 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -63,6 +63,7 @@ using namespace QQuickViewTestUtil; using namespace QQuickVisualTestUtil; +Q_DECLARE_METATYPE(QQuickPathView::HighlightRangeMode) static void initStandardTreeModel(QStandardItemModel *model) { @@ -101,6 +102,8 @@ private slots: void removeModel(); void moveModel_data(); void moveModel(); + void consecutiveModelChanges_data(); + void consecutiveModelChanges(); void path(); void pathMoved(); void setCurrentIndex(); @@ -529,6 +532,127 @@ void tst_QQuickPathView::moveModel() delete canvas; } +void tst_QQuickPathView::consecutiveModelChanges_data() +{ + QTest::addColumn("mode"); + QTest::addColumn >("changes"); + QTest::addColumn("count"); + QTest::addColumn("offset"); + + QTest::newRow("no range - insert after, insert before") + << QQuickPathView::NoHighlightRange + << (QList() + << ListChange::insert(7, 2) + << ListChange::insert(1, 3)) + << 13 + << 6.; + QTest::newRow("no range - remove after, remove before") + << QQuickPathView::NoHighlightRange + << (QList() + << ListChange::remove(6, 2) + << ListChange::remove(1, 3)) + << 3 + << 2.; + + QTest::newRow("no range - remove after, insert before") + << QQuickPathView::NoHighlightRange + << (QList() + << ListChange::remove(5, 2) + << ListChange::insert(1, 3)) + << 9 + << 2.; + + QTest::newRow("no range - insert after, remove before") + << QQuickPathView::NoHighlightRange + << (QList() + << ListChange::insert(6, 2) + << ListChange::remove(1, 3)) + << 7 + << 6.; + + QTest::newRow("no range - insert, remove all, polish, insert") + << QQuickPathView::NoHighlightRange + << (QList() + << ListChange::insert(3, 1) + << ListChange::remove(0, 9) + << ListChange::polish() + << ListChange::insert(0, 3)) + << 3 + << 0.; +} + +void tst_QQuickPathView::consecutiveModelChanges() +{ + QFETCH(QQuickPathView::HighlightRangeMode, mode); + QFETCH(QList, changes); + QFETCH(int, count); + QFETCH(qreal, offset); + + QQuickView *canvas = createView(); + canvas->show(); + + QaimModel model; + model.addItem("Ben", "12345"); + model.addItem("Bohn", "2345"); + model.addItem("Bob", "54321"); + model.addItem("Bill", "4321"); + model.addItem("Jinny", "679"); + model.addItem("Milly", "73378"); + model.addItem("Jimmy", "3535"); + model.addItem("Barb", "9039"); + + QQmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(testFileUrl("pathview0.qml")); + qApp->processEvents(); + + QQuickPathView *pathview = findItem(canvas->rootObject(), "view"); + QVERIFY(pathview != 0); + + pathview->setHighlightRangeMode(mode); + + pathview->setCurrentIndex(4); + if (mode == QQuickPathView::StrictlyEnforceRange) + QTRY_COMPARE(pathview->offset(), 4.0); + else + pathview->setOffset(4); + + for (int i=0; i > items; + for (int j=changes[i].index; jsetCurrentIndex(changes[i].index); + break; + case ListChange::Polish: + QQUICK_VERIFY_POLISH(pathview); + break; + default: + continue; + } + } + QQUICK_VERIFY_POLISH(pathview); + + QCOMPARE(findItems(pathview, "wrapper").count(), count); + QCOMPARE(pathview->count(), count); + QTRY_COMPARE(pathview->offset(), offset); + + delete canvas; +} + void tst_QQuickPathView::path() { QQmlEngine engine; diff --git a/tests/auto/quick/qquickpositioners/qquickpositioners.pro b/tests/auto/quick/qquickpositioners/qquickpositioners.pro index e4fce55..2092b1a 100644 --- a/tests/auto/quick/qquickpositioners/qquickpositioners.pro +++ b/tests/auto/quick/qquickpositioners/qquickpositioners.pro @@ -11,4 +11,4 @@ macx:CONFIG -= app_bundle TESTDATA = data/* CONFIG += parallel_test -QT += core-private gui-private v8-private qml-private quick-private testlib +QT += testlib diff --git a/tests/auto/quick/shared/util.pri b/tests/auto/quick/shared/util.pri index aa79c7c..28036f1 100644 --- a/tests/auto/quick/shared/util.pri +++ b/tests/auto/quick/shared/util.pri @@ -1,4 +1,6 @@ +QT += core-private gui-private v8-private qml-private quick-private + HEADERS += $$PWD/visualtestutil.h \ $$PWD/viewtestutil.h SOURCES += $$PWD/visualtestutil.cpp \ diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h index 06efd9c..10ecd6a 100644 --- a/tests/auto/quick/shared/viewtestutil.h +++ b/tests/auto/quick/shared/viewtestutil.h @@ -60,7 +60,7 @@ namespace QQuickViewTestUtil QList adjustIndexesForRemoveDisplaced(const QList &indexes, int index, int count); struct ListChange { - enum { Inserted, Removed, Moved, SetCurrent, SetContentY } type; + enum { Inserted, Removed, Moved, SetCurrent, SetContentY, Polish } type; int index; int count; int to; // Move @@ -71,6 +71,7 @@ namespace QQuickViewTestUtil static ListChange move(int index, int to, int count) { ListChange c = { Moved, index, count, to, 0.0 }; return c; } static ListChange setCurrent(int index) { ListChange c = { SetCurrent, index, -1, -1, 0.0 }; return c; } static ListChange setContentY(qreal pos) { ListChange c = { SetContentY, -1, -1, -1, pos }; return c; } + static ListChange polish() { ListChange c = { Polish, -1, -1, -1, 0.0 }; return c; } }; class QmlListModel : public QListModelInterface diff --git a/tests/auto/quick/shared/visualtestutil.h b/tests/auto/quick/shared/visualtestutil.h index 9407ff8..c2fc9cc 100644 --- a/tests/auto/quick/shared/visualtestutil.h +++ b/tests/auto/quick/shared/visualtestutil.h @@ -45,6 +45,8 @@ #include #include +#include + namespace QQuickVisualTestUtil { QQuickItem *findVisibleChild(QQuickItem *parent, const QString &objectName); @@ -106,7 +108,9 @@ namespace QQuickVisualTestUtil items << qobject_cast(findItem(parent, objectName, indexes[i])); return items; } - } +#define QQUICK_VERIFY_POLISH(item) \ + QTRY_COMPARE(QQuickItemPrivate::get(item)->polishScheduled, false) + #endif // QQUICKVISUALTESTUTIL_H -- 2.7.4