SOURCES += tst_qquickanchors.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
macx:CONFIG -= app_bundle
#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
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;
SOURCES += tst_qquickflickable.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
testDataFiles.files = data
testDataFiles.path = .
#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
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()
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"
SOURCES += tst_qquickfocusscope.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
macx:CONFIG -= app_bundle
#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
{
public:
tst_qquickfocusscope() {}
- template<typename T>
- T *findItem(QQuickItem *parent, const QString &id);
-
private slots:
void basic();
void nested();
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;
SOURCES += tst_qquickgridview.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
testDataFiles.files = data
testDataFiles.path = .
#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
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()
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
model.addItem("Fred", "12345");
model.addItem("John", "2345");
model.addItem("Bob", "54321");
}
// 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();
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
model.addItem("Fred", "12345");
model.addItem("John", "2345");
model.addItem("Bob", "54321");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
model.addItem("Fred", "12345");
model.addItem("John", "2345");
model.addItem("Bob", "54321");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
QScopedPointer<QQuickView> canvas(createView());
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
<< -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);
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < startCount; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
void tst_QQuickGridView::currentIndex()
{
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 60; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
void tst_QQuickGridView::noCurrentIndex()
{
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 60; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
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), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
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), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 7; i++)
model.addItem("Item" + QString::number(i), "");
QFETCH(QPointF, firstDelegatePos);
QFETCH(QPointF, resizeContentPos);
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
// 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) {
// 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";
void tst_QQuickGridView::changeColumnCount()
{
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
model.addItem("Fred", "12345");
model.addItem("John", "2345");
model.addItem("Bob", "54321");
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
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");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 10; i++)
model.addItem("Item" + QString::number(i), "");
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), "");
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);
}
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) {
void tst_QQuickGridView::unrequestedVisibility()
{
- TestModel model;
+ QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
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"
../../shared/testhttpserver.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
testDataFiles.files = data
testDataFiles.path = .
#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
void imageCrash_QTBUG_22125();
private:
- template<typename T>
- T *findItem(QQuickItem *parent, const QString &id, int index=-1);
-
QDeclarativeEngine engine;
};
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"
#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
{
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
incrementalmodel.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
testDataFiles.files = data
testDataFiles.path = .
#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
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();
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()
{
}
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
<< -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);
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < startCount; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
QTRY_COMPARE(listview->currentIndex(), 6);
// change model
- TestModel model2;
+ QmlListModel model2;
for (int i = 0; i < 5; i++)
model2.addItem("Item" + QString::number(i), "");
canvas->show();
QTest::qWait(200);
- TestModel model;
+ QmlListModel model;
model.addItem("Item 0", "a");
model.addItem("Item 1", "b");
model.addItem("Item 2", "b");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
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));
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));
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)
void tst_QQuickListView::currentIndex()
{
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
void tst_QQuickListView::noCurrentIndex()
{
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
{
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 90; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
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), "");
QFETCH(QPointF, changedContentPos);
QFETCH(QPointF, resizeContentPos);
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
canvas->rootContext()->setContextProperty("setCurrentToZero", QVariant(false));
canvas->setSource(testFileUrl("fillModelOnComponentCompleted.qml"));
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 3; i++)
model.addItem("Item" + QString::number(i), "");
// Vertical
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
// Horizontal
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
// Horizontal RTL
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
{
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
{
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
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), "");
QQuickView *canvas = createView();
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
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++)
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");
{
QQuickView *canvas = createView();
- TestModel2 model;
+ QaimModel model;
for (int i = 0; i < 50; i++)
model.addItem("Item" + QString::number(i), "");
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()
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()
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()
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()
void tst_QQuickListView::qListModelInterface_moved()
{
- moved<TestModel>(testFileUrl("listviewtest.qml"));
+ moved<QmlListModel>(testFileUrl("listviewtest.qml"));
}
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()
void tst_QQuickListView::qAbstractItemModel_moved()
{
- moved<TestModel2>(testFileUrl("listviewtest.qml"));
+ moved<QaimModel>(testFileUrl("listviewtest.qml"));
}
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()
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();
void tst_QQuickListView::unrequestedVisibility()
{
- TestModel model;
+ QmlListModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
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)
SOURCES += tst_qquickpathview.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
testDataFiles.files = data
testDataFiles.path = .
#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)
{
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
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()
{
}
{
QQuickView *canvas = createView();
- TestModel model;
+ QaimModel model;
model.addItem("Fred", "12345");
model.addItem("John", "2345");
model.addItem("Bob", "54321");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
model.addItem("Ben", "12345");
model.addItem("Bohn", "2345");
model.addItem("Bob", "54321");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
model.addItem("Ben", "12345");
model.addItem("Bohn", "2345");
model.addItem("Bob", "54321");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
model.addItem("Ben", "12345");
model.addItem("Bohn", "2345");
model.addItem("Bob", "54321");
TestObject *testObject = new TestObject;
ctxt->setContextProperty("testObject", testObject);
- TestModel model;
+ QaimModel model;
model.addItem("red", "1");
model.addItem("green", "2");
model.addItem("blue", "3");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
model.addItem("Ben", "12345");
model.addItem("Bohn", "2345");
model.addItem("Bob", "54321");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
model.addItem("Ben", "12345");
model.addItem("Bohn", "2345");
model.addItem("Bob", "54321");
QQuickView *canvas = createView();
canvas->show();
- TestModel model;
+ QaimModel model;
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
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;
delete obj;
}
-
QTEST_MAIN(tst_QQuickPathView)
#include "tst_qquickpathview.moc"
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"
+ }
}
}
SOURCES += tst_qquickrepeater.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
testFiles.files = data
testFiles.path = .
#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
{
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
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()
{
}
TestObject *testObject = new TestObject;
ctxt->setContextProperty("testObject", testObject);
- TestModel testModel;
+ QaimModel testModel;
ctxt->setContextProperty("testData", &testModel);
canvas->setSource(testFileUrl("repeater2.qml"));
qApp->processEvents();
TestObject *testObject = new TestObject;
ctxt->setContextProperty("testObject", testObject);
- TestModel testModel;
+ QaimModel testModel;
testModel.addItem("one", "1");
testModel.addItem("two", "2");
testModel.addItem("three", "3");
TestObject *testObject = new TestObject;
ctxt->setContextProperty("testObject", testObject);
- TestModel testModel;
+ QaimModel testModel;
testModel.addItem("one", "1");
testModel.addItem("two", "2");
testModel.addItem("three", "3");
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"
SOURCES += tst_qquickvisualdatamodel.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
testDataFiles.files = data
testDataFiles.path = .
**
****************************************************************************/
#include "../../shared/util.h"
+#include "../shared/visualtestutil.h"
+
#include <qtest.h>
#include <QtTest/QSignalSpy>
#include <QStandardItemModel>
#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)
bool failed;
QDeclarativeEngine engine;
- template<typename T>
- T *findItem(QQuickItem *parent, const QString &objectName, int index = -1);
};
Q_DECLARE_METATYPE(QDeclarativeChangeSet)
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)
--- /dev/null
+
+HEADERS += $$PWD/visualtestutil.h \
+ $$PWD/viewtestutil.h
+SOURCES += $$PWD/visualtestutil.cpp \
+ $$PWD/viewtestutil.cpp
+
+DEFINES += QT_DECLARATIVETEST_DATADIR=\\\"$${_PRO_FILE_PWD_}/data\\\"
--- /dev/null
+/****************************************************************************
+**
+** 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();
+}
+
--- /dev/null
+/****************************************************************************
+**
+** 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
--- /dev/null
+/****************************************************************************
+**
+** 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);
+ }
+}
+
--- /dev/null
+/****************************************************************************
+**
+** 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