From 4652008c01b23eefdba3b02fe8101c5bde857d41 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 6 Oct 2010 13:59:19 +1000 Subject: Ensure PathView updates positions when path changes. Fixes regression caused by optimization added in commit 35a51442ed21f58c06b21293eeb56e843251ee82. Task-number: QTBUG-14239 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativepathview.cpp | 17 +++++++++++++++-- src/declarative/graphicsitems/qdeclarativepathview_p.h | 1 + .../qdeclarativepathview/data/pathUpdate.qml | 18 ++++++++++++++++++ .../qdeclarativepathview/tst_qdeclarativepathview.cpp | 18 ++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativepathview/data/pathUpdate.qml diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index d134929..3ae8788 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -300,6 +300,19 @@ void QDeclarativePathViewPrivate::setHighlightPosition(qreal pos) } } +void QDeclarativePathView::pathUpdated() +{ + Q_D(QDeclarativePathView); + QList::iterator it = d->items.begin(); + while (it != d->items.end()) { + QDeclarativeItem *item = *it; + if (QDeclarativePathViewAttached *att = d->attached(item)) + att->m_percent = -1; + ++it; + } + refill(); +} + void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal percent) { if (QDeclarativePathViewAttached *att = attached(item)) { @@ -526,9 +539,9 @@ void QDeclarativePathView::setPath(QDeclarativePath *path) if (d->path == path) return; if (d->path) - disconnect(d->path, SIGNAL(changed()), this, SLOT(refill())); + disconnect(d->path, SIGNAL(changed()), this, SLOT(pathUpdated())); d->path = path; - connect(d->path, SIGNAL(changed()), this, SLOT(refill())); + connect(d->path, SIGNAL(changed()), this, SLOT(pathUpdated())); if (d->isValid() && isComponentComplete()) { d->clear(); if (d->attType) { diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index 62a8c44..7775b1c 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -186,6 +186,7 @@ private Q_SLOTS: void modelReset(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); + void pathUpdated(); private: friend class QDeclarativePathViewAttached; diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathUpdate.qml b/tests/auto/declarative/qdeclarativepathview/data/pathUpdate.qml new file mode 100644 index 0000000..0c99e7f --- /dev/null +++ b/tests/auto/declarative/qdeclarativepathview/data/pathUpdate.qml @@ -0,0 +1,18 @@ +import Qt 4.7 + +Rectangle { + width: 400 + height: 400 + + PathView { + id: view + objectName: "pathView" + anchors.fill: parent + model: 10 + delegate: Rectangle { objectName: "wrapper"; color: "green"; width: 100; height: 100 } + path: Path { + startX: view.width/2; startY: 0 + PathLine { x: view.width/2; y: view.height } + } + } +} diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 3b5d438..eb4bdbb 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -85,6 +85,7 @@ private slots: void pathUpdateOnStartChanged(); void package(); void emptyModel(); + void pathUpdate(); private: QDeclarativeView *createView(); @@ -787,6 +788,23 @@ void tst_QDeclarativePathView::emptyModel() } +// QTBUG-14239 +void tst_QDeclarativePathView::pathUpdate() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pathUpdate.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativeItem *item = findItem(pathView, "wrapper", 0); + QVERIFY(item); + QCOMPARE(item->x(), 150.0); + + delete canvas; +} + QDeclarativeView *tst_QDeclarativePathView::createView() { QDeclarativeView *canvas = new QDeclarativeView(0); -- cgit v0.12