diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-02-26 06:34:28 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-03-02 01:28:20 (GMT) |
commit | 2de0a9ff40c6dcbfca5dc75aae7ac0a294618f4a (patch) | |
tree | dddc1e8c72225c818937fff0fd96bd4cd1252950 /tests/auto/declarative/qdeclarativegridview | |
parent | ffe622b5424bd13155fea01116ed6504f06d9d83 (diff) | |
download | Qt-2de0a9ff40c6dcbfca5dc75aae7ac0a294618f4a.zip Qt-2de0a9ff40c6dcbfca5dc75aae7ac0a294618f4a.tar.gz Qt-2de0a9ff40c6dcbfca5dc75aae7ac0a294618f4a.tar.bz2 |
Add NOTIFY signals to list, grid and path views
Reviewed-by: akennedy
Diffstat (limited to 'tests/auto/declarative/qdeclarativegridview')
-rw-r--r-- | tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml | 69 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp | 125 |
2 files changed, 184 insertions, 10 deletions
diff --git a/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml new file mode 100644 index 0000000..da2e8d0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml @@ -0,0 +1,69 @@ +import Qt 4.6 + +Rectangle { + width: 360; height: 120; color: "white" + Component { + id: delegate + Item { + id: wrapper + width: 180; height: 40; + Column { + x: 5; y: 5 + Text { text: '<b>Name:</b> ' + name } + Text { text: '<b>Number:</b> ' + number } + } + } + } + Component { + id: highlightRed + Rectangle { + color: "red" + radius: 10 + opacity: 0.5 + } + } + GridView { + cellWidth:180 + cellHeight:40 + objectName: "gridView" + anchors.fill: parent + model: listModel + delegate: delegate + highlight: highlightRed + focus: true + keyNavigationWraps: true + cacheBuffer: 10 + flow: GridView.LeftToRight + } + + data:[ + ListModel { + id: listModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + }, + ListModel { + objectName: "alternateModel" + ListElement { + name: "Jack" + number: "555 8426" + } + ListElement { + name: "Mary" + number: "555 3264" + } + } + ] +} + +
\ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 2a60fee..cc65d32 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -39,16 +39,17 @@ ** ****************************************************************************/ -#include <qdeclarativeengine.h> -#include <qdeclarativecomponent.h> -#include <QStringListModel> #include <QtTest/QtTest> -#include <private/qlistmodelinterface_p.h> -#include <qdeclarativeview.h> -#include <private/qdeclarativegridview_p.h> -#include <private/qdeclarativetext_p.h> -#include <qdeclarativecontext.h> -#include <qdeclarativeexpression.h> +#include <QtGui/qstringlistmodel.h> +#include <QtDeclarative/qdeclarativeview.h> +#include <QtDeclarative/qdeclarativeengine.h> +#include <QtDeclarative/qdeclarativecomponent.h> +#include <QtDeclarative/qdeclarativecontext.h> +#include <QtDeclarative/qdeclarativeexpression.h> +#include <QtDeclarative/private/qlistmodelinterface_p.h> +#include <QtDeclarative/private/qdeclarativegridview_p.h> +#include <QtDeclarative/private/qdeclarativetext_p.h> +#include <QtDeclarative/private/qdeclarativelistmodel_p.h> class tst_QDeclarativeGridView : public QObject { @@ -66,6 +67,9 @@ private slots: void currentIndex(); void defaultValues(); void properties(); + void propertyChanges(); + void componentChanges(); + void modelChanges(); void positionViewAtIndex(); void resetModel(); void QTBUG_8456(); @@ -91,7 +95,7 @@ public: setRoleNames(roles); } - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); } QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { QVariant rv; if (role == Name) @@ -796,6 +800,107 @@ void tst_QDeclarativeGridView::properties() delete obj; } +void tst_QDeclarativeGridView::propertyChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild<QDeclarativeGridView*>("gridView"); + QVERIFY(gridView); + + QSignalSpy keyNavigationWrapsSpy(gridView, SIGNAL(keyNavigationWrapsChanged())); + QSignalSpy cacheBufferSpy(gridView, SIGNAL(cacheBufferChanged())); + QSignalSpy flowSpy(gridView, SIGNAL(flowChanged())); + + QCOMPARE(gridView->isWrapEnabled(), true); + QCOMPARE(gridView->cacheBuffer(), 10); + QCOMPARE(gridView->flow(), QDeclarativeGridView::LeftToRight); + + gridView->setWrapEnabled(false); + gridView->setCacheBuffer(3); + gridView->setFlow(QDeclarativeGridView::TopToBottom); + + QCOMPARE(gridView->isWrapEnabled(), false); + QCOMPARE(gridView->cacheBuffer(), 3); + QCOMPARE(gridView->flow(), QDeclarativeGridView::TopToBottom); + + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(flowSpy.count(),1); + + gridView->setWrapEnabled(false); + gridView->setCacheBuffer(3); + gridView->setFlow(QDeclarativeGridView::TopToBottom); + + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(flowSpy.count(),1); + + delete canvas; +} + +void tst_QDeclarativeGridView::componentChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild<QDeclarativeGridView*>("gridView"); + QVERIFY(gridView); + + QDeclarativeComponent component(canvas->engine()); + component.setData("import Qt 4.6; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile("")); + + QDeclarativeComponent delegateComponent(canvas->engine()); + delegateComponent.setData("import Qt 4.6; Text { text: '<b>Name:</b> ' + name }", QUrl::fromLocalFile("")); + + QSignalSpy highlightSpy(gridView, SIGNAL(highlightChanged())); + QSignalSpy delegateSpy(gridView, SIGNAL(delegateChanged())); + + gridView->setHighlight(&component); + gridView->setDelegate(&delegateComponent); + + QCOMPARE(gridView->highlight(), &component); + QCOMPARE(gridView->delegate(), &delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + + gridView->setHighlight(&component); + gridView->setDelegate(&delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + delete canvas; +} + +void tst_QDeclarativeGridView::modelChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild<QDeclarativeGridView*>("gridView"); + QVERIFY(gridView); + + QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild<QDeclarativeListModel*>("alternateModel"); + QVERIFY(alternateModel); + QVariant modelVariant = QVariant::fromValue(alternateModel); + QSignalSpy modelSpy(gridView, SIGNAL(modelChanged())); + + gridView->setModel(modelVariant); + QCOMPARE(gridView->model(), modelVariant); + QCOMPARE(modelSpy.count(),1); + + gridView->setModel(modelVariant); + QCOMPARE(modelSpy.count(),1); + + gridView->setModel(QVariant()); + QCOMPARE(modelSpy.count(),2); + delete canvas; +} + void tst_QDeclarativeGridView::positionViewAtIndex() { QDeclarativeView *canvas = createView(); |