diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-11-18 06:22:49 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-11-18 06:23:39 (GMT) |
commit | ec5f062124c4bfade1ba79f68397307d334eb12f (patch) | |
tree | 86fd47a014e805f569f3d77255effc2213d862d3 /tests/auto | |
parent | 1c719c4ea6abef35ccae67f6052d8baa74b4e2b3 (diff) | |
parent | c098fef1f410c54f0655af9532d45f80a77b3a91 (diff) | |
download | Qt-ec5f062124c4bfade1ba79f68397307d334eb12f.zip Qt-ec5f062124c4bfade1ba79f68397307d334eb12f.tar.gz Qt-ec5f062124c4bfade1ba79f68397307d334eb12f.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests/auto')
12 files changed, 294 insertions, 4 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index e1817d6..33b5afc 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -54,7 +54,7 @@ SUBDIRS += \ qmltimer \ # Cover qmlxmllistmodel \ # Cover qpacketprotocol \ # Cover - repeater \ # Cover + qmlgraphicsrepeater \ # Cover sql \ # Cover states \ # Cover valuetypes \ # Cover diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 36f4dc5..e9f785b 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -318,13 +318,22 @@ void tst_QmlGraphicsListView::items() testObject->setAnimate(true); QMetaObject::invokeMethod(canvas->root(), "checkProperties"); QVERIFY(testObject->error() == false); + QVERIFY(listview->currentItem()); // set invalid highlight testObject->setInvalidHighlight(true); QMetaObject::invokeMethod(canvas->root(), "checkProperties"); QVERIFY(testObject->error() == false); + QVERIFY(listview->currentItem()); QVERIFY(listview->highlightItem() == 0); + // back to normal highlight + testObject->setInvalidHighlight(false); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + QVERIFY(listview->currentItem()); + QVERIFY(listview->highlightItem() != 0); + // set an empty model and confirm that items are destroyed T model2; ctxt->setContextProperty("testModel", &model2); diff --git a/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml new file mode 100644 index 0000000..6aea96b --- /dev/null +++ b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml @@ -0,0 +1,36 @@ +import Qt 4.6 + +PathView { + id: pathview + objectName: "pathview" + width: 240; height: 320 + pathItemCount: testObject.pathItemCount + + function checkProperties() { + testObject.error = false; + if (testObject.useModel && view.model != itemModel) { + print("model property incorrect"); + testObject.error = true; + } + } + + model: testObject.useModel ? testData : 0 + + delegate: Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + width: 20; height: 20; color: name + Text { + objectName: "myText" + text: name + } + } + } + + path: Path { + startX: 120; startY: 20; + PathLine { x: 120; y: 300 } + } +} diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp index 561392a..8aa2691 100644 --- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp +++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp @@ -45,6 +45,10 @@ #include <qtest.h> #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qmlview.h> +#include <QtDeclarative/private/qmlgraphicstext_p.h> +#include <QAbstractListModel> +#include <QFile> #include <private/qmlvaluetype_p.h> #include "../../../shared/util.h" @@ -56,9 +60,107 @@ public: private slots: void initValues(); + void dataModel(); void pathview2(); void pathview3(); void path(); + +private: + QmlView *createView(const QString &filename); + template<typename T> + T *findItem(QmlGraphicsItem *parent, const QString &objectName, int index=-1); + template<typename T> + QList<T*> findItems(QmlGraphicsItem *parent, const QString &objectName); +}; + +class TestObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool error READ error WRITE setError) + Q_PROPERTY(bool useModel READ useModel NOTIFY useModelChanged) + Q_PROPERTY(int pathItemCount READ pathItemCount NOTIFY pathItemCountChanged) + +public: + TestObject() : QObject(), mError(true), mUseModel(true), mPathItemCount(-1) {} + + bool error() const { return mError; } + void setError(bool err) { mError = err; } + + bool useModel() const { return mUseModel; } + void setUseModel(bool use) { mUseModel = use; emit useModelChanged(); } + + int pathItemCount() const { return mPathItemCount; } + void setPathItemCount(int count) { mPathItemCount = count; emit pathItemCountChanged(); } + +signals: + void useModelChanged(); + void pathItemCountChanged(); + +private: + bool mError; + bool mUseModel; + int mPathItemCount; +}; + +class TestModel : public QAbstractListModel +{ +public: + enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; + + TestModel(QObject *parent=0) : QAbstractListModel(parent) { + QHash<int, QByteArray> roles; + roles[Name] = "name"; + roles[Number] = "number"; + setRoleNames(roles); + } + + int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { + QVariant rv; + if (role == Name) + rv = list.at(index.row()).first; + else if (role == Number) + rv = list.at(index.row()).second; + + return rv; + } + + int count() const { return rowCount(); } + QString name(int index) const { return list.at(index).first; } + QString number(int index) const { return list.at(index).second; } + + void addItem(const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), list.count(), list.count()); + list.append(QPair<QString,QString>(name, number)); + emit endInsertRows(); + } + + void insertItem(int index, const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), index, index); + list.insert(index, QPair<QString,QString>(name, number)); + emit endInsertRows(); + } + + void removeItem(int index) { + emit beginRemoveRows(QModelIndex(), index, index); + list.removeAt(index); + emit endRemoveRows(); + } + + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + + void modifyItem(int idx, const QString &name, const QString &number) { + list[idx] = QPair<QString,QString>(name, number); + emit dataChanged(index(idx,0), index(idx,0)); + } + +private: + QList<QPair<QString,QString> > list; }; @@ -165,6 +267,145 @@ void tst_QmlGraphicsPathView::path() QCOMPARE(cubic->control2Y(), 90.); } +void tst_QmlGraphicsPathView::dataModel() +{ + QmlView *canvas = createView(SRCDIR "/data/datamodel.qml"); + + QmlContext *ctxt = canvas->rootContext(); + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); + + TestModel model; + model.addItem("red", "1"); + model.addItem("green", "2"); + model.addItem("blue", "3"); + model.addItem("purple", "4"); + model.addItem("gray", "5"); + model.addItem("brown", "6"); + model.addItem("yellow", "7"); + model.addItem("thistle", "8"); + model.addItem("cyan", "9"); + + ctxt->setContextProperty("testData", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsPathView *pathview = qobject_cast<QmlGraphicsPathView*>(canvas->root()); + QVERIFY(pathview != 0); + + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(pathview, "wrapper", 0); + QVERIFY(item); + QCOMPARE(item->x(), 110.0); + QCOMPARE(item->y(), 10.0); + + model.insertItem(4, "orange", "10"); + + int itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 10); + + QmlGraphicsText *text = findItem<QmlGraphicsText>(pathview, "myText", 4); + QVERIFY(text); + QCOMPARE(text->text(), model.name(4)); + + model.removeItem(2); + text = findItem<QmlGraphicsText>(pathview, "myText", 2); + QVERIFY(text); + QCOMPARE(text->text(), model.name(2)); + + testObject->setPathItemCount(5); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + + model.insertItem(2, "pink", "2"); + + itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + + text = findItem<QmlGraphicsText>(pathview, "myText", 2); + QVERIFY(text); + QCOMPARE(text->text(), model.name(2)); + + model.removeItem(3); + itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + text = findItem<QmlGraphicsText>(pathview, "myText", 3); + QVERIFY(text); + QCOMPARE(text->text(), model.name(3)); + + delete canvas; +} + +QmlView *tst_QmlGraphicsPathView::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + + return canvas; +} + +/* + Find an item with the specified objectName. If index is supplied then the + item must also evaluate the {index} expression equal to index + */ +template<typename T> +T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + if (index != -1) { + QmlExpression e(qmlContext(item), "index", item); + e.setTrackChange(false); + if (e.value().toInt() == index) + return static_cast<T*>(item); + } else { + return static_cast<T*>(item); + } + } + item = findItem<T>(item, objectName, index); + if (item) + return static_cast<T*>(item); + } + + return 0; +} + +template<typename T> +QList<T*> tst_QmlGraphicsPathView::findItems(QmlGraphicsItem *parent, const QString &objectName) +{ + QList<T*> items; + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast<T*>(item)); + items += findItems<T>(item, objectName); + } + + return items; +} + QTEST_MAIN(tst_QmlGraphicsPathView) #include "tst_qmlgraphicspathview.moc" diff --git a/tests/auto/declarative/repeater/data/intmodel.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml index 2d6eae8..2d6eae8 100644 --- a/tests/auto/declarative/repeater/data/intmodel.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml diff --git a/tests/auto/declarative/repeater/data/itemlist.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml index 8d28bf8..8d28bf8 100644 --- a/tests/auto/declarative/repeater/data/itemlist.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml diff --git a/tests/auto/declarative/repeater/data/objlist.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml index ecc6d02..ecc6d02 100644 --- a/tests/auto/declarative/repeater/data/objlist.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml diff --git a/tests/auto/declarative/repeater/data/repeater.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml index 7d83230..7d83230 100644 --- a/tests/auto/declarative/repeater/data/repeater.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml diff --git a/tests/auto/declarative/repeater/data/repeater2.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml index c3c3260..c3c3260 100644 --- a/tests/auto/declarative/repeater/data/repeater2.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml diff --git a/tests/auto/declarative/repeater/repeater.pro b/tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro index 968904b..0a10ec6 100644 --- a/tests/auto/declarative/repeater/repeater.pro +++ b/tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro @@ -2,7 +2,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative macx:CONFIG -= app_bundle -SOURCES += tst_repeater.cpp +SOURCES += tst_qmlgraphicsrepeater.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp index c0fa645..e8019d7 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp @@ -280,8 +280,10 @@ void tst_QmlGraphicsRepeater::dataModel() QCOMPARE(container->childItems().count(), 4); testModel.addItem("four", "4"); - QCOMPARE(container->childItems().count(), 5); + + testModel.removeItem(2); + QCOMPARE(container->childItems().count(), 4); } void tst_QmlGraphicsRepeater::itemModel() @@ -346,4 +348,4 @@ T *tst_QmlGraphicsRepeater::findItem(QObject *parent, const QString &objectName) QTEST_MAIN(tst_QmlGraphicsRepeater) -#include "tst_repeater.moc" +#include "tst_qmlgraphicsrepeater.moc" diff --git a/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml b/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml index 1ffbe15..70018b6 100644 --- a/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml +++ b/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml @@ -21,6 +21,8 @@ Rectangle { id: wrapper width: 85; height: 85; color: lColor scale: wrapper.PathView.scale + + MouseRegion { anchors.fill: parent } transform: Rotation { id: itemRotation; origin.x: wrapper.width/2; origin.y: wrapper.height/2 |