From d5a981b987eeac7bce9520ef6a3c45c5bb3e2d48 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 16 Nov 2009 13:58:05 +1000 Subject: More ListView tests. --- .../graphicsitems/qmlgraphicsgridview.cpp | 23 ++++--- .../graphicsitems/qmlgraphicslistview.cpp | 28 ++++---- .../qmlgraphicslistview/data/listview.qml | 34 +++++++++- .../tst_qmlgraphicslistview.cpp | 74 ++++++++++++++++++++-- 4 files changed, 131 insertions(+), 28 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 29eb983..9465c4c 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -843,6 +843,9 @@ QmlComponent *QmlGraphicsGridView::delegate() const void QmlGraphicsGridView::setDelegate(QmlComponent *delegate) { Q_D(QmlGraphicsGridView); + if (delegate == this->delegate()) + return; + if (!d->ownModel) { d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; @@ -944,9 +947,11 @@ QmlComponent *QmlGraphicsGridView::highlight() const void QmlGraphicsGridView::setHighlight(QmlComponent *highlight) { Q_D(QmlGraphicsGridView); - delete d->highlightComponent; - d->highlightComponent = highlight; - d->updateCurrent(d->currentIndex); + if (highlight != d->highlightComponent) { + delete d->highlightComponent; + d->highlightComponent = highlight; + d->updateCurrent(d->currentIndex); + } } /*! @@ -978,12 +983,14 @@ bool QmlGraphicsGridView::highlightFollowsCurrentItem() const void QmlGraphicsGridView::setHighlightFollowsCurrentItem(bool autoHighlight) { Q_D(QmlGraphicsGridView); - d->autoHighlight = autoHighlight; - if (d->highlightXAnimator) { - d->highlightXAnimator->setEnabled(d->autoHighlight); - d->highlightYAnimator->setEnabled(d->autoHighlight); + if (d->autoHighlight != autoHighlight) { + d->autoHighlight = autoHighlight; + if (d->highlightXAnimator) { + d->highlightXAnimator->setEnabled(d->autoHighlight); + d->highlightYAnimator->setEnabled(d->autoHighlight); + } + d->updateHighlight(); } - d->updateHighlight(); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index edcd094..c075a8a 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -1158,6 +1158,8 @@ QmlComponent *QmlGraphicsListView::delegate() const void QmlGraphicsListView::setDelegate(QmlComponent *delegate) { Q_D(QmlGraphicsListView); + if (delegate == this->delegate()) + return; if (!d->ownModel) { d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; @@ -1263,9 +1265,11 @@ QmlComponent *QmlGraphicsListView::highlight() const void QmlGraphicsListView::setHighlight(QmlComponent *highlight) { Q_D(QmlGraphicsListView); - delete d->highlightComponent; - d->highlightComponent = highlight; - d->updateCurrent(d->currentIndex); + if (highlight != d->highlightComponent) { + delete d->highlightComponent; + d->highlightComponent = highlight; + d->updateCurrent(d->currentIndex); + } } /*! @@ -1295,12 +1299,14 @@ bool QmlGraphicsListView::highlightFollowsCurrentItem() const void QmlGraphicsListView::setHighlightFollowsCurrentItem(bool autoHighlight) { Q_D(QmlGraphicsListView); - d->autoHighlight = autoHighlight; - if (d->highlightPosAnimator) { - d->highlightPosAnimator->setEnabled(d->autoHighlight); - d->highlightSizeAnimator->setEnabled(d->autoHighlight); + if (d->autoHighlight != autoHighlight) { + d->autoHighlight = autoHighlight; + if (d->highlightPosAnimator) { + d->highlightPosAnimator->setEnabled(d->autoHighlight); + d->highlightSizeAnimator->setEnabled(d->autoHighlight); + } + d->updateHighlight(); } - d->updateHighlight(); } /*! @@ -1520,8 +1526,7 @@ qreal QmlGraphicsListView::highlightMoveSpeed() const void QmlGraphicsListView::setHighlightMoveSpeed(qreal speed) { Q_D(QmlGraphicsListView);\ - if (d->highlightMoveSpeed != speed) - { + if (d->highlightMoveSpeed != speed) { d->highlightMoveSpeed = speed; if (d->highlightPosAnimator) d->highlightPosAnimator->setVelocity(d->highlightMoveSpeed); @@ -1538,8 +1543,7 @@ qreal QmlGraphicsListView::highlightResizeSpeed() const void QmlGraphicsListView::setHighlightResizeSpeed(qreal speed) { Q_D(QmlGraphicsListView);\ - if (d->highlightResizeSpeed != speed) - { + if (d->highlightResizeSpeed != speed) { d->highlightResizeSpeed = speed; if (d->highlightSizeAnimator) d->highlightSizeAnimator->setVelocity(d->highlightResizeSpeed); diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml index ccefeba..ec8bb68 100644 --- a/tests/auto/declarative/qmlgraphicslistview/data/listview.qml +++ b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml @@ -4,6 +4,29 @@ Rectangle { width: 240 height: 320 color: "#ffffff" + function checkProperties() { + testObject.error = false; + if (list.model != testModel) { + print("model property incorrect"); + testObject.error = true; + } + if (!testObject.animate && list.delegate != myDelegate) { + print("delegate property incorrect - expected myDelegate"); + testObject.error = true; + } + if (testObject.animate && list.delegate != animatedDelegate) { + print("delegate property incorrect - expected animatedDelegate"); + testObject.error = true; + } + if (testObject.invalidHighlight && list.highlight != invalidHl) { + print("highlight property incorrect - expected invalidHl"); + testObject.error = true; + } + if (!testObject.invalidHighlight && list.highlight != myHighlight) { + print("highlight property incorrect - expected myHighlight"); + testObject.error = true; + } + } resources: [ Component { id: myDelegate @@ -70,6 +93,14 @@ Rectangle { */ } } + }, + Component { + id: myHighlight + Rectangle { color: "green" } + }, + Component { + id: invalidHl + EaseFollow {} } ] ListView { @@ -79,7 +110,8 @@ Rectangle { width: 240 height: 320 model: testModel - delegate: testAnimate ? myDelegate : animatedDelegate + delegate: testObject.animate ? animatedDelegate : myDelegate + highlight: testObject.invalidHighlight ? invalidHl : myHighlight highlightMoveSpeed: 1000 highlightResizeSpeed: 1000 } diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index d416603..f7a2d9e 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -90,6 +90,38 @@ private: QList findItems(QmlGraphicsItem *parent, const QString &objectName); }; +class TestObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool error READ error WRITE setError NOTIFY changedError) + Q_PROPERTY(bool animate READ animate NOTIFY changedAnim) + Q_PROPERTY(bool invalidHighlight READ invalidHighlight NOTIFY changedHl) + +public: + TestObject(QObject *parent = 0) + : QObject(parent), mError(true), mAnimate(false), mInvalidHighlight(false) {} + + bool error() const { return mError; } + void setError(bool err) { mError = err; emit changedError(); } + + bool animate() const { return mAnimate; } + void setAnimate(bool anim) { mAnimate = anim; emit changedAnim(); } + + bool invalidHighlight() const { return mInvalidHighlight; } + void setInvalidHighlight(bool invalid) { mInvalidHighlight = invalid; emit changedHl(); } + +signals: + void changedError(); + void changedAnim(); + void changedHl(); + +public: + bool mError; + bool mAnimate; + bool mInvalidHighlight; +}; + class TestModel : public QListModelInterface { Q_OBJECT @@ -243,7 +275,9 @@ void tst_QmlGraphicsListView::items() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - ctxt->setContextProperty("testAnimate", QVariant(false)); + + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); canvas->execute(); qApp->processEvents(); @@ -254,6 +288,9 @@ void tst_QmlGraphicsListView::items() QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + QCOMPARE(listview->count(), model.count()); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item @@ -269,6 +306,16 @@ void tst_QmlGraphicsListView::items() QCOMPARE(number->text(), model.number(i)); } + // switch to other delegate + testObject->setAnimate(true); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + // set invalid highlight + testObject->setInvalidHighlight(true); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + // set an empty model and confirm that items are destroyed T model2; ctxt->setContextProperty("testModel", &model2); @@ -294,7 +341,9 @@ void tst_QmlGraphicsListView::changed() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - ctxt->setContextProperty("testAnimate", QVariant(false)); + + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); canvas->execute(); qApp->processEvents(); @@ -328,7 +377,9 @@ void tst_QmlGraphicsListView::inserted() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - ctxt->setContextProperty("testAnimate", QVariant(false)); + + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); canvas->execute(); qApp->processEvents(); @@ -415,7 +466,10 @@ void tst_QmlGraphicsListView::removed(bool animated) QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - ctxt->setContextProperty("testAnimate", QVariant(animated)); + + TestObject *testObject = new TestObject; + testObject->setAnimate(animated); + ctxt->setContextProperty("testObject", testObject); canvas->execute(); qApp->processEvents(); @@ -526,7 +580,9 @@ void tst_QmlGraphicsListView::moved() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - ctxt->setContextProperty("testAnimate", QVariant(false)); + + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); canvas->execute(); qApp->processEvents(); @@ -665,7 +721,9 @@ void tst_QmlGraphicsListView::spacing() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - ctxt->setContextProperty("testAnimate", QVariant(false)); + + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); canvas->execute(); qApp->processEvents(); @@ -934,7 +992,9 @@ void tst_QmlGraphicsListView::cacheBuffer() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - ctxt->setContextProperty("testAnimate", QVariant(false)); + + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); canvas->execute(); qApp->processEvents(); -- cgit v0.12