From 5e42176970c05c015685194aecf954aaac5d9e1e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 31 Jan 2012 17:15:00 +1000 Subject: [PATCH] Separate out some of the common test code Moves findItem, findItems() etc. into shared/visualtestutil.h and moves duplicate list model test classes and other common view-specific code into shared/viewtestutil.h. Change-Id: Ia79bc4df1ab7fb618597755c0288a2e8f5054faf Reviewed-by: Martin Jones --- .../auto/qtquick2/qquickanchors/qquickanchors.pro | 1 + .../qtquick2/qquickanchors/tst_qquickanchors.cpp | 29 +- .../qtquick2/qquickflickable/qquickflickable.pro | 1 + .../qquickflickable/tst_qquickflickable.cpp | 49 +-- .../qtquick2/qquickfocusscope/qquickfocusscope.pro | 1 + .../qquickfocusscope/tst_qquickfocusscope.cpp | 28 +- .../qtquick2/qquickgridview/qquickgridview.pro | 1 + .../qtquick2/qquickgridview/tst_qquickgridview.cpp | 329 ++------------ tests/auto/qtquick2/qquickimage/qquickimage.pro | 1 + .../auto/qtquick2/qquickimage/tst_qquickimage.cpp | 38 +- tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp | 26 +- .../qtquick2/qquicklistview/qquicklistview.pro | 1 + .../qtquick2/qquicklistview/tst_qquicklistview.cpp | 478 +++------------------ .../qtquick2/qquickpathview/qquickpathview.pro | 1 + .../qtquick2/qquickpathview/tst_qquickpathview.cpp | 199 +-------- .../qtquick2/qquickrepeater/data/repeater1.qml | 42 +- .../qtquick2/qquickrepeater/qquickrepeater.pro | 1 + .../qtquick2/qquickrepeater/tst_qquickrepeater.cpp | 133 +----- .../qquickvisualdatamodel.pro | 1 + .../tst_qquickvisualdatamodel.cpp | 32 +- tests/auto/qtquick2/shared/util.pri | 7 + tests/auto/qtquick2/shared/viewtestutil.cpp | 345 +++++++++++++++ tests/auto/qtquick2/shared/viewtestutil.h | 146 +++++++ tests/auto/qtquick2/shared/visualtestutil.cpp | 71 +++ tests/auto/qtquick2/shared/visualtestutil.h | 102 +++++ 25 files changed, 858 insertions(+), 1205 deletions(-) create mode 100644 tests/auto/qtquick2/shared/util.pri create mode 100644 tests/auto/qtquick2/shared/viewtestutil.cpp create mode 100644 tests/auto/qtquick2/shared/viewtestutil.h create mode 100644 tests/auto/qtquick2/shared/visualtestutil.cpp create mode 100644 tests/auto/qtquick2/shared/visualtestutil.h diff --git a/tests/auto/qtquick2/qquickanchors/qquickanchors.pro b/tests/auto/qtquick2/qquickanchors/qquickanchors.pro index 25711d4..bd94f9c 100644 --- a/tests/auto/qtquick2/qquickanchors/qquickanchors.pro +++ b/tests/auto/qtquick2/qquickanchors/qquickanchors.pro @@ -3,6 +3,7 @@ CONFIG += testcase SOURCES += tst_qquickanchors.cpp include (../../shared/util.pri) +include (../shared/util.pri) macx:CONFIG -= app_bundle diff --git a/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp b/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp index 54e3008..ff3426b 100644 --- a/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp @@ -49,10 +49,13 @@ #include #include #include "../../shared/util.h" +#include "../shared/visualtestutil.h" Q_DECLARE_METATYPE(QQuickAnchors::Anchor) Q_DECLARE_METATYPE(QQuickAnchorLine::AnchorLine) +using namespace QQuickVisualTestUtil; + class tst_qquickanchors : public QDeclarativeDataTest { Q_OBJECT @@ -82,32 +85,6 @@ private slots: void marginsRTL(); }; -/* - Find an item with the specified objectName. -*/ -template -T *findItem(QQuickItem *parent, const QString &objectName) -{ - if (!parent) - return 0; - - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QQuickItem::children().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) - return static_cast(item); - item = findItem(item, objectName); - if (item) - return static_cast(item); - } - - return 0; -} - void tst_qquickanchors::basicAnchors() { QQuickView *view = new QQuickView; diff --git a/tests/auto/qtquick2/qquickflickable/qquickflickable.pro b/tests/auto/qtquick2/qquickflickable/qquickflickable.pro index 6939130..d1b8b69 100644 --- a/tests/auto/qtquick2/qquickflickable/qquickflickable.pro +++ b/tests/auto/qtquick2/qquickflickable/qquickflickable.pro @@ -5,6 +5,7 @@ macx:CONFIG -= app_bundle SOURCES += tst_qquickflickable.cpp include (../../shared/util.pri) +include (../shared/util.pri) testDataFiles.files = data testDataFiles.path = . diff --git a/tests/auto/qtquick2/qquickflickable/tst_qquickflickable.cpp b/tests/auto/qtquick2/qquickflickable/tst_qquickflickable.cpp index a176870..d357877 100644 --- a/tests/auto/qtquick2/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/qtquick2/qquickflickable/tst_qquickflickable.cpp @@ -48,8 +48,13 @@ #include #include #include "../../shared/util.h" +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" #include +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + class tst_qquickflickable : public QDeclarativeDataTest { Q_OBJECT @@ -76,10 +81,6 @@ private slots: private: QDeclarativeEngine engine; - - void flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration); - template - T *findItem(QQuickItem *parent, const QString &objectName); }; void tst_qquickflickable::create() @@ -657,46 +658,6 @@ void tst_qquickflickable::margins() delete root; } -void tst_qquickflickable::flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration) -{ - const int pointCount = 5; - QPoint diff = to - from; - - // send press, five equally spaced moves, and release. - QTest::mousePress(canvas, Qt::LeftButton, 0, from); - - for (int i = 0; i < pointCount; ++i) { - QMouseEvent mv(QEvent::MouseMove, from + (i+1)*diff/pointCount, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); - QGuiApplication::sendEvent(canvas, &mv); - QTest::qWait(duration/pointCount); - QCoreApplication::processEvents(); - } - - QTest::mouseRelease(canvas, Qt::LeftButton, 0, to); - QTest::qWait(50); -} - -template -T *tst_qquickflickable::findItem(QQuickItem *parent, const QString &objectName) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - return static_cast(item); - } - item = findItem(item, objectName); - if (item) - return static_cast(item); - } - - return 0; -} - QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" diff --git a/tests/auto/qtquick2/qquickfocusscope/qquickfocusscope.pro b/tests/auto/qtquick2/qquickfocusscope/qquickfocusscope.pro index 75bd663..d83f6ca 100644 --- a/tests/auto/qtquick2/qquickfocusscope/qquickfocusscope.pro +++ b/tests/auto/qtquick2/qquickfocusscope/qquickfocusscope.pro @@ -3,6 +3,7 @@ TARGET = tst_qquickfocusscope SOURCES += tst_qquickfocusscope.cpp include (../../shared/util.pri) +include (../shared/util.pri) macx:CONFIG -= app_bundle diff --git a/tests/auto/qtquick2/qquickfocusscope/tst_qquickfocusscope.cpp b/tests/auto/qtquick2/qquickfocusscope/tst_qquickfocusscope.cpp index c52cfae..4264c68 100644 --- a/tests/auto/qtquick2/qquickfocusscope/tst_qquickfocusscope.cpp +++ b/tests/auto/qtquick2/qquickfocusscope/tst_qquickfocusscope.cpp @@ -48,6 +48,9 @@ #include #include #include "../../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; class tst_qquickfocusscope : public QDeclarativeDataTest { @@ -55,9 +58,6 @@ class tst_qquickfocusscope : public QDeclarativeDataTest public: tst_qquickfocusscope() {} - template - T *findItem(QQuickItem *parent, const QString &id); - private slots: void basic(); void nested(); @@ -71,28 +71,6 @@ private slots: void canvasFocus(); }; -/* - Find an item with the specified id. -*/ -template -T *tst_qquickfocusscope::findItem(QQuickItem *parent, const QString &objectName) -{ - const QMetaObject &mo = T::staticMetaObject; - QList children = parent->childItems(); - for (int i = 0; i < children.count(); ++i) { - QQuickItem *item = children.at(i); - if (item) { - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - return static_cast(item); - } - item = findItem(item, objectName); - if (item) - return static_cast(item); - } - } - return 0; -} - void tst_qquickfocusscope::basic() { QQuickView *view = new QQuickView; diff --git a/tests/auto/qtquick2/qquickgridview/qquickgridview.pro b/tests/auto/qtquick2/qquickgridview/qquickgridview.pro index ad026f0..583aeda 100644 --- a/tests/auto/qtquick2/qquickgridview/qquickgridview.pro +++ b/tests/auto/qtquick2/qquickgridview/qquickgridview.pro @@ -5,6 +5,7 @@ macx:CONFIG -= app_bundle SOURCES += tst_qquickgridview.cpp include (../../shared/util.pri) +include (../shared/util.pri) testDataFiles.files = data testDataFiles.path = . diff --git a/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp b/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp index fb2b6b4..e6b27f8 100644 --- a/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp @@ -48,16 +48,20 @@ #include #include #include -#include #include #include #include #include "../../shared/util.h" +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" #include Q_DECLARE_METATYPE(Qt::LayoutDirection) Q_DECLARE_METATYPE(QQuickGridView::Flow) +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + class tst_QQuickGridView : public QDeclarativeDataTest { Q_OBJECT @@ -123,137 +127,6 @@ private slots: void cacheBuffer(); void asynchronous(); void unrequestedVisibility(); - -private: - QQuickView *createView(); - void flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration); - template - T *findItem(QQuickItem *parent, const QString &id, int index=-1); - template - QList findItems(QQuickItem *parent, const QString &objectName); - void dumpTree(QQuickItem *parent, int depth = 0); -}; - -template -void tst_qquickgridview_move(int from, int to, int n, T *items) -{ - if (from > to) { - // Only move forwards - flip if backwards moving - int tfrom = from; - int tto = to; - from = tto; - to = tto+n; - n = tfrom-tto; - } - - T replaced; - int i=0; - typename T::ConstIterator it=items->begin(); it += from+n; - for (; ibegin(); it += from; - for (; ibegin(); t += from; - for (; f != replaced.end(); ++f, ++t) - *t = *f; -} - -class TestModel : public QAbstractListModel -{ -public: - enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; - - TestModel(QObject *parent=0) : QAbstractListModel(parent) { - QHash roles; - roles[Name] = "name"; - roles[Number] = "number"; - setRoleNames(roles); - } - - 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) - 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(name, number)); - emit endInsertRows(); - } - - void addItems(const QList > &items) { - emit beginInsertRows(QModelIndex(), list.count(), list.count()+items.count()-1); - for (int i=0; i(items[i].first, items[i].second)); - emit endInsertRows(); - } - - void insertItem(int index, const QString &name, const QString &number) { - emit beginInsertRows(QModelIndex(), index, index); - list.insert(index, QPair(name, number)); - emit endInsertRows(); - } - - void insertItems(int index, const QList > &items) { - emit beginInsertRows(QModelIndex(), index, index + items.count() - 1); - for (int i=0; i(items[i].first, items[i].second)); - emit endInsertRows(); - } - - void removeItem(int index) { - emit beginRemoveRows(QModelIndex(), index, index); - list.removeAt(index); - emit endRemoveRows(); - } - - void removeItems(int index, int count) { - emit beginRemoveRows(QModelIndex(), index, index+count-1); - while (count--) - 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 moveItems(int from, int to, int count) { - emit beginMoveRows(QModelIndex(), from, from+count-1, QModelIndex(), to > from ? to+count : to); - tst_qquickgridview_move(from, to, count, &list); - emit endMoveRows(); - } - - void modifyItem(int idx, const QString &name, const QString &number) { - list[idx] = QPair(name, number); - emit dataChanged(index(idx,0), index(idx,0)); - } - - void clear() { - int count = list.count(); - emit beginRemoveRows(QModelIndex(), 0, count-1); - list.clear(); - emit endRemoveRows(); - } - - -private: - QList > list; }; tst_QQuickGridView::tst_QQuickGridView() @@ -264,7 +137,7 @@ void tst_QQuickGridView::items() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; model.addItem("Fred", "12345"); model.addItem("John", "2345"); model.addItem("Bob", "54321"); @@ -301,7 +174,7 @@ void tst_QQuickGridView::items() } // set an empty model and confirm that items are destroyed - TestModel model2; + QaimModel model2; ctxt->setContextProperty("testModel", &model2); int itemCount = findItems(contentItem, "wrapper").count(); @@ -314,7 +187,7 @@ void tst_QQuickGridView::changed() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; model.addItem("Fred", "12345"); model.addItem("John", "2345"); model.addItem("Bob", "54321"); @@ -353,7 +226,7 @@ void tst_QQuickGridView::inserted() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; model.addItem("Fred", "12345"); model.addItem("John", "2345"); model.addItem("Bob", "54321"); @@ -440,7 +313,7 @@ void tst_QQuickGridView::inserted_more() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -610,7 +483,7 @@ void tst_QQuickGridView::insertBeforeVisible() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -694,7 +567,7 @@ void tst_QQuickGridView::removed() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -848,7 +721,7 @@ void tst_QQuickGridView::removed_more() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1041,7 +914,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1120,7 +993,7 @@ void tst_QQuickGridView::clear() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1167,7 +1040,7 @@ void tst_QQuickGridView::moved() QScopedPointer canvas(createView()); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1373,19 +1246,6 @@ void tst_QQuickGridView::moved_data() << -60.0; // 16,17,18 move to above item 0, all items move up by 1 row } -struct ListChange { - enum { Inserted, Removed, Moved, SetCurrent } type; - int index; - int count; - int to; // Move - - static ListChange insert(int index, int count = 1) { ListChange c = { Inserted, index, count, -1 }; return c; } - static ListChange remove(int index, int count = 1) { ListChange c = { Removed, index, count, -1 }; return c; } - static ListChange move(int index, int to, int count) { ListChange c = { Moved, index, count, to }; return c; } - static ListChange setCurrent(int index) { ListChange c = { SetCurrent, index, -1, -1 }; return c; } -}; -Q_DECLARE_METATYPE(QList) - void tst_QQuickGridView::multipleChanges() { QFETCH(int, startCount); @@ -1396,7 +1256,7 @@ void tst_QQuickGridView::multipleChanges() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < startCount; i++) model.addItem("Item" + QString::number(i), ""); @@ -1613,7 +1473,7 @@ void tst_QQuickGridView::swapWithFirstItem() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1638,7 +1498,7 @@ void tst_QQuickGridView::swapWithFirstItem() void tst_QQuickGridView::currentIndex() { - TestModel model; + QaimModel model; for (int i = 0; i < 60; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -1884,7 +1744,7 @@ void tst_QQuickGridView::currentIndex() void tst_QQuickGridView::noCurrentIndex() { - TestModel model; + QaimModel model; for (int i = 0; i < 60; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -1923,7 +1783,7 @@ void tst_QQuickGridView::changeFlow() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -2213,7 +2073,7 @@ void tst_QQuickGridView::positionViewAtIndex() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -2414,7 +2274,7 @@ void tst_QQuickGridView::snapping() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -2516,7 +2376,7 @@ void tst_QQuickGridView::positionViewAtIndex_rightToLeft() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -2691,7 +2551,7 @@ void tst_QQuickGridView::enforceRange() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -2733,7 +2593,7 @@ void tst_QQuickGridView::enforceRange() gridview->setCurrentIndex(5); QTRY_COMPARE(gridview->contentY(), 100.); - TestModel model2; + QaimModel model2; for (int i = 0; i < 5; i++) model2.addItem("Item" + QString::number(i), ""); @@ -2747,7 +2607,7 @@ void tst_QQuickGridView::enforceRange_rightToLeft() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -2791,7 +2651,7 @@ void tst_QQuickGridView::enforceRange_rightToLeft() QTRY_COMPARE(gridview->contentX(), -340.); QTRY_COMPARE(gridview->contentY(), 0.0); - TestModel model2; + QaimModel model2; for (int i = 0; i < 5; i++) model2.addItem("Item" + QString::number(i), ""); @@ -2877,7 +2737,7 @@ void tst_QQuickGridView::footer() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 7; i++) model.addItem("Item" + QString::number(i), ""); @@ -3035,7 +2895,7 @@ void tst_QQuickGridView::header() QFETCH(QPointF, firstDelegatePos); QFETCH(QPointF, resizeContentPos); - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -3180,7 +3040,7 @@ void tst_QQuickGridView::resizeViewAndRepaint() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3213,14 +3073,14 @@ void tst_QQuickGridView::resizeViewAndRepaint() // Ensure we handle -ve sizes gridview->setHeight(-100); - QTRY_COMPARE(findItems(contentItem, "wrapper").count(), 3); + QTRY_COMPARE(findItems(contentItem, "wrapper", false).count(), 3); gridview->setCacheBuffer(120); - QTRY_COMPARE(findItems(contentItem, "wrapper").count(), 9); + QTRY_COMPARE(findItems(contentItem, "wrapper", false).count(), 9); // ensure items in cache become visible gridview->setHeight(120); - QTRY_COMPARE(findItems(contentItem, "wrapper").count(), 15); + QTRY_COMPARE(findItems(contentItem, "wrapper", false).count(), 15); int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { @@ -3234,9 +3094,9 @@ void tst_QQuickGridView::resizeViewAndRepaint() // ensure items outside view become invisible gridview->setHeight(60); - QTRY_COMPARE(findItems(contentItem, "wrapper").count(), 12); + QTRY_COMPARE(findItems(contentItem, "wrapper", false).count(), 12); - itemCount = findItems(contentItem, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper", false).count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -3251,7 +3111,7 @@ void tst_QQuickGridView::resizeViewAndRepaint() void tst_QQuickGridView::changeColumnCount() { - TestModel model; + QmlListModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3328,7 +3188,7 @@ void tst_QQuickGridView::indexAt_itemAt() QQuickView *canvas = createView(); - TestModel model; + QaimModel model; model.addItem("Fred", "12345"); model.addItem("John", "2345"); model.addItem("Bob", "54321"); @@ -3371,7 +3231,7 @@ void tst_QQuickGridView::onAdd() const int delegateWidth = 50; const int delegateHeight = 100; - TestModel model; + QaimModel model; QQuickView *canvas = createView(); canvas->setGeometry(0,0,5 * delegateWidth, 5 * delegateHeight); // just ensure all items fit @@ -3432,7 +3292,7 @@ void tst_QQuickGridView::onRemove() const int delegateWidth = 50; const int delegateHeight = 100; - TestModel model; + QaimModel model; for (int i=0; ishow(); - TestModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3562,7 +3422,7 @@ void tst_QQuickGridView::margins() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3854,7 +3714,7 @@ void tst_QQuickGridView::unaligned() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; for (int i = 0; i < 10; i++) model.addItem("Item" + QString::number(i), ""); @@ -3909,37 +3769,11 @@ void tst_QQuickGridView::unaligned() delete canvas; } -QQuickView *tst_QQuickGridView::createView() -{ - QQuickView *canvas = new QQuickView(0); - canvas->setGeometry(0,0,240,320); - - return canvas; -} - -void tst_QQuickGridView::flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration) -{ - const int pointCount = 5; - QPoint diff = to - from; - - // send press, five equally spaced moves, and release. - QTest::mousePress(canvas, Qt::LeftButton, 0, from); - - for (int i = 0; i < pointCount; ++i) { - QMouseEvent mv(QEvent::MouseMove, from + (i+1)*diff/pointCount, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); - QGuiApplication::sendEvent(canvas, &mv); - QTest::qWait(duration/pointCount); - QCoreApplication::processEvents(); - } - - QTest::mouseRelease(canvas, Qt::LeftButton, 0, to); -} - void tst_QQuickGridView::cacheBuffer() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; for (int i = 0; i < 90; i++) model.addItem("Item" + QString::number(i), ""); @@ -3961,7 +3795,7 @@ void tst_QQuickGridView::cacheBuffer() QVERIFY(gridview->model() != 0); // Confirm items positioned correctly - int itemCount = findItems(contentItem, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper", false).count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem(contentItem, "wrapper", i); QTRY_COMPARE(item->x(), (i%3)*80.0); @@ -3991,7 +3825,7 @@ void tst_QQuickGridView::cacheBuffer() } int newItemCount = 0; - newItemCount = findItems(contentItem, "wrapper").count(); + newItemCount = findItems(contentItem, "wrapper", false).count(); // Confirm items positioned correctly for (int i = 0; i < model.count() && i < newItemCount; ++i) { @@ -4081,7 +3915,7 @@ void tst_QQuickGridView::asynchronous() void tst_QQuickGridView::unrequestedVisibility() { - TestModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -4251,75 +4085,6 @@ void tst_QQuickGridView::unrequestedVisibility() delete 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 -T *tst_QQuickGridView::findItem(QQuickItem *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(item); - if (context) { - if (context->contextProperty("index").toInt() == index) { - return static_cast(item); - } - } - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} - -template -QList tst_QQuickGridView::findItems(QQuickItem *parent, const QString &objectName) -{ - QList items; - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - items.append(static_cast(item)); - //qDebug() << " found:" << item; - } - items += findItems(item, objectName); - } - - return items; -} - -void tst_QQuickGridView::dumpTree(QQuickItem *parent, int depth) -{ - static QString padding(" "); - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(item); - qDebug() << padding.left(depth*2) << item << (context ? context->contextProperty("index").toInt() : -1); - dumpTree(item, depth+1); - } -} - - QTEST_MAIN(tst_QQuickGridView) #include "tst_qquickgridview.moc" diff --git a/tests/auto/qtquick2/qquickimage/qquickimage.pro b/tests/auto/qtquick2/qquickimage/qquickimage.pro index 64a1a8f..43e95a2 100644 --- a/tests/auto/qtquick2/qquickimage/qquickimage.pro +++ b/tests/auto/qtquick2/qquickimage/qquickimage.pro @@ -7,6 +7,7 @@ SOURCES += tst_qquickimage.cpp \ ../../shared/testhttpserver.cpp include (../../shared/util.pri) +include (../shared/util.pri) testDataFiles.files = data testDataFiles.path = . diff --git a/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp b/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp index 69d22c5..b33caa7 100644 --- a/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp @@ -58,10 +58,14 @@ #include "../../shared/util.h" #include "../../shared/testhttpserver.h" +#include "../shared/visualtestutil.h" #define SERVER_PORT 14451 #define SERVER_ADDR "http://127.0.0.1:14451" + +using namespace QQuickVisualTestUtil; + Q_DECLARE_METATYPE(QQuickImageBase::Status) class tst_qquickimage : public QDeclarativeDataTest @@ -93,9 +97,6 @@ private slots: void imageCrash_QTBUG_22125(); private: - template - T *findItem(QQuickItem *parent, const QString &id, int index=-1); - QDeclarativeEngine engine; }; @@ -697,37 +698,6 @@ void tst_qquickimage::imageCrash_QTBUG_22125() QCoreApplication::processEvents(); } -/* - Find an item with the specified objectName. If index is supplied then the - item must also evaluate the {index} expression equal to index -*/ -template -T *tst_qquickimage::findItem(QQuickItem *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QDeclarativeExpression e(qmlContext(item), item, "index"); - if (e.evaluate().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} - QTEST_MAIN(tst_qquickimage) #include "tst_qquickimage.moc" diff --git a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp index a676dc9..f6a7b0c 100644 --- a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp @@ -47,6 +47,9 @@ #include #include #include "../../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; class tst_QQuickItem : public QDeclarativeDataTest { @@ -86,29 +89,6 @@ private: QDeclarativeEngine engine; }; -template -T *findItem(QQuickItem *parent, const QString &objectName) -{ - if (!parent) - return 0; - - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QQuickItem::children().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) - return static_cast(item); - item = findItem(item, objectName); - if (item) - return static_cast(item); - } - - return 0; -} - class KeysTestObject : public QObject { Q_OBJECT diff --git a/tests/auto/qtquick2/qquicklistview/qquicklistview.pro b/tests/auto/qtquick2/qquicklistview/qquicklistview.pro index b1f8514..6957513 100644 --- a/tests/auto/qtquick2/qquicklistview/qquicklistview.pro +++ b/tests/auto/qtquick2/qquicklistview/qquicklistview.pro @@ -7,6 +7,7 @@ SOURCES += tst_qquicklistview.cpp \ incrementalmodel.cpp include (../../shared/util.pri) +include (../shared/util.pri) testDataFiles.files = data testDataFiles.path = . diff --git a/tests/auto/qtquick2/qquicklistview/tst_qquicklistview.cpp b/tests/auto/qtquick2/qquicklistview/tst_qquicklistview.cpp index 3915d13..b77a8c0 100644 --- a/tests/auto/qtquick2/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/qtquick2/qquicklistview/tst_qquicklistview.cpp @@ -51,15 +51,19 @@ #include #include #include -#include #include #include "../../shared/util.h" +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" #include "incrementalmodel.h" #include Q_DECLARE_METATYPE(Qt::LayoutDirection) Q_DECLARE_METATYPE(QQuickListView::Orientation) +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + class tst_QQuickListView : public QDeclarativeDataTest { Q_OBJECT @@ -177,14 +181,6 @@ private: template void moved(const QUrl &source); template void clear(const QUrl &source); template void sections(const QUrl &source); - QQuickView *createView(); - void flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration); - QQuickItem *findVisibleChild(QQuickItem *parent, const QString &objectName); - template - T *findItem(QQuickItem *parent, const QString &id, int index=-1); - template - QList findItems(QQuickItem *parent, const QString &objectName, bool visibleOnly = true); - void dumpTree(QQuickItem *parent, int depth = 0); void inserted_more_data(); void removed_more_data(); @@ -230,239 +226,6 @@ public: int mCacheBuffer; }; -template -void tst_qquicklistview_move(int from, int to, int n, T *items) -{ - if (from > to) { - // Only move forwards - flip if backwards moving - int tfrom = from; - int tto = to; - from = tto; - to = tto+n; - n = tfrom-tto; - } - if (n == 1) { - items->move(from, to); - } else { - T replaced; - int i=0; - typename T::ConstIterator it=items->begin(); it += from+n; - for (; ibegin(); it += from; - for (; ibegin(); t += from; - for (; f != replaced.end(); ++f, ++t) - *t = *f; - } -} - -class TestModel : public QListModelInterface -{ - Q_OBJECT -public: - TestModel(QObject *parent = 0) : QListModelInterface(parent) {} - ~TestModel() {} - - enum Roles { Name, Number }; - - QString name(int index) const { return list.at(index).first; } - QString number(int index) const { return list.at(index).second; } - - int count() const { return list.count(); } - - QList roles() const { return QList() << Name << Number; } - QString toString(int role) const { - switch (role) { - case Name: - return "name"; - case Number: - return "number"; - default: - return ""; - } - } - - QVariant data(int index, int role) const - { - if (role==0) - return list.at(index).first; - if (role==1) - return list.at(index).second; - return QVariant(); - } - QHash data(int index, const QList &roles) const { - QHash returnHash; - - for (int i = 0; i < roles.size(); ++i) { - int role = roles.at(i); - QVariant info; - switch (role) { - case Name: - info = list.at(index).first; - break; - case Number: - info = list.at(index).second; - break; - default: - break; - } - returnHash.insert(role, info); - } - return returnHash; - } - - void addItem(const QString &name, const QString &number) { - list.append(QPair(name, number)); - emit itemsInserted(list.count()-1, 1); - } - - void insertItem(int index, const QString &name, const QString &number) { - list.insert(index, QPair(name, number)); - emit itemsInserted(index, 1); - } - - void insertItems(int index, const QList > &items) { - for (int i=0; i(items[i].first, items[i].second)); - emit itemsInserted(index, items.count()); - } - - void removeItem(int index) { - list.removeAt(index); - emit itemsRemoved(index, 1); - } - - void removeItems(int index, int count) { - int c = count; - while (c--) - list.removeAt(index); - emit itemsRemoved(index, count); - } - - void moveItem(int from, int to) { - list.move(from, to); - emit itemsMoved(from, to, 1); - } - - void moveItems(int from, int to, int count) { - tst_qquicklistview_move(from, to, count, &list); - emit itemsMoved(from, to, count); - } - - void modifyItem(int index, const QString &name, const QString &number) { - list[index] = QPair(name, number); - emit itemsChanged(index, 1, roles()); - } - - void clear() { - int count = list.count(); - list.clear(); - emit itemsRemoved(0, count); - } - -private: - QList > list; -}; - - -class TestModel2 : public QAbstractListModel -{ -public: - enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; - - TestModel2(QObject *parent=0) : QAbstractListModel(parent) { - QHash roles; - roles[Name] = "name"; - roles[Number] = "number"; - setRoleNames(roles); - } - - 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) - 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(name, number)); - emit endInsertRows(); - } - - void addItems(const QList > &items) { - emit beginInsertRows(QModelIndex(), list.count(), list.count()+items.count()-1); - for (int i=0; i(items[i].first, items[i].second)); - emit endInsertRows(); - } - - void insertItem(int index, const QString &name, const QString &number) { - emit beginInsertRows(QModelIndex(), index, index); - list.insert(index, QPair(name, number)); - emit endInsertRows(); - } - - void insertItems(int index, const QList > &items) { - emit beginInsertRows(QModelIndex(), index, index+items.count()-1); - for (int i=0; i(items[i].first, items[i].second)); - emit endInsertRows(); - } - - void removeItem(int index) { - emit beginRemoveRows(QModelIndex(), index, index); - list.removeAt(index); - emit endRemoveRows(); - } - - void removeItems(int index, int count) { - emit beginRemoveRows(QModelIndex(), index, index+count-1); - while (count--) - 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 moveItems(int from, int to, int count) { - emit beginMoveRows(QModelIndex(), from, from+count-1, QModelIndex(), to > from ? to+count : to); - tst_qquicklistview_move(from, to, count, &list); - emit endMoveRows(); - } - - void modifyItem(int idx, const QString &name, const QString &number) { - list[idx] = QPair(name, number); - emit dataChanged(index(idx,0), index(idx,0)); - } - - void clear() { - int count = list.count(); - emit beginRemoveRows(QModelIndex(), 0, count-1); - list.clear(); - emit endRemoveRows(); - } - -private: - QList > list; -}; - tst_QQuickListView::tst_QQuickListView() { } @@ -854,7 +617,7 @@ void tst_QQuickListView::insertBeforeVisible() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1561,20 +1324,6 @@ void tst_QQuickListView::moved_data() << -20.0 * 3; // to minimize movement, 16,17,18 move to above item 0, and other items do not move } - -struct ListChange { - enum { Inserted, Removed, Moved, SetCurrent } type; - int index; - int count; - int to; // Move - - static ListChange insert(int index, int count = 1) { ListChange c = { Inserted, index, count, -1 }; return c; } - static ListChange remove(int index, int count = 1) { ListChange c = { Removed, index, count, -1 }; return c; } - static ListChange move(int index, int to, int count) { ListChange c = { Moved, index, count, to }; return c; } - static ListChange setCurrent(int index) { ListChange c = { SetCurrent, index, -1, -1 }; return c; } -}; -Q_DECLARE_METATYPE(QList) - void tst_QQuickListView::multipleChanges() { QFETCH(int, startCount); @@ -1585,7 +1334,7 @@ void tst_QQuickListView::multipleChanges() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QmlListModel model; for (int i = 0; i < startCount; i++) model.addItem("Item" + QString::number(i), ""); @@ -1802,7 +1551,7 @@ void tst_QQuickListView::swapWithFirstItem() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1831,7 +1580,7 @@ void tst_QQuickListView::enforceRange() { QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1869,7 +1618,7 @@ void tst_QQuickListView::enforceRange() QTRY_COMPARE(listview->currentIndex(), 6); // change model - TestModel model2; + QmlListModel model2; for (int i = 0; i < 5; i++) model2.addItem("Item" + QString::number(i), ""); @@ -1890,7 +1639,7 @@ void tst_QQuickListView::enforceRange_withoutHighlight() canvas->show(); QTest::qWait(200); - TestModel model; + QmlListModel model; model.addItem("Item 0", "a"); model.addItem("Item 1", "b"); model.addItem("Item 2", "b"); @@ -1931,7 +1680,7 @@ void tst_QQuickListView::spacing() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -2086,7 +1835,7 @@ void tst_QQuickListView::sectionsDelegate() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i/5)); @@ -2206,7 +1955,7 @@ void tst_QQuickListView::sectionsPositioning() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i/5)); @@ -2335,7 +2084,7 @@ void tst_QQuickListView::currentIndex_delayedItemCreation() QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; // test currentIndexChanged() is emitted even if currentIndex = 0 on start up // (since the currentItem will have changed and that shares the same index) @@ -2367,7 +2116,7 @@ void tst_QQuickListView::currentIndex_delayedItemCreation_data() void tst_QQuickListView::currentIndex() { - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -2504,7 +2253,7 @@ void tst_QQuickListView::currentIndex() void tst_QQuickListView::noCurrentIndex() { - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -2585,7 +2334,7 @@ void tst_QQuickListView::cacheBuffer() { QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 90; i++) model.addItem("Item" + QString::number(i), ""); @@ -2686,7 +2435,7 @@ void tst_QQuickListView::positionViewAtIndex() { QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3111,7 +2860,7 @@ void tst_QQuickListView::QTBUG_11105() { QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -3142,7 +2891,7 @@ void tst_QQuickListView::QTBUG_11105() listview->positionViewAtIndex(20, QQuickListView::Beginning); QCOMPARE(listview->contentY(), 280.); - TestModel model2; + QmlListModel model2; for (int i = 0; i < 5; i++) model2.addItem("Item" + QString::number(i), ""); @@ -3166,7 +2915,7 @@ void tst_QQuickListView::header() QFETCH(QPointF, changedContentPos); QFETCH(QPointF, resizeContentPos); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -3304,7 +3053,7 @@ void tst_QQuickListView::header_delayItemCreation() { QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; canvas->rootContext()->setContextProperty("setCurrentToZero", QVariant(false)); canvas->setSource(testFileUrl("fillModelOnComponentCompleted.qml")); @@ -3341,7 +3090,7 @@ void tst_QQuickListView::footer() QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 3; i++) model.addItem("Item" + QString::number(i), ""); @@ -3499,7 +3248,7 @@ void tst_QQuickListView::headerFooter() // Vertical QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -3529,7 +3278,7 @@ void tst_QQuickListView::headerFooter() // Horizontal QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -3560,7 +3309,7 @@ void tst_QQuickListView::headerFooter() // Horizontal RTL QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -3594,7 +3343,7 @@ void tst_QQuickListView::resizeView() { QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3675,7 +3424,7 @@ void tst_QQuickListView::resizeViewAndRepaint() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QmlListModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3712,7 +3461,7 @@ void tst_QQuickListView::sizeLessThan1() { QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -3854,7 +3603,7 @@ void tst_QQuickListView::resizeFirstDelegate() canvas->show(); // bug only occurs when all items in the model are visible - TestModel model; + QmlListModel model; for (int i = 0; i < 10; i++) model.addItem("Item" + QString::number(i), ""); @@ -3959,7 +3708,7 @@ void tst_QQuickListView::indexAt_itemAt() QQuickView *canvas = createView(); - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -4022,7 +3771,7 @@ void tst_QQuickListView::onAdd() QFETCH(int, itemsToAdd); const int delegateHeight = 10; - TestModel2 model; + QaimModel model; // these initial items should not trigger ListView.onAdd for (int i=0; i(testFileUrl("listviewtest.qml"), false); + items(testFileUrl("listviewtest.qml"), false); } void tst_QQuickListView::qListModelInterface_package_items() { - items(testFileUrl("listviewtest-package.qml"), true); + items(testFileUrl("listviewtest-package.qml"), true); } void tst_QQuickListView::qAbstractItemModel_items() { - items(testFileUrl("listviewtest.qml"), false); + items(testFileUrl("listviewtest.qml"), false); } void tst_QQuickListView::qListModelInterface_changed() { - changed(testFileUrl("listviewtest.qml"), false); + changed(testFileUrl("listviewtest.qml"), false); } void tst_QQuickListView::qListModelInterface_package_changed() { - changed(testFileUrl("listviewtest-package.qml"), true); + changed(testFileUrl("listviewtest-package.qml"), true); } void tst_QQuickListView::qAbstractItemModel_changed() { - changed(testFileUrl("listviewtest.qml"), false); + changed(testFileUrl("listviewtest.qml"), false); } void tst_QQuickListView::qListModelInterface_inserted() { - inserted(testFileUrl("listviewtest.qml")); + inserted(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qListModelInterface_package_inserted() { - inserted(testFileUrl("listviewtest-package.qml")); + inserted(testFileUrl("listviewtest-package.qml")); } void tst_QQuickListView::qListModelInterface_inserted_more() { - inserted_more(); + inserted_more(); } void tst_QQuickListView::qListModelInterface_inserted_more_data() @@ -4497,12 +4246,12 @@ void tst_QQuickListView::qListModelInterface_inserted_more_data() void tst_QQuickListView::qAbstractItemModel_inserted() { - inserted(testFileUrl("listviewtest.qml")); + inserted(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qAbstractItemModel_inserted_more() { - inserted_more(); + inserted_more(); } void tst_QQuickListView::qAbstractItemModel_inserted_more_data() @@ -4512,13 +4261,13 @@ void tst_QQuickListView::qAbstractItemModel_inserted_more_data() void tst_QQuickListView::qListModelInterface_removed() { - removed(testFileUrl("listviewtest.qml"), false); - removed(testFileUrl("listviewtest.qml"), true); + removed(testFileUrl("listviewtest.qml"), false); + removed(testFileUrl("listviewtest.qml"), true); } void tst_QQuickListView::qListModelInterface_removed_more() { - removed_more(testFileUrl("listviewtest.qml")); + removed_more(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qListModelInterface_removed_more_data() @@ -4528,19 +4277,19 @@ void tst_QQuickListView::qListModelInterface_removed_more_data() void tst_QQuickListView::qListModelInterface_package_removed() { - removed(testFileUrl("listviewtest-package.qml"), false); - removed(testFileUrl("listviewtest-package.qml"), true); + removed(testFileUrl("listviewtest-package.qml"), false); + removed(testFileUrl("listviewtest-package.qml"), true); } void tst_QQuickListView::qAbstractItemModel_removed() { - removed(testFileUrl("listviewtest.qml"), false); - removed(testFileUrl("listviewtest.qml"), true); + removed(testFileUrl("listviewtest.qml"), false); + removed(testFileUrl("listviewtest.qml"), true); } void tst_QQuickListView::qAbstractItemModel_removed_more() { - removed_more(testFileUrl("listviewtest.qml")); + removed_more(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qAbstractItemModel_removed_more_data() @@ -4550,7 +4299,7 @@ void tst_QQuickListView::qAbstractItemModel_removed_more_data() void tst_QQuickListView::qListModelInterface_moved() { - moved(testFileUrl("listviewtest.qml")); + moved(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qListModelInterface_moved_data() @@ -4560,7 +4309,7 @@ void tst_QQuickListView::qListModelInterface_moved_data() void tst_QQuickListView::qListModelInterface_package_moved() { - moved(testFileUrl("listviewtest-package.qml")); + moved(testFileUrl("listviewtest-package.qml")); } void tst_QQuickListView::qListModelInterface_package_moved_data() @@ -4570,7 +4319,7 @@ void tst_QQuickListView::qListModelInterface_package_moved_data() void tst_QQuickListView::qAbstractItemModel_moved() { - moved(testFileUrl("listviewtest.qml")); + moved(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qAbstractItemModel_moved_data() @@ -4580,32 +4329,32 @@ void tst_QQuickListView::qAbstractItemModel_moved_data() void tst_QQuickListView::qListModelInterface_clear() { - clear(testFileUrl("listviewtest.qml")); + clear(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qListModelInterface_package_clear() { - clear(testFileUrl("listviewtest-package.qml")); + clear(testFileUrl("listviewtest-package.qml")); } void tst_QQuickListView::qAbstractItemModel_clear() { - clear(testFileUrl("listviewtest.qml")); + clear(testFileUrl("listviewtest.qml")); } void tst_QQuickListView::qListModelInterface_sections() { - sections(testFileUrl("listview-sections.qml")); + sections(testFileUrl("listview-sections.qml")); } void tst_QQuickListView::qListModelInterface_package_sections() { - sections(testFileUrl("listview-sections-package.qml")); + sections(testFileUrl("listview-sections-package.qml")); } void tst_QQuickListView::qAbstractItemModel_sections() { - sections(testFileUrl("listview-sections.qml")); + sections(testFileUrl("listview-sections.qml")); } void tst_QQuickListView::creationContext() @@ -4642,32 +4391,6 @@ void tst_QQuickListView::QTBUG_21742() QCOMPARE(rootItem->property("count").toInt(), 1); } -QQuickView *tst_QQuickListView::createView() -{ - QQuickView *canvas = new QQuickView(0); - canvas->setGeometry(0,0,240,320); - - return canvas; -} - -void tst_QQuickListView::flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration) -{ - const int pointCount = 5; - QPoint diff = to - from; - - // send press, five equally spaced moves, and release. - QTest::mousePress(canvas, Qt::LeftButton, 0, from); - - for (int i = 0; i < pointCount; ++i) { - QMouseEvent mv(QEvent::MouseMove, from + (i+1)*diff/pointCount, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); - QGuiApplication::sendEvent(canvas, &mv); - QTest::qWait(duration/pointCount); - QCoreApplication::processEvents(); - } - - QTest::mouseRelease(canvas, Qt::LeftButton, 0, to); -} - void tst_QQuickListView::asynchronous() { QQuickView *canvas = createView(); @@ -4831,7 +4554,7 @@ void tst_QQuickListView::snapOneItem() void tst_QQuickListView::unrequestedVisibility() { - TestModel model; + QmlListModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -4997,79 +4720,6 @@ void tst_QQuickListView::unrequestedVisibility() delete canvas; } -QQuickItem *tst_QQuickListView::findVisibleChild(QQuickItem *parent, const QString &objectName) -{ - QQuickItem *item = 0; - QList items = parent->findChildren(objectName); - for (int i = 0; i < items.count(); ++i) { - if (items.at(i)->isVisible()) { - item = items.at(i); - break; - } - } - return item; -} -/* - Find an item with the specified objectName. If index is supplied then the - item must also evaluate the {index} expression equal to index -*/ -template -T *tst_QQuickListView::findItem(QQuickItem *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QDeclarativeExpression e(qmlContext(item), item, "index"); - if (e.evaluate().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} - -template -QList tst_QQuickListView::findItems(QQuickItem *parent, const QString &objectName, bool visibleOnly) -{ - QList items; - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item || (visibleOnly && !item->isVisible())) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) - items.append(static_cast(item)); - items += findItems(item, objectName); - } - - return items; -} - -void tst_QQuickListView::dumpTree(QQuickItem *parent, int depth) -{ - static QString padding(" "); - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - qDebug() << padding.left(depth*2) << item; - dumpTree(item, depth+1); - } -} QTEST_MAIN(tst_QQuickListView) diff --git a/tests/auto/qtquick2/qquickpathview/qquickpathview.pro b/tests/auto/qtquick2/qquickpathview/qquickpathview.pro index 3d2a4ff..027abb6 100644 --- a/tests/auto/qtquick2/qquickpathview/qquickpathview.pro +++ b/tests/auto/qtquick2/qquickpathview/qquickpathview.pro @@ -5,6 +5,7 @@ macx:CONFIG -= app_bundle SOURCES += tst_qquickpathview.cpp include (../../shared/util.pri) +include (../shared/util.pri) testDataFiles.files = data testDataFiles.path = . diff --git a/tests/auto/qtquick2/qquickpathview/tst_qquickpathview.cpp b/tests/auto/qtquick2/qquickpathview/tst_qquickpathview.cpp index 2a4e1be..6b36c7e 100644 --- a/tests/auto/qtquick2/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/qtquick2/qquickpathview/tst_qquickpathview.cpp @@ -52,12 +52,17 @@ #include #include #include -#include #include #include #include #include "../../shared/util.h" +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + static void initStandardTreeModel(QStandardItemModel *model) { @@ -118,13 +123,6 @@ private slots: void creationContext(); void currentOffsetOnInsertion(); void asynchronous(); - -private: - QQuickView *createView(); - template - T *findItem(QQuickItem *parent, const QString &objectName, int index=-1); - template - QList findItems(QQuickItem *parent, const QString &objectName); }; class TestObject : public QObject @@ -157,116 +155,6 @@ private: int mPathItemCount; }; -class TestModel : public QAbstractListModel -{ -public: - enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; - - TestModel(QObject *parent=0) : QAbstractListModel(parent) { - QHash roles; - roles[Name] = "name"; - roles[Number] = "number"; - setRoleNames(roles); - } - - 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) - 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) { - beginInsertRows(QModelIndex(), list.count(), list.count()); - list.append(QPair(name, number)); - endInsertRows(); - } - - void insertItem(int index, const QString &name, const QString &number) { - beginInsertRows(QModelIndex(), index, index); - list.insert(index, QPair(name, number)); - endInsertRows(); - } - - void insertItems(int index, const QList > &items) { - beginInsertRows(QModelIndex(), index, index+items.count()-1); - for (int i=0; i(items[i].first, items[i].second)); - endInsertRows(); - } - - void removeItem(int index) { - beginRemoveRows(QModelIndex(), index, index); - list.removeAt(index); - endRemoveRows(); - } - - void removeItems(int index, int count) { - emit beginRemoveRows(QModelIndex(), index, index+count-1); - while (count--) - list.removeAt(index); - emit endRemoveRows(); - } - - void moveItem(int from, int to) { - beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); - list.move(from, to); - endMoveRows(); - } - - void moveItems(int from, int to, int count) { - beginMoveRows(QModelIndex(), from, from+count-1, QModelIndex(), to > from ? to+count : to); - move(from, to, count); - endMoveRows(); - } - - void modifyItem(int idx, const QString &name, const QString &number) { - list[idx] = QPair(name, number); - emit dataChanged(index(idx,0), index(idx,0)); - } - - void move(int from, int to, int n) - { - if (from > to) { - // Only move forwards - flip if backwards moving - int tfrom = from; - int tto = to; - from = tto; - to = tto+n; - n = tfrom-tto; - } - if (n == 1) { - list.move(from, to); - } else { - QList > replaced; - int i=0; - QList >::ConstIterator it=list.begin(); it += from+n; - for (; i >::ConstIterator f=replaced.begin(); - QList >::Iterator t=list.begin(); t += from; - for (; f != replaced.end(); ++f, ++t) - *t = *f; - } - } - -private: - QList > list; -}; - - tst_QQuickPathView::tst_QQuickPathView() { } @@ -295,7 +183,7 @@ void tst_QQuickPathView::items() { QQuickView *canvas = createView(); - TestModel model; + QaimModel model; model.addItem("Fred", "12345"); model.addItem("John", "2345"); model.addItem("Bob", "54321"); @@ -425,7 +313,7 @@ void tst_QQuickPathView::insertModel() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; model.addItem("Ben", "12345"); model.addItem("Bohn", "2345"); model.addItem("Bob", "54321"); @@ -511,7 +399,7 @@ void tst_QQuickPathView::removeModel() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; model.addItem("Ben", "12345"); model.addItem("Bohn", "2345"); model.addItem("Bob", "54321"); @@ -602,7 +490,7 @@ void tst_QQuickPathView::moveModel() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; model.addItem("Ben", "12345"); model.addItem("Bohn", "2345"); model.addItem("Bob", "54321"); @@ -691,7 +579,7 @@ void tst_QQuickPathView::dataModel() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - TestModel model; + QaimModel model; model.addItem("red", "1"); model.addItem("green", "2"); model.addItem("blue", "3"); @@ -801,7 +689,7 @@ void tst_QQuickPathView::pathMoved() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; model.addItem("Ben", "12345"); model.addItem("Bohn", "2345"); model.addItem("Bob", "54321"); @@ -858,7 +746,7 @@ void tst_QQuickPathView::setCurrentIndex() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; model.addItem("Ben", "12345"); model.addItem("Bohn", "2345"); model.addItem("Bob", "54321"); @@ -1430,7 +1318,7 @@ void tst_QQuickPathView::currentOffsetOnInsertion() QQuickView *canvas = createView(); canvas->show(); - TestModel model; + QaimModel model; QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -1560,64 +1448,6 @@ void tst_QQuickPathView::asynchronous() delete canvas; } -QQuickView *tst_QQuickPathView::createView() -{ - QQuickView *canvas = new QQuickView(0); - canvas->setGeometry(0,0,240,320); - - 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 -T *tst_QQuickPathView::findItem(QQuickItem *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QDeclarativeExpression e(qmlContext(item), item, "index"); - if (e.evaluate().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} - -template -QList tst_QQuickPathView::findItems(QQuickItem *parent, const QString &objectName) -{ - QList items; - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QQuickItem::children().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) - items.append(static_cast(item)); - items += findItems(item, objectName); - } - - return items; -} - void tst_QQuickPathView::missingPercent() { QDeclarativeEngine engine; @@ -1628,7 +1458,6 @@ void tst_QQuickPathView::missingPercent() delete obj; } - QTEST_MAIN(tst_QQuickPathView) #include "tst_qquickpathview.moc" diff --git a/tests/auto/qtquick2/qquickrepeater/data/repeater1.qml b/tests/auto/qtquick2/qquickrepeater/data/repeater1.qml index 596dc91..3e6f407 100644 --- a/tests/auto/qtquick2/qquickrepeater/data/repeater1.qml +++ b/tests/auto/qtquick2/qquickrepeater/data/repeater1.qml @@ -1,28 +1,30 @@ import QtQuick 2.0 -Rectangle { - id: container - objectName: "container" - width: 240 - height: 320 - color: "white" - Text { - text: "Zero" - } - Repeater { - id: repeater - objectName: "repeater" +Item { + Rectangle { + id: container + objectName: "container" width: 240 height: 320 - model: testData - Component { - Text { - y: index*20 - text: modelData + color: "white" + Text { + text: "Zero" + } + Repeater { + id: repeater + objectName: "repeater" + width: 240 + height: 320 + model: testData + Component { + Text { + y: index*20 + text: modelData + } } } - } - Text { - text: "Last" + Text { + text: "Last" + } } } diff --git a/tests/auto/qtquick2/qquickrepeater/qquickrepeater.pro b/tests/auto/qtquick2/qquickrepeater/qquickrepeater.pro index fa1781f..b791faf 100644 --- a/tests/auto/qtquick2/qquickrepeater/qquickrepeater.pro +++ b/tests/auto/qtquick2/qquickrepeater/qquickrepeater.pro @@ -5,6 +5,7 @@ macx:CONFIG -= app_bundle SOURCES += tst_qquickrepeater.cpp include (../../shared/util.pri) +include (../shared/util.pri) testFiles.files = data testFiles.path = . diff --git a/tests/auto/qtquick2/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/qtquick2/qquickrepeater/tst_qquickrepeater.cpp index 518ea18..5932270 100644 --- a/tests/auto/qtquick2/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/qtquick2/qquickrepeater/tst_qquickrepeater.cpp @@ -51,6 +51,12 @@ #include #include "../../shared/util.h" +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + class tst_QQuickRepeater : public QDeclarativeDataTest { @@ -71,13 +77,6 @@ private slots: void properties(); void asynchronous(); void initParent(); - -private: - QQuickView *createView(); - template - T *findItem(QObject *parent, const QString &objectName, int index); - template - T *findItem(QObject *parent, const QString &id); }; class TestObject : public QObject @@ -104,67 +103,6 @@ private: bool mUseModel; }; -class TestModel : public QAbstractListModel -{ -public: - enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; - - TestModel(QObject *parent=0) : QAbstractListModel(parent) { - QHash roles; - roles[Name] = "name"; - roles[Number] = "number"; - setRoleNames(roles); - } - - 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) - 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(name, number)); - emit endInsertRows(); - } - - void insertItem(int index, const QString &name, const QString &number) { - emit beginInsertRows(QModelIndex(), index, index); - list.insert(index, QPair(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(name, number); - emit dataChanged(index(idx,0), index(idx,0)); - } - -private: - QList > list; -}; - - tst_QQuickRepeater::tst_QQuickRepeater() { } @@ -306,7 +244,7 @@ void tst_QQuickRepeater::dataModel_adding() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - TestModel testModel; + QaimModel testModel; ctxt->setContextProperty("testData", &testModel); canvas->setSource(testFileUrl("repeater2.qml")); qApp->processEvents(); @@ -370,7 +308,7 @@ void tst_QQuickRepeater::dataModel_removing() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - TestModel testModel; + QaimModel testModel; testModel.addItem("one", "1"); testModel.addItem("two", "2"); testModel.addItem("three", "3"); @@ -438,7 +376,7 @@ void tst_QQuickRepeater::dataModel_changes() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - TestModel testModel; + QaimModel testModel; testModel.addItem("one", "1"); testModel.addItem("two", "2"); testModel.addItem("three", "3"); @@ -701,59 +639,6 @@ void tst_QQuickRepeater::initParent() QCOMPARE(qvariant_cast(rootObject->property("parentItem")), rootObject); } -QQuickView *tst_QQuickRepeater::createView() -{ - QQuickView *canvas = new QQuickView(0); - canvas->setGeometry(0,0,240,320); - - return canvas; -} - -template -T *tst_QQuickRepeater::findItem(QObject *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->children().count() << "children"; - for (int i = 0; i < parent->children().count(); ++i) { - QQuickItem *item = qobject_cast(parent->children().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QDeclarativeExpression e(qmlContext(item), item, "index"); - if (e.evaluate().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} - -template -T *tst_QQuickRepeater::findItem(QObject *parent, const QString &objectName) -{ - const QMetaObject &mo = T::staticMetaObject; - if (mo.cast(parent) && (objectName.isEmpty() || parent->objectName() == objectName)) - return static_cast(parent); - for (int i = 0; i < parent->children().count(); ++i) { - QQuickItem *child = qobject_cast(parent->children().at(i)); - if (!child) - continue; - QQuickItem *item = findItem(child, objectName); - if (item) - return static_cast(item); - } - - return 0; -} - QTEST_MAIN(tst_QQuickRepeater) #include "tst_qquickrepeater.moc" diff --git a/tests/auto/qtquick2/qquickvisualdatamodel/qquickvisualdatamodel.pro b/tests/auto/qtquick2/qquickvisualdatamodel/qquickvisualdatamodel.pro index 26112cf..6db887d 100644 --- a/tests/auto/qtquick2/qquickvisualdatamodel/qquickvisualdatamodel.pro +++ b/tests/auto/qtquick2/qquickvisualdatamodel/qquickvisualdatamodel.pro @@ -5,6 +5,7 @@ macx:CONFIG -= app_bundle SOURCES += tst_qquickvisualdatamodel.cpp include (../../shared/util.pri) +include (../shared/util.pri) testDataFiles.files = data testDataFiles.path = . diff --git a/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 114123f..1b6a762 100644 --- a/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -39,6 +39,8 @@ ** ****************************************************************************/ #include "../../shared/util.h" +#include "../shared/visualtestutil.h" + #include #include #include @@ -55,6 +57,8 @@ #include #include +using namespace QQuickVisualTestUtil; + template int lengthOf(const T (&)[N]) { return N; } static void initStandardTreeModel(QStandardItemModel *model) @@ -249,8 +253,6 @@ private: bool failed; QDeclarativeEngine engine; - template - T *findItem(QQuickItem *parent, const QString &objectName, int index = -1); }; Q_DECLARE_METATYPE(QDeclarativeChangeSet) @@ -3438,32 +3440,6 @@ void tst_qquickvisualdatamodel::warnings() QCOMPARE(evaluate(listView, "count"), count); } -template -T *tst_qquickvisualdatamodel::findItem(QQuickItem *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QQuickItem *item = qobject_cast(parent->childItems().at(i)); - if (!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QDeclarativeExpression e(qmlContext(item), item, "index"); - if (e.evaluate().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} QTEST_MAIN(tst_qquickvisualdatamodel) diff --git a/tests/auto/qtquick2/shared/util.pri b/tests/auto/qtquick2/shared/util.pri new file mode 100644 index 0000000..eddbe4b --- /dev/null +++ b/tests/auto/qtquick2/shared/util.pri @@ -0,0 +1,7 @@ + +HEADERS += $$PWD/visualtestutil.h \ + $$PWD/viewtestutil.h +SOURCES += $$PWD/visualtestutil.cpp \ + $$PWD/viewtestutil.cpp + +DEFINES += QT_DECLARATIVETEST_DATADIR=\\\"$${_PRO_FILE_PWD_}/data\\\" diff --git a/tests/auto/qtquick2/shared/viewtestutil.cpp b/tests/auto/qtquick2/shared/viewtestutil.cpp new file mode 100644 index 0000000..ed2066d --- /dev/null +++ b/tests/auto/qtquick2/shared/viewtestutil.cpp @@ -0,0 +1,345 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "viewtestutil.h" + +#include + +#include + +template +static void qdeclarativemodelviewstestutil_move(int from, int to, int n, T *items) +{ + if (from > to) { + // Only move forwards - flip if backwards moving + int tfrom = from; + int tto = to; + from = tto; + to = tto+n; + n = tfrom-tto; + } + + T replaced; + int i=0; + typename T::ConstIterator it=items->begin(); it += from+n; + for (; ibegin(); it += from; + for (; ibegin(); t += from; + for (; f != replaced.end(); ++f, ++t) + *t = *f; +} + +QQuickView *QQuickViewTestUtil::createView() +{ + QQuickView *canvas = new QQuickView(0); + canvas->setGeometry(0,0,240,320); + + return canvas; +} + +void QQuickViewTestUtil::flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration) +{ + const int pointCount = 5; + QPoint diff = to - from; + + // send press, five equally spaced moves, and release. + QTest::mousePress(canvas, Qt::LeftButton, 0, from); + + for (int i = 0; i < pointCount; ++i) { + QMouseEvent mv(QEvent::MouseMove, from + (i+1)*diff/pointCount, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QGuiApplication::sendEvent(canvas, &mv); + QTest::qWait(duration/pointCount); + QCoreApplication::processEvents(); + } + + QTest::mouseRelease(canvas, Qt::LeftButton, 0, to); + QTest::qWait(50); +} + +QQuickViewTestUtil::QmlListModel::QmlListModel(QObject *parent) + : QListModelInterface(parent) +{ +} + +QQuickViewTestUtil::QmlListModel::~QmlListModel() +{ +} + +QString QQuickViewTestUtil::QmlListModel::name(int index) const +{ + return list.at(index).first; +} + +QString QQuickViewTestUtil::QmlListModel::number(int index) const +{ + return list.at(index).second; +} + +int QQuickViewTestUtil::QmlListModel::count() const +{ + return list.count(); +} + +QList QQuickViewTestUtil::QmlListModel::roles() const +{ + return QList() << Name << Number; +} + +QString QQuickViewTestUtil::QmlListModel::toString(int role) const +{ + switch (role) { + case Name: + return "name"; + case Number: + return "number"; + default: + return ""; + } +} + +QVariant QQuickViewTestUtil::QmlListModel::data(int index, int role) const +{ + if (role==0) + return list.at(index).first; + if (role==1) + return list.at(index).second; + return QVariant(); +} + +QHash QQuickViewTestUtil::QmlListModel::data(int index, const QList &roles) const +{ + QHash returnHash; + + for (int i = 0; i < roles.size(); ++i) { + int role = roles.at(i); + QVariant info; + switch (role) { + case Name: + info = list.at(index).first; + break; + case Number: + info = list.at(index).second; + break; + default: + break; + } + returnHash.insert(role, info); + } + return returnHash; +} + +void QQuickViewTestUtil::QmlListModel::addItem(const QString &name, const QString &number) +{ + list.append(QPair(name, number)); + emit itemsInserted(list.count()-1, 1); +} + +void QQuickViewTestUtil::QmlListModel::insertItem(int index, const QString &name, const QString &number) +{ + list.insert(index, QPair(name, number)); + emit itemsInserted(index, 1); +} + +void QQuickViewTestUtil::QmlListModel::insertItems(int index, const QList > &items) +{ + for (int i=0; i(items[i].first, items[i].second)); + emit itemsInserted(index, items.count()); +} + +void QQuickViewTestUtil::QmlListModel::removeItem(int index) +{ + list.removeAt(index); + emit itemsRemoved(index, 1); +} + +void QQuickViewTestUtil::QmlListModel::removeItems(int index, int count) +{ + int c = count; + while (c--) + list.removeAt(index); + emit itemsRemoved(index, count); +} + +void QQuickViewTestUtil::QmlListModel::moveItem(int from, int to) +{ + list.move(from, to); + emit itemsMoved(from, to, 1); +} + +void QQuickViewTestUtil::QmlListModel::moveItems(int from, int to, int count) +{ + qdeclarativemodelviewstestutil_move(from, to, count, &list); + emit itemsMoved(from, to, count); +} + +void QQuickViewTestUtil::QmlListModel::modifyItem(int index, const QString &name, const QString &number) +{ + list[index] = QPair(name, number); + emit itemsChanged(index, 1, roles()); +} + +void QQuickViewTestUtil::QmlListModel::clear() { + int count = list.count(); + list.clear(); + emit itemsRemoved(0, count); +} + + +QQuickViewTestUtil::QaimModel::QaimModel(QObject *parent) + : QAbstractListModel(parent) +{ + QHash roles; + roles[Name] = "name"; + roles[Number] = "number"; + setRoleNames(roles); +} + +int QQuickViewTestUtil::QaimModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return list.count(); +} + +QVariant QQuickViewTestUtil::QaimModel::data(const QModelIndex &index, int role) 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 QQuickViewTestUtil::QaimModel::count() const +{ + return rowCount(); +} + +QString QQuickViewTestUtil::QaimModel::name(int index) const +{ + return list.at(index).first; +} + +QString QQuickViewTestUtil::QaimModel::number(int index) const +{ + return list.at(index).second; +} + +void QQuickViewTestUtil::QaimModel::addItem(const QString &name, const QString &number) +{ + emit beginInsertRows(QModelIndex(), list.count(), list.count()); + list.append(QPair(name, number)); + emit endInsertRows(); +} + +void QQuickViewTestUtil::QaimModel::addItems(const QList > &items) +{ + emit beginInsertRows(QModelIndex(), list.count(), list.count()+items.count()-1); + for (int i=0; i(items[i].first, items[i].second)); + emit endInsertRows(); +} + +void QQuickViewTestUtil::QaimModel::insertItem(int index, const QString &name, const QString &number) +{ + emit beginInsertRows(QModelIndex(), index, index); + list.insert(index, QPair(name, number)); + emit endInsertRows(); +} + +void QQuickViewTestUtil::QaimModel::insertItems(int index, const QList > &items) +{ + emit beginInsertRows(QModelIndex(), index, index+items.count()-1); + for (int i=0; i(items[i].first, items[i].second)); + emit endInsertRows(); +} + +void QQuickViewTestUtil::QaimModel::removeItem(int index) +{ + emit beginRemoveRows(QModelIndex(), index, index); + list.removeAt(index); + emit endRemoveRows(); +} + +void QQuickViewTestUtil::QaimModel::removeItems(int index, int count) +{ + emit beginRemoveRows(QModelIndex(), index, index+count-1); + while (count--) + list.removeAt(index); + emit endRemoveRows(); +} + +void QQuickViewTestUtil::QaimModel::moveItem(int from, int to) +{ + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); +} + +void QQuickViewTestUtil::QaimModel::moveItems(int from, int to, int count) +{ + emit beginMoveRows(QModelIndex(), from, from+count-1, QModelIndex(), to > from ? to+count : to); + qdeclarativemodelviewstestutil_move(from, to, count, &list); + emit endMoveRows(); +} + +void QQuickViewTestUtil::QaimModel::modifyItem(int idx, const QString &name, const QString &number) +{ + list[idx] = QPair(name, number); + emit dataChanged(index(idx,0), index(idx,0)); +} + +void QQuickViewTestUtil::QaimModel::clear() +{ + int count = list.count(); + emit beginRemoveRows(QModelIndex(), 0, count-1); + list.clear(); + emit endRemoveRows(); +} + diff --git a/tests/auto/qtquick2/shared/viewtestutil.h b/tests/auto/qtquick2/shared/viewtestutil.h new file mode 100644 index 0000000..98b0dbb --- /dev/null +++ b/tests/auto/qtquick2/shared/viewtestutil.h @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKVIEWTESTUTIL_H +#define QQUICKVIEWTESTUTIL_H + +#include +#include +#include +#include + +QT_FORWARD_DECLARE_CLASS(QQuickView) + +namespace QQuickViewTestUtil +{ + QQuickView *createView(); + + void flick(QQuickView *canvas, const QPoint &from, const QPoint &to, int duration); + + struct ListChange { + enum { Inserted, Removed, Moved, SetCurrent } type; + int index; + int count; + int to; // Move + + static ListChange insert(int index, int count = 1) { ListChange c = { Inserted, index, count, -1 }; return c; } + static ListChange remove(int index, int count = 1) { ListChange c = { Removed, index, count, -1 }; return c; } + static ListChange move(int index, int to, int count) { ListChange c = { Moved, index, count, to }; return c; } + static ListChange setCurrent(int index) { ListChange c = { SetCurrent, index, -1, -1 }; return c; } + }; + + class QmlListModel : public QListModelInterface + { + Q_OBJECT + public: + QmlListModel(QObject *parent = 0); + ~QmlListModel(); + + enum Roles { Name, Number }; + + QString name(int index) const; + QString number(int index) const; + + int count() const; + + QList roles() const; + QString toString(int role) const; + + QVariant data(int index, int role) const; + QHash data(int index, const QList &roles) const; + + void addItem(const QString &name, const QString &number); + void insertItem(int index, const QString &name, const QString &number); + void insertItems(int index, const QList > &items); + + void removeItem(int index); + void removeItems(int index, int count); + + void moveItem(int from, int to); + void moveItems(int from, int to, int count); + + void modifyItem(int index, const QString &name, const QString &number); + + void clear(); + + private: + QList > list; + }; + + class QaimModel : public QAbstractListModel + { + Q_OBJECT + public: + enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; + + QaimModel(QObject *parent=0); + + int rowCount(const QModelIndex &parent=QModelIndex()) const; + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; + + int count() const; + QString name(int index) const; + QString number(int index) const; + + void addItem(const QString &name, const QString &number); + void addItems(const QList > &items); + void insertItem(int index, const QString &name, const QString &number); + void insertItems(int index, const QList > &items); + + void removeItem(int index); + void removeItems(int index, int count); + + void moveItem(int from, int to); + void moveItems(int from, int to, int count); + + void modifyItem(int idx, const QString &name, const QString &number); + + void clear(); + + private: + QList > list; + }; + +} + +Q_DECLARE_METATYPE(QList) + +#endif // QQUICKVIEWTESTUTIL_H diff --git a/tests/auto/qtquick2/shared/visualtestutil.cpp b/tests/auto/qtquick2/shared/visualtestutil.cpp new file mode 100644 index 0000000..8680df1 --- /dev/null +++ b/tests/auto/qtquick2/shared/visualtestutil.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "visualtestutil.h" + +#include +#include + +QQuickItem *QQuickVisualTestUtil::findVisibleChild(QQuickItem *parent, const QString &objectName) +{ + QQuickItem *item = 0; + QList items = parent->findChildren(objectName); + for (int i = 0; i < items.count(); ++i) { + if (items.at(i)->isVisible()) { + item = items.at(i); + break; + } + } + return item; +} + +void QQuickVisualTestUtil::dumpTree(QQuickItem *parent, int depth) +{ + static QString padding(" "); + for (int i = 0; i < parent->childItems().count(); ++i) { + QQuickItem *item = qobject_cast(parent->childItems().at(i)); + if (!item) + continue; + qDebug() << padding.left(depth*2) << item; + dumpTree(item, depth+1); + } +} + diff --git a/tests/auto/qtquick2/shared/visualtestutil.h b/tests/auto/qtquick2/shared/visualtestutil.h new file mode 100644 index 0000000..ceed4b0 --- /dev/null +++ b/tests/auto/qtquick2/shared/visualtestutil.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKVISUALTESTUTIL_H +#define QQUICKVISUALTESTUTIL_H + +#include +#include + +namespace QQuickVisualTestUtil +{ + QQuickItem *findVisibleChild(QQuickItem *parent, const QString &objectName); + + void dumpTree(QQuickItem *parent, int depth = 0); + + + /* + Find an item with the specified objectName. If index is supplied then the + item must also evaluate the {index} expression equal to index + */ + template + T *findItem(QQuickItem *parent, const QString &objectName, int index = -1) + { + const QMetaObject &mo = T::staticMetaObject; + for (int i = 0; i < parent->childItems().count(); ++i) { + QQuickItem *item = qobject_cast(parent->childItems().at(i)); + if (!item) + continue; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + if (index != -1) { + QDeclarativeExpression e(qmlContext(item), item, "index"); + if (e.evaluate().toInt() == index) + return static_cast(item); + } else { + return static_cast(item); + } + } + item = findItem(item, objectName, index); + if (item) + return static_cast(item); + } + + return 0; + } + + template + QList findItems(QQuickItem *parent, const QString &objectName, bool visibleOnly = true) + { + QList items; + const QMetaObject &mo = T::staticMetaObject; + for (int i = 0; i < parent->childItems().count(); ++i) { + QQuickItem *item = qobject_cast(parent->childItems().at(i)); + if (!item || (visibleOnly && !item->isVisible())) + continue; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast(item)); + items += findItems(item, objectName); + } + + return items; + } +} + +#endif // QQUICKVISUALTESTUTIL_H -- 2.7.4