aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2012-01-31 17:15:00 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-07 11:45:38 +0100
commit5e42176970c05c015685194aecf954aaac5d9e1e (patch)
tree110385902f865b7cbe13ea393a023c3ec3d6067b /tests/auto
parenta52c11229a0c55071a43c9352b6c2e9e8ae481fa (diff)
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 <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtquick2/qquickanchors/qquickanchors.pro1
-rw-r--r--tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp29
-rw-r--r--tests/auto/qtquick2/qquickflickable/qquickflickable.pro1
-rw-r--r--tests/auto/qtquick2/qquickflickable/tst_qquickflickable.cpp49
-rw-r--r--tests/auto/qtquick2/qquickfocusscope/qquickfocusscope.pro1
-rw-r--r--tests/auto/qtquick2/qquickfocusscope/tst_qquickfocusscope.cpp28
-rw-r--r--tests/auto/qtquick2/qquickgridview/qquickgridview.pro1
-rw-r--r--tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp329
-rw-r--r--tests/auto/qtquick2/qquickimage/qquickimage.pro1
-rw-r--r--tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp38
-rw-r--r--tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp26
-rw-r--r--tests/auto/qtquick2/qquicklistview/qquicklistview.pro1
-rw-r--r--tests/auto/qtquick2/qquicklistview/tst_qquicklistview.cpp478
-rw-r--r--tests/auto/qtquick2/qquickpathview/qquickpathview.pro1
-rw-r--r--tests/auto/qtquick2/qquickpathview/tst_qquickpathview.cpp199
-rw-r--r--tests/auto/qtquick2/qquickrepeater/data/repeater1.qml42
-rw-r--r--tests/auto/qtquick2/qquickrepeater/qquickrepeater.pro1
-rw-r--r--tests/auto/qtquick2/qquickrepeater/tst_qquickrepeater.cpp133
-rw-r--r--tests/auto/qtquick2/qquickvisualdatamodel/qquickvisualdatamodel.pro1
-rw-r--r--tests/auto/qtquick2/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp32
-rw-r--r--tests/auto/qtquick2/shared/util.pri7
-rw-r--r--tests/auto/qtquick2/shared/viewtestutil.cpp345
-rw-r--r--tests/auto/qtquick2/shared/viewtestutil.h146
-rw-r--r--tests/auto/qtquick2/shared/visualtestutil.cpp71
-rw-r--r--tests/auto/qtquick2/shared/visualtestutil.h102
25 files changed, 858 insertions, 1205 deletions
diff --git a/tests/auto/qtquick2/qquickanchors/qquickanchors.pro b/tests/auto/qtquick2/qquickanchors/qquickanchors.pro
index 25711d4848..bd94f9cceb 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 54e3008549..ff3426bf13 100644
--- a/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp
+++ b/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp
@@ -49,10 +49,13 @@
#include <QtQuick/private/qquickanchors_p_p.h>
#include <QtQuick/private/qquickitem_p.h>
#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<typename T>
-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<QQuickItem*>(parent->childItems().at(i));
- if (!item)
- continue;
- //qDebug() << "try" << item;
- if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName))
- return static_cast<T*>(item);
- item = findItem<T>(item, objectName);
- if (item)
- return static_cast<T*>(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 693913001a..d1b8b6948f 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 a17687073c..d357877ed5 100644
--- a/tests/auto/qtquick2/qquickflickable/tst_qquickflickable.cpp
+++ b/tests/auto/qtquick2/qquickflickable/tst_qquickflickable.cpp
@@ -48,8 +48,13 @@
#include <private/qdeclarativevaluetype_p.h>
#include <math.h>
#include "../../shared/util.h"
+#include "../shared/viewtestutil.h"
+#include "../shared/visualtestutil.h"
#include <QtOpenGL/QGLShaderProgram>
+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<typename T>
- 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<typename T>
-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<QQuickItem*>(parent->childItems().at(i));
- if (!item)
- continue;
- //qDebug() << "try" << item;
- if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
- return static_cast<T*>(item);
- }
- item = findItem<T>(item, objectName);
- if (item)
- return static_cast<T*>(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 75bd663405..d83f6ca7a3 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 c52cfaec2c..4264c68d92 100644
--- a/tests/auto/qtquick2/qquickfocusscope/tst_qquickfocusscope.cpp
+++ b/tests/auto/qtquick2/qquickfocusscope/tst_qquickfocusscope.cpp
@@ -48,6 +48,9 @@
#include <QtQuick/private/qquicktext_p.h>
#include <QtQuick/private/qquickfocusscope_p.h>
#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<typename T>
- 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<typename T>
-T *tst_qquickfocusscope::findItem(QQuickItem *parent, const QString &objectName)
-{
- const QMetaObject &mo = T::staticMetaObject;
- QList<QQuickItem *> 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<T*>(item);
- }
- item = findItem<T>(item, objectName);
- if (item)
- return static_cast<T*>(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 ad026f0ad4..583aedae8c 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 fb2b6b46f9..e6b27f808c 100644
--- a/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp
+++ b/tests/auto/qtquick2/qquickgridview/tst_qquickgridview.cpp
@@ -48,16 +48,20 @@
#include <QtDeclarative/qdeclarativeexpression.h>
#include <QtDeclarative/qdeclarativeincubator.h>
#include <QtQuick/private/qquickitem_p.h>
-#include <QtDeclarative/private/qlistmodelinterface_p.h>
#include <QtQuick/private/qquickgridview_p.h>
#include <QtQuick/private/qquicktext_p.h>
#include <QtDeclarative/private/qdeclarativelistmodel_p.h>
#include "../../shared/util.h"
+#include "../shared/viewtestutil.h"
+#include "../shared/visualtestutil.h"
#include <QtGui/qguiapplication.h>
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<typename T>
- T *findItem(QQuickItem *parent, const QString &id, int index=-1);
- template<typename T>
- QList<T*> findItems(QQuickItem *parent, const QString &objectName);
- void dumpTree(QQuickItem *parent, int depth = 0);
-};
-
-template<typename T>
-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 (; i<to-from; ++i,++it)
- replaced.append(*it);
- i=0;
- it=items->begin(); it += from;
- for (; i<n; ++i,++it)
- replaced.append(*it);
- typename T::ConstIterator f=replaced.begin();
- typename T::Iterator t=items->begin(); 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<int, QByteArray> 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<QString,QString>(name, number));
- emit endInsertRows();
- }
-
- void addItems(const QList<QPair<QString, QString> > &items) {
- emit beginInsertRows(QModelIndex(), list.count(), list.count()+items.count()-1);
- for (int i=0; i<items.count(); i++)
- list.append(QPair<QString,QString>(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<QString,QString>(name, number));
- emit endInsertRows();
- }
-
- void insertItems(int index, const QList<QPair<QString, QString> > &items) {
- emit beginInsertRows(QModelIndex(), index, index + items.count() - 1);
- for (int i=0; i<items.count(); i++)
- list.insert(index + i, QPair<QString,QString>(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<QString,QString>(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<QPair<QString,QString> > 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<QQuickItem>(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<QQuickView> 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<ListChange>)
-
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<QQuickItem>(contentItem, "wrapper").count(), 3);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 3);
gridview->setCacheBuffer(120);
- QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 9);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 9);
// ensure items in cache become visible
gridview->setHeight(120);
- QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 15);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 15);
int itemCount = findItems<QQuickItem>(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<QQuickItem>(contentItem, "wrapper").count(), 12);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 12);
- itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
+ itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count();
for (int i = 0; i < model.count() && i < itemCount; ++i) {
QQuickItem *item = findItem<QQuickItem>(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; i<initialItemCount; i++)
model.addItem(QString("value %1").arg(i), "dummy value");
@@ -3499,7 +3359,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), "");
@@ -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<QQuickItem>(contentItem, "wrapper").count();
+ int itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count();
for (int i = 0; i < model.count() && i < itemCount; ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QTRY_COMPARE(item->x(), (i%3)*80.0);
@@ -3991,7 +3825,7 @@ void tst_QQuickGridView::cacheBuffer()
}
int newItemCount = 0;
- newItemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
+ newItemCount = findItems<QQuickItem>(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<typename T>
-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<QQuickItem*>(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<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_QQuickGridView::findItems(QQuickItem *parent, const QString &objectName)
-{
- QList<T*> items;
- const QMetaObject &mo = T::staticMetaObject;
- //qDebug() << parent->childItems().count() << "children";
- for (int i = 0; i < parent->childItems().count(); ++i) {
- QQuickItem *item = qobject_cast<QQuickItem*>(parent->childItems().at(i));
- if (!item)
- continue;
- //qDebug() << "try" << item;
- if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
- items.append(static_cast<T*>(item));
- //qDebug() << " found:" << item;
- }
- items += findItems<T>(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<QQuickItem*>(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 64a1a8f6c9..43e95a2bed 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 69d22c527a..b33caa78c4 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<typename T>
- 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<typename T>
-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<QQuickItem*>(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<T*>(item);
- } else {
- return static_cast<T*>(item);
- }
- }
- item = findItem<T>(item, objectName, index);
- if (item)
- return static_cast<T*>(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 a676dc91d7..f6a7b0c9c3 100644
--- a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp
@@ -47,6 +47,9 @@
#include <QtQuick/private/qquickrectangle_p.h>
#include <private/qquickitem_p.h>
#include "../../shared/util.h"
+#include "../shared/visualtestutil.h"
+
+using namespace QQuickVisualTestUtil;
class tst_QQuickItem : public QDeclarativeDataTest
{
@@ -86,29 +89,6 @@ private:
QDeclarativeEngine engine;
};
-template<typename T>
-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<QQuickItem*>(parent->childItems().at(i));
- if (!item)
- continue;
- //qDebug() << "try" << item;
- if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName))
- return static_cast<T*>(item);
- item = findItem<T>(item, objectName);
- if (item)
- return static_cast<T*>(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 b1f8514c03..6957513fd6 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 3915d13de5..b77a8c0ca3 100644
--- a/tests/auto/qtquick2/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/qtquick2/qquicklistview/tst_qquicklistview.cpp
@@ -51,15 +51,19 @@
#include <QtQuick/private/qquicktext_p.h>
#include <QtQuick/private/qquickvisualitemmodel_p.h>
#include <QtDeclarative/private/qdeclarativelistmodel_p.h>
-#include <QtDeclarative/private/qlistmodelinterface_p.h>
#include <QtQuick/private/qdeclarativechangeset_p.h>
#include "../../shared/util.h"
+#include "../shared/viewtestutil.h"
+#include "../shared/visualtestutil.h"
#include "incrementalmodel.h"
#include <math.h>
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 <class T> void moved(const QUrl &source);
template <class T> void clear(const QUrl &source);
template <class T> 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<typename T>
- T *findItem(QQuickItem *parent, const QString &id, int index=-1);
- template<typename T>
- QList<T*> 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<typename T>
-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 (; i<to-from; ++i,++it)
- replaced.append(*it);
- i=0;
- it=items->begin(); it += from;
- for (; i<n; ++i,++it)
- replaced.append(*it);
- typename T::ConstIterator f=replaced.begin();
- typename T::Iterator t=items->begin(); 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<int> roles() const { return QList<int>() << 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<int, QVariant> data(int index, const QList<int> &roles) const {
- QHash<int,QVariant> 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<QString,QString>(name, number));
- emit itemsInserted(list.count()-1, 1);
- }
-
- void insertItem(int index, const QString &name, const QString &number) {
- list.insert(index, QPair<QString,QString>(name, number));
- emit itemsInserted(index, 1);
- }
-
- void insertItems(int index, const QList<QPair<QString, QString> > &items) {
- for (int i=0; i<items.count(); i++)
- list.insert(index + i, QPair<QString,QString>(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<QString,QString>(name, number);
- emit itemsChanged(index, 1, roles());
- }
-
- void clear() {
- int count = list.count();
- list.clear();
- emit itemsRemoved(0, count);
- }
-
-private:
- QList<QPair<QString,QString> > list;
-};
-
-
-class TestModel2 : public QAbstractListModel
-{
-public:
- enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 };
-
- TestModel2(QObject *parent=0) : QAbstractListModel(parent) {
- QHash<int, QByteArray> 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<QString,QString>(name, number));
- emit endInsertRows();
- }
-
- void addItems(const QList<QPair<QString, QString> > &items) {
- emit beginInsertRows(QModelIndex(), list.count(), list.count()+items.count()-1);
- for (int i=0; i<items.count(); i++)
- list.append(QPair<QString,QString>(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<QString,QString>(name, number));
- emit endInsertRows();
- }
-
- void insertItems(int index, const QList<QPair<QString, QString> > &items) {
- emit beginInsertRows(QModelIndex(), index, index+items.count()-1);
- for (int i=0; i<items.count(); i++)
- list.insert(index + i, QPair<QString,QString>(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<QString,QString>(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<QPair<QString,QString> > 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<ListChange>)
-
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<initialItemCount; i++)
@@ -4079,7 +3828,7 @@ void tst_QQuickListView::onRemove()
QFETCH(int, removeCount);
const int delegateHeight = 10;
- TestModel2 model;
+ QaimModel model;
for (int i=0; i<initialItemCount; i++)
model.addItem(QString("value %1").arg(i), "dummy value");
@@ -4237,7 +3986,7 @@ void tst_QQuickListView::margins()
{
QQuickView *canvas = createView();
- TestModel2 model;
+ QaimModel model;
for (int i = 0; i < 50; i++)
model.addItem("Item" + QString::number(i), "");
@@ -4447,47 +4196,47 @@ void tst_QQuickListView::snapToItem()
void tst_QQuickListView::qListModelInterface_items()
{
- items<TestModel>(testFileUrl("listviewtest.qml"), false);
+ items<QmlListModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_package_items()
{
- items<TestModel>(testFileUrl("listviewtest-package.qml"), true);
+ items<QmlListModel>(testFileUrl("listviewtest-package.qml"), true);
}
void tst_QQuickListView::qAbstractItemModel_items()
{
- items<TestModel2>(testFileUrl("listviewtest.qml"), false);
+ items<QaimModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_changed()
{
- changed<TestModel>(testFileUrl("listviewtest.qml"), false);
+ changed<QmlListModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_package_changed()
{
- changed<TestModel>(testFileUrl("listviewtest-package.qml"), true);
+ changed<QmlListModel>(testFileUrl("listviewtest-package.qml"), true);
}
void tst_QQuickListView::qAbstractItemModel_changed()
{
- changed<TestModel2>(testFileUrl("listviewtest.qml"), false);
+ changed<QaimModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_inserted()
{
- inserted<TestModel>(testFileUrl("listviewtest.qml"));
+ inserted<QmlListModel>(testFileUrl("listviewtest.qml"));
}
void tst_QQuickListView::qListModelInterface_package_inserted()
{
- inserted<TestModel>(testFileUrl("listviewtest-package.qml"));
+ inserted<QmlListModel>(testFileUrl("listviewtest-package.qml"));
}
void tst_QQuickListView::qListModelInterface_inserted_more()
{
- inserted_more<TestModel>();
+ inserted_more<QmlListModel>();
}
void tst_QQuickListView::qListModelInterface_inserted_more_data()
@@ -4497,12 +4246,12 @@ void tst_QQuickListView::qListModelInterface_inserted_more_data()
void tst_QQuickListView::qAbstractItemModel_inserted()
{
- inserted<TestModel2>(testFileUrl("listviewtest.qml"));
+ inserted<QaimModel>(testFileUrl("listviewtest.qml"));
}
void tst_QQuickListView::qAbstractItemModel_inserted_more()
{
- inserted_more<TestModel2>();
+ inserted_more<QaimModel>();
}
void tst_QQuickListView::qAbstractItemModel_inserted_more_data()
@@ -4512,13 +4261,13 @@ void tst_QQuickListView::qAbstractItemModel_inserted_more_data()
void tst_QQuickListView::qListModelInterface_removed()
{
- removed<TestModel>(testFileUrl("listviewtest.qml"), false);
- removed<TestModel>(testFileUrl("listviewtest.qml"), true);
+ removed<QmlListModel>(testFileUrl("listviewtest.qml"), false);
+ removed<QmlListModel>(testFileUrl("listviewtest.qml"), true);
}
void tst_QQuickListView::qListModelInterface_removed_more()
{
- removed_more<TestModel>(testFileUrl("listviewtest.qml"));
+ removed_more<QmlListModel>(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<TestModel>(testFileUrl("listviewtest-package.qml"), false);
- removed<TestModel>(testFileUrl("listviewtest-package.qml"), true);
+ removed<QmlListModel>(testFileUrl("listviewtest-package.qml"), false);
+ removed<QmlListModel>(testFileUrl("listviewtest-package.qml"), true);
}
void tst_QQuickListView::qAbstractItemModel_removed()
{
- removed<TestModel2>(testFileUrl("listviewtest.qml"), false);
- removed<TestModel2>(testFileUrl("listviewtest.qml"), true);
+ removed<QaimModel>(testFileUrl("listviewtest.qml"), false);
+ removed<QaimModel>(testFileUrl("listviewtest.qml"), true);
}
void tst_QQuickListView::qAbstractItemModel_removed_more()
{
- removed_more<TestModel2>(testFileUrl("listviewtest.qml"));
+ removed_more<QaimModel>(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<TestModel>(testFileUrl("listviewtest.qml"));
+ moved<QmlListModel>(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<TestModel>(testFileUrl("listviewtest-package.qml"));
+ moved<QmlListModel>(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<TestModel2>(testFileUrl("listviewtest.qml"));
+ moved<QaimModel>(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<TestModel>(testFileUrl("listviewtest.qml"));
+ clear<QmlListModel>(testFileUrl("listviewtest.qml"));
}
void tst_QQuickListView::qListModelInterface_package_clear()
{
- clear<TestModel>(testFileUrl("listviewtest-package.qml"));
+ clear<QmlListModel>(testFileUrl("listviewtest-package.qml"));
}
void tst_QQuickListView::qAbstractItemModel_clear()
{
- clear<TestModel2>(testFileUrl("listviewtest.qml"));
+ clear<QaimModel>(testFileUrl("listviewtest.qml"));
}
void tst_QQuickListView::qListModelInterface_sections()
{
- sections<TestModel>(testFileUrl("listview-sections.qml"));
+ sections<QmlListModel>(testFileUrl("listview-sections.qml"));
}
void tst_QQuickListView::qListModelInterface_package_sections()
{
- sections<TestModel>(testFileUrl("listview-sections-package.qml"));
+ sections<QmlListModel>(testFileUrl("listview-sections-package.qml"));
}
void tst_QQuickListView::qAbstractItemModel_sections()
{
- sections<TestModel2>(testFileUrl("listview-sections.qml"));
+ sections<QaimModel>(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<QQuickItem*> items = parent->findChildren<QQuickItem*>(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<typename T>
-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<QQuickItem*>(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<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_QQuickListView::findItems(QQuickItem *parent, const QString &objectName, bool visibleOnly)
-{
- QList<T*> items;
- const QMetaObject &mo = T::staticMetaObject;
- //qDebug() << parent->childItems().count() << "children";
- for (int i = 0; i < parent->childItems().count(); ++i) {
- QQuickItem *item = qobject_cast<QQuickItem*>(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<T*>(item));
- items += findItems<T>(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<QQuickItem*>(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 3d2a4ff91c..027abb60e6 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 2a4e1be884..6b36c7e02a 100644
--- a/tests/auto/qtquick2/qquickpathview/tst_qquickpathview.cpp
+++ b/tests/auto/qtquick2/qquickpathview/tst_qquickpathview.cpp
@@ -52,12 +52,17 @@
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtDeclarative/private/qdeclarativelistmodel_p.h>
#include <QtDeclarative/private/qdeclarativevaluetype_p.h>
-#include <QAbstractListModel>
#include <QStringListModel>
#include <QStandardItemModel>
#include <QFile>
#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<typename T>
- T *findItem(QQuickItem *parent, const QString &objectName, int index=-1);
- template<typename T>
- QList<T*> 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<int, QByteArray> 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<QString,QString>(name, number));
- endInsertRows();
- }
-
- void insertItem(int index, const QString &name, const QString &number) {
- beginInsertRows(QModelIndex(), index, index);
- list.insert(index, QPair<QString,QString>(name, number));
- endInsertRows();
- }
-
- void insertItems(int index, const QList<QPair<QString, QString> > &items) {
- beginInsertRows(QModelIndex(), index, index+items.count()-1);
- for (int i=0; i<items.count(); i++)
- list.insert(index + i, QPair<QString,QString>(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<QString,QString>(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<QPair<QString,QString> > replaced;
- int i=0;
- QList<QPair<QString,QString> >::ConstIterator it=list.begin(); it += from+n;
- for (; i<to-from; ++i,++it)
- replaced.append(*it);
- i=0;
- it=list.begin(); it += from;
- for (; i<n; ++i,++it)
- replaced.append(*it);
- QList<QPair<QString,QString> >::ConstIterator f=replaced.begin();
- QList<QPair<QString,QString> >::Iterator t=list.begin(); t += from;
- for (; f != replaced.end(); ++f, ++t)
- *t = *f;
- }
- }
-
-private:
- QList<QPair<QString,QString> > 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<typename T>
-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<QQuickItem*>(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<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_QQuickPathView::findItems(QQuickItem *parent, const QString &objectName)
-{
- QList<T*> 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<QQuickItem*>(parent->childItems().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;
-}
-
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 596dc9131e..3e6f4071ff 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 fa1781fc44..b791faf78a 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 518ea1843b..59322704f5 100644
--- a/tests/auto/qtquick2/qquickrepeater/tst_qquickrepeater.cpp
+++ b/tests/auto/qtquick2/qquickrepeater/tst_qquickrepeater.cpp
@@ -51,6 +51,12 @@
#include <QtQuick/private/qquicktext_p.h>
#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<typename T>
- T *findItem(QObject *parent, const QString &objectName, int index);
- template<typename T>
- 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<int, QByteArray> 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<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;
-};
-
-
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<QQuickItem*>(rootObject->property("parentItem")), rootObject);
}
-QQuickView *tst_QQuickRepeater::createView()
-{
- QQuickView *canvas = new QQuickView(0);
- canvas->setGeometry(0,0,240,320);
-
- return canvas;
-}
-
-template<typename T>
-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<QQuickItem*>(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<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>
-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<T*>(parent);
- for (int i = 0; i < parent->children().count(); ++i) {
- QQuickItem *child = qobject_cast<QQuickItem*>(parent->children().at(i));
- if (!child)
- continue;
- QQuickItem *item = findItem<T>(child, objectName);
- if (item)
- return static_cast<T*>(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 26112cf659..6db887d747 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 114123f8e0..1b6a7629d9 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 <qtest.h>
#include <QtTest/QSignalSpy>
#include <QStandardItemModel>
@@ -55,6 +57,8 @@
#include <private/qdeclarativeengine_p.h>
#include <math.h>
+using namespace QQuickVisualTestUtil;
+
template <typename T, int N> int lengthOf(const T (&)[N]) { return N; }
static void initStandardTreeModel(QStandardItemModel *model)
@@ -249,8 +253,6 @@ private:
bool failed;
QDeclarativeEngine engine;
- template<typename T>
- T *findItem(QQuickItem *parent, const QString &objectName, int index = -1);
};
Q_DECLARE_METATYPE(QDeclarativeChangeSet)
@@ -3438,32 +3440,6 @@ void tst_qquickvisualdatamodel::warnings()
QCOMPARE(evaluate<int>(listView, "count"), count);
}
-template<typename T>
-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<QQuickItem*>(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<T*>(item);
- } else {
- return static_cast<T*>(item);
- }
- }
- item = findItem<T>(item, objectName, index);
- if (item)
- return static_cast<T*>(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 0000000000..eddbe4b6aa
--- /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 0000000000..ed2066d6aa
--- /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 <QtQuick/QQuickView>
+
+#include <QtTest/QTest>
+
+template<typename T>
+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 (; i<to-from; ++i,++it)
+ replaced.append(*it);
+ i=0;
+ it=items->begin(); it += from;
+ for (; i<n; ++i,++it)
+ replaced.append(*it);
+ typename T::ConstIterator f=replaced.begin();
+ typename T::Iterator t=items->begin(); 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<int> QQuickViewTestUtil::QmlListModel::roles() const
+{
+ return QList<int>() << 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<int, QVariant> QQuickViewTestUtil::QmlListModel::data(int index, const QList<int> &roles) const
+{
+ QHash<int,QVariant> 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<QString,QString>(name, number));
+ emit itemsInserted(list.count()-1, 1);
+}
+
+void QQuickViewTestUtil::QmlListModel::insertItem(int index, const QString &name, const QString &number)
+{
+ list.insert(index, QPair<QString,QString>(name, number));
+ emit itemsInserted(index, 1);
+}
+
+void QQuickViewTestUtil::QmlListModel::insertItems(int index, const QList<QPair<QString, QString> > &items)
+{
+ for (int i=0; i<items.count(); i++)
+ list.insert(index + i, QPair<QString,QString>(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<QString,QString>(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<int, QByteArray> 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<QString,QString>(name, number));
+ emit endInsertRows();
+}
+
+void QQuickViewTestUtil::QaimModel::addItems(const QList<QPair<QString, QString> > &items)
+{
+ emit beginInsertRows(QModelIndex(), list.count(), list.count()+items.count()-1);
+ for (int i=0; i<items.count(); i++)
+ list.append(QPair<QString,QString>(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<QString,QString>(name, number));
+ emit endInsertRows();
+}
+
+void QQuickViewTestUtil::QaimModel::insertItems(int index, const QList<QPair<QString, QString> > &items)
+{
+ emit beginInsertRows(QModelIndex(), index, index+items.count()-1);
+ for (int i=0; i<items.count(); i++)
+ list.insert(index + i, QPair<QString,QString>(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<QString,QString>(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 0000000000..98b0dbbf92
--- /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 <QtQuick/QQuickItem>
+#include <QtDeclarative/QDeclarativeExpression>
+#include <QtDeclarative/private/qlistmodelinterface_p.h>
+#include <QtCore/QAbstractListModel>
+
+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<int> roles() const;
+ QString toString(int role) const;
+
+ QVariant data(int index, int role) const;
+ QHash<int, QVariant> data(int index, const QList<int> &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<QPair<QString, QString> > &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<QPair<QString,QString> > 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<QPair<QString, QString> > &items);
+ void insertItem(int index, const QString &name, const QString &number);
+ void insertItems(int index, const QList<QPair<QString, QString> > &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<QPair<QString,QString> > list;
+ };
+
+}
+
+Q_DECLARE_METATYPE(QList<QQuickViewTestUtil::ListChange>)
+
+#endif // QQUICKVIEWTESTUTIL_H
diff --git a/tests/auto/qtquick2/shared/visualtestutil.cpp b/tests/auto/qtquick2/shared/visualtestutil.cpp
new file mode 100644
index 0000000000..8680df10e9
--- /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 <QtQuick/QQuickItem>
+#include <QtCore/QDebug>
+
+QQuickItem *QQuickVisualTestUtil::findVisibleChild(QQuickItem *parent, const QString &objectName)
+{
+ QQuickItem *item = 0;
+ QList<QQuickItem*> items = parent->findChildren<QQuickItem*>(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<QQuickItem*>(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 0000000000..ceed4b04a7
--- /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 <QtQuick/QQuickItem>
+#include <QtDeclarative/QDeclarativeExpression>
+
+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<typename T>
+ 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<QQuickItem*>(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<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*> findItems(QQuickItem *parent, const QString &objectName, bool visibleOnly = true)
+ {
+ QList<T*> items;
+ const QMetaObject &mo = T::staticMetaObject;
+ for (int i = 0; i < parent->childItems().count(); ++i) {
+ QQuickItem *item = qobject_cast<QQuickItem*>(parent->childItems().at(i));
+ if (!item || (visibleOnly && !item->isVisible()))
+ continue;
+ if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName))
+ items.append(static_cast<T*>(item));
+ items += findItems<T>(item, objectName);
+ }
+
+ return items;
+ }
+}
+
+#endif // QQUICKVISUALTESTUTIL_H