/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** 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_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
-#include <QtWidgets/qstringlistmodel.h>
+#include <QtCore/qstringlistmodel.h>
#include <QtQuick/qquickview.h>
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
Q_DECLARE_METATYPE(Qt::LayoutDirection)
Q_DECLARE_METATYPE(QQuickGridView::Flow)
-class tst_QQuickGridView : public QObject
+class tst_QQuickGridView : public QDeclarativeDataTest
{
Q_OBJECT
public:
tst_QQuickGridView();
private slots:
- void initTestCase();
- void cleanupTestCase();
void items();
void changed();
void inserted();
void insertBeforeVisible();
void insertBeforeVisible_data();
void removed();
+ void removed_more();
+ void removed_more_data();
void addOrRemoveBeforeVisible();
void addOrRemoveBeforeVisible_data();
void clear();
void header();
void header_data();
void resizeViewAndRepaint();
- void indexAt();
+ void indexAt_itemAt_data();
+ void indexAt_itemAt();
void onAdd();
void onAdd_data();
void onRemove();
void unaligned();
void cacheBuffer();
void asynchronous();
+ void unrequestedVisibility();
private:
QQuickView *createView();
*t = *f;
}
-void tst_QQuickGridView::initTestCase()
-{
-}
-
-void tst_QQuickGridView::cleanupTestCase()
-{
-
-}
-
-
class TestModel : public QAbstractListModel
{
public:
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickFlickable *gridview = findItem<QQuickFlickable>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
// check visibleItems.first() is in correct position
QQuickItem *item0 = findItem<QQuickItem>(contentItem, "wrapper", 0);
QVERIFY(item0);
- QCOMPARE(item0->y(), itemsOffsetAfterMove);
+ QCOMPARE(item0->y(), 0.0);
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
int firstVisibleIndex = -1;
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
int firstVisibleIndex = 20; // move to an index where the top item is not visible
gridview->setContentY(firstVisibleIndex * 20.0);
gridview->setCurrentIndex(firstVisibleIndex);
+
qApp->processEvents();
QTRY_COMPARE(gridview->currentIndex(), firstVisibleIndex);
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", firstVisibleIndex);
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
delete canvas;
}
+void tst_QQuickGridView::removed_more()
+{
+ QFETCH(qreal, contentY);
+ QFETCH(int, removeIndex);
+ QFETCH(int, removeCount);
+ QFETCH(qreal, itemsOffsetAfterMove);
+ QFETCH(QString, firstVisible);
+
+ QQuickText *name;
+ QQuickText *number;
+ QQuickView *canvas = createView();
+ canvas->show();
+
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testRightToLeft", QVariant(false));
+ ctxt->setContextProperty("testTopToBottom", QVariant(false));
+ canvas->setSource(testFileUrl("gridview1.qml"));
+ qApp->processEvents();
+
+ QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+ QTRY_VERIFY(gridview != 0);
+ QQuickItem *contentItem = gridview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
+
+ gridview->setContentY(contentY);
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+ model.removeItems(removeIndex, removeCount);
+ QTRY_COMPARE(gridview->property("count").toInt(), model.count());
+
+ QString firstName;
+ int firstVisibleIndex = -1;
+ QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+ for (int i=0; i<items.count(); i++) {
+ if (items[i]->y() >= contentY) {
+ QDeclarativeExpression e(qmlContext(items[i]), items[i], "index");
+ firstVisibleIndex = e.evaluate().toInt();
+ QDeclarativeExpression en(qmlContext(items[i]), items[i], "name");
+ firstName = en.evaluate().toString();
+ break;
+ }
+ }
+ QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
+ QCOMPARE(firstName, firstVisible);
+
+ // Confirm items positioned correctly and indexes correct
+ int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
+ for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
+
+ QTRY_COMPARE(item->x(), (i%3)*80.0);
+ QTRY_COMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
+
+ name = findItem<QQuickText>(contentItem, "textName", i);
+ QVERIFY(name != 0);
+ QTRY_COMPARE(name->text(), model.name(i));
+ number = findItem<QQuickText>(contentItem, "textNumber", i);
+ QVERIFY(number != 0);
+ QTRY_COMPARE(number->text(), model.number(i));
+ }
+
+ delete canvas;
+}
+
+void tst_QQuickGridView::removed_more_data()
+{
+ QTest::addColumn<qreal>("contentY");
+ QTest::addColumn<int>("removeIndex");
+ QTest::addColumn<int>("removeCount");
+ QTest::addColumn<qreal>("itemsOffsetAfterMove");
+ QTest::addColumn<QString>("firstVisible");
+
+ QTest::newRow("remove 1, before visible items")
+ << 120.0 // show 6-23
+ << 3 << 1
+ << 0.0 << "Item7";
+
+ QTest::newRow("remove multiple, all before visible items")
+ << 120.0
+ << 1 << 3
+ << 60.0 << "Item6"; // removed top row, slide down by 1 row
+
+ QTest::newRow("remove multiple, all before visible items, remove item 0")
+ << 120.0
+ << 0 << 4
+ << 60.0 << "Item7"; // removed top row, slide down by 1 row
+
+ QTest::newRow("remove multiple rows, all before visible items")
+ << 240.0 // show 12-29
+ << 1 << 7
+ << 120.0 << "Item13";
+
+
+ // remove 3,4,5 before the visible pos, first row moves down to just before the visible pos,
+ // items 6,7 are removed from view, item 8 slides up to original pos of item 6 (120px)
+ QTest::newRow("remove multiple, mix of items from before and within visible items")
+ << 120.0
+ << 3 << 5
+ << 60.0 << "Item8"; // adjust for the 1 row removed before the visible
+
+ QTest::newRow("remove multiple, mix of items from before and within visible items, remove item 0")
+ << 120.0
+ << 0 << 8
+ << 60.0 * 2 << "Item8"; // adjust for the 2 rows removed before the visible
+
+
+ QTest::newRow("remove 1, from start of visible, content at start")
+ << 0.0
+ << 0 << 1
+ << 0.0 << "Item1";
+
+ QTest::newRow("remove multiple, from start of visible, content at start")
+ << 0.0
+ << 0 << 3
+ << 0.0 << "Item3";
+
+ QTest::newRow("remove 1, from start of visible, content not at start")
+ << 120.0 // show 6-23
+ << 4 << 1
+ << 0.0 << "Item7";
+
+ QTest::newRow("remove multiple, from start of visible, content not at start")
+ << 120.0 // show 6-23
+ << 4 << 3
+ << 0.0 << "Item9";
+
+
+ QTest::newRow("remove 1, from middle of visible, content at start")
+ << 0.0
+ << 10 << 1
+ << 0.0 << "Item0";
+
+ QTest::newRow("remove multiple, from middle of visible, content at start")
+ << 0.0
+ << 10 << 5
+ << 0.0 << "Item0";
+
+ QTest::newRow("remove 1, from middle of visible, content not at start")
+ << 120.0 // show 6-23
+ << 10 << 1
+ << 0.0 << "Item6";
+
+ QTest::newRow("remove multiple, from middle of visible, content not at start")
+ << 120.0 // show 6-23
+ << 10 << 5
+ << 0.0 << "Item6";
+
+
+ QTest::newRow("remove 1, after visible, content at start")
+ << 0.0
+ << 16 << 1
+ << 0.0 << "Item0";
+
+ QTest::newRow("remove multiple, after visible, content at start")
+ << 0.0
+ << 16 << 5
+ << 0.0 << "Item0";
+
+ QTest::newRow("remove 1, after visible, content not at start")
+ << 120.0 // show 6-23
+ << 16+4 << 1
+ << 0.0 << "Item6";
+
+ QTest::newRow("remove multiple, after visible, content not at start")
+ << 120.0 // show 6-23
+ << 16+4 << 5
+ << 0.0 << "Item6";
+
+ QTest::newRow("remove multiple, mix of items from within and after visible items")
+ << 120.0 // show 6-23
+ << 20 << 5
+ << 0.0 << "Item6";
+}
+
void tst_QQuickGridView::addOrRemoveBeforeVisible()
{
// QTBUG-21588: ensure re-layout is done on grid after adding or removing
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QTRY_VERIFY(gridview != 0);
gridview->setCurrentIndex(0);
qApp->processEvents();
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
// scroll down until item 0 is no longer drawn
// (bug not triggered if we just move using content y, since that doesn't
QTest::addColumn<qreal>("newTopContentY");
QTest::newRow("add") << true << -60.0;
- QTest::newRow("remove") << false << 0.0;
+ QTest::newRow("remove") << false << -60.0;
}
void tst_QQuickGridView::clear()
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QTRY_VERIFY(currentItem != 0);
gridview->setContentY(contentY);
- model.moveItems(from, to, count);
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
- // wait for items to move
+ model.moveItems(from, to, count);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
// Confirm items positioned correctly and indexes correct
// model starts with 30 items, each 80x60, in area 240x320
// 18 items should be visible at a time
+ // The first visible item should not move upwards and out of the view
+ // if items are moved/removed before it.
+
+
QTest::newRow("move 1 forwards, within visible items")
<< 0.0
<< 1 << 8 << 1
QTest::newRow("move 1 forwards, from non-visible -> visible")
<< 120.0 // show 6-23
<< 1 << 23 << 1
- << 0.0; // only 1 item was removed from the 1st row, so it doesn't move down
+ << 0.0;
QTest::newRow("move 1 forwards, from non-visible -> visible (move first item)")
<< 120.0 // // show 6-23
<< 0 << 6 << 1
- << 0.0; // only 1 item was removed from the 1st row, so it doesn't move down
+ << 0.0;
QTest::newRow("move 1 forwards, from visible -> non-visible")
<< 0.0
<< 0 << 6 << 3
<< 60.0; // top row moved and shifted to below 3rd row, all items should shift down by 1 row
+ QTest::newRow("move multiple forwards, mix of non-visible/visible")
+ << 120.0
+ << 3 << 16 << 6
+ << 60.0; // top two rows removed, third row is now the first visible
+
+ QTest::newRow("move multiple forwards, to bottom of view")
+ << 0.0
+ << 5 << 13 << 5
+ << 0.0;
+
+ QTest::newRow("move multiple forwards, to bottom of view, first row -> last")
+ << 0.0
+ << 0 << 15 << 3
+ << 0.0;
+
+ QTest::newRow("move multiple forwards, to bottom of view, content y not 0")
+ << 120.0
+ << 5+4 << 13+4 << 5
+ << 0.0;
+
QTest::newRow("move multiple forwards, from visible -> non-visible")
<< 0.0
<< 1 << 16 << 3
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- QString filename(TESTDATA("gridview-initCurrent.qml"));
+ QString filename(testFile("gridview-initCurrent.qml"));
canvas->setSource(QUrl::fromLocalFile(filename));
qApp->processEvents();
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- QString filename(TESTDATA("gridview-noCurrent.qml"));
+ QString filename(testFile("gridview-noCurrent.qml"));
canvas->setSource(QUrl::fromLocalFile(filename));
qApp->processEvents();
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
void tst_QQuickGridView::defaultValues()
{
QDeclarativeEngine engine;
- QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("gridview3.qml")));
+ QDeclarativeComponent c(&engine, testFileUrl("gridview3.qml"));
QQuickGridView *obj = qobject_cast<QQuickGridView*>(c.create());
QTRY_VERIFY(obj != 0);
void tst_QQuickGridView::properties()
{
QDeclarativeEngine engine;
- QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("gridview2.qml")));
+ QDeclarativeComponent c(&engine, testFileUrl("gridview2.qml"));
QQuickGridView *obj = qobject_cast<QQuickGridView*>(c.create());
QTRY_VERIFY(obj != 0);
{
QQuickView *canvas = createView();
QTRY_VERIFY(canvas);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("propertychangestest.qml")));
+ canvas->setSource(testFileUrl("propertychangestest.qml"));
QQuickGridView *gridView = canvas->rootObject()->findChild<QQuickGridView*>("gridView");
QTRY_VERIFY(gridView);
{
QQuickView *canvas = createView();
QTRY_VERIFY(canvas);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("propertychangestest.qml")));
+ canvas->setSource(testFileUrl("propertychangestest.qml"));
QQuickGridView *gridView = canvas->rootObject()->findChild<QQuickGridView*>("gridView");
QTRY_VERIFY(gridView);
{
QQuickView *canvas = createView();
QTRY_VERIFY(canvas);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("propertychangestest.qml")));
+ canvas->setSource(testFileUrl("propertychangestest.qml"));
QQuickGridView *gridView = canvas->rootObject()->findChild<QQuickGridView*>("gridView");
QTRY_VERIFY(gridView);
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testTopToBottom", QVariant(false));
ctxt->setContextProperty("testRightToLeft", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
void tst_QQuickGridView::mirroring()
{
QQuickView *canvasA = createView();
- canvasA->setSource(QUrl::fromLocalFile(TESTDATA("mirroring.qml")));
+ canvasA->setSource(testFileUrl("mirroring.qml"));
QQuickGridView *gridviewA = findItem<QQuickGridView>(canvasA->rootObject(), "view");
QTRY_VERIFY(gridviewA != 0);
QQuickView *canvasB = createView();
- canvasB->setSource(QUrl::fromLocalFile(TESTDATA("mirroring.qml")));
+ canvasB->setSource(testFileUrl("mirroring.qml"));
QQuickGridView *gridviewB = findItem<QQuickGridView>(canvasB->rootObject(), "view");
QTRY_VERIFY(gridviewA != 0);
qApp->processEvents();
ctxt->setContextProperty("testTopToBottom", QVariant(true));
ctxt->setContextProperty("testRightToLeft", QVariant(true));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("displaygrid.qml")));
+ canvas->setSource(testFileUrl("displaygrid.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview-enforcerange.qml")));
+ canvas->setSource(testFileUrl("gridview-enforcerange.qml"));
qApp->processEvents();
QVERIFY(canvas->rootObject() != 0);
ctxt->setContextProperty("testRightToLeft", QVariant(true));
ctxt->setContextProperty("testTopToBottom", QVariant(true));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview-enforcerange.qml")));
+ canvas->setSource(testFileUrl("gridview-enforcerange.qml"));
qApp->processEvents();
QVERIFY(canvas->rootObject() != 0);
{
QQuickView *canvas = createView();
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("setindex.qml")));
+ canvas->setSource(testFileUrl("setindex.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
{
QQuickView *canvas = createView();
- QString filename(TESTDATA("manual-highlight.qml"));
+ QString filename(testFile("manual-highlight.qml"));
canvas->setSource(QUrl::fromLocalFile(filename));
qApp->processEvents();
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("footer.qml")));
+ canvas->setSource(testFileUrl("footer.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
canvas->rootContext()->setContextProperty("testModel", &model);
canvas->rootContext()->setContextProperty("initialViewWidth", 240);
canvas->rootContext()->setContextProperty("initialViewHeight", 320);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("header.qml")));
+ canvas->setSource(testFileUrl("header.qml"));
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QTRY_VERIFY(gridview != 0);
canvas->rootContext()->setContextProperty("testModel", &model);
canvas->rootContext()->setContextProperty("initialViewWidth", 240);
canvas->rootContext()->setContextProperty("initialViewHeight", 320);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("header.qml")));
+ canvas->setSource(testFileUrl("header.qml"));
gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QTRY_VERIFY(gridview != 0);
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("initialHeight", 100);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("resizeview.qml")));
+ canvas->setSource(testFileUrl("resizeview.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QVERIFY(!findItem<QQuickItem>(contentItem, "wrapper", 10));
gridview->setHeight(320);
+
+#ifdef Q_OS_MAC
+ QSKIP("QTBUG-21590 view does not reliably receive polish without a running animation");
+#endif
+
QTRY_VERIFY(findItem<QQuickItem>(contentItem, "wrapper", 10));
gridview->setHeight(100);
QTRY_VERIFY(!findItem<QQuickItem>(contentItem, "wrapper", 10));
+ // Ensure we handle -ve sizes
+ gridview->setHeight(-100);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 3);
+
+ gridview->setCacheBuffer(120);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 9);
+
+ // ensure items in cache become visible
+ gridview->setHeight(120);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 15);
+
+ int itemCount = findItems<QQuickItem>(contentItem, "wrapper").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";
+ QTRY_VERIFY(item);
+ QTRY_COMPARE(item->x(), qreal((i%3)*80));
+ QTRY_COMPARE(item->y(), qreal((i/3)*60));
+ QCOMPARE(item->isVisible(), i < 9); // inside view visible, outside not visible
+ }
+
+ // ensure items outside view become invisible
+ gridview->setHeight(60);
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 12);
+
+ itemCount = findItems<QQuickItem>(contentItem, "wrapper").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";
+ QTRY_VERIFY(item);
+ QTRY_COMPARE(item->x(), qreal((i%3)*80));
+ QTRY_COMPARE(item->y(), qreal((i/3)*60));
+ QCOMPARE(item->isVisible(), i < 6); // inside view visible, outside not visible
+ }
+
delete canvas;
}
-void tst_QQuickGridView::indexAt()
+void tst_QQuickGridView::indexAt_itemAt_data()
+{
+ QTest::addColumn<qreal>("x");
+ QTest::addColumn<qreal>("y");
+ QTest::addColumn<int>("index");
+
+ QTest::newRow("Item 0 - 0, 0") << 0. << 0. << 0;
+ QTest::newRow("Item 0 - 79, 59") << 79. << 59. << 0;
+ QTest::newRow("Item 1 - 80, 0") << 80. << 0. << 1;
+ QTest::newRow("Item 3 - 0, 60") << 0. << 60. << 3;
+ QTest::newRow("No Item - 240, 0") << 240. << 0. << -1;
+}
+
+void tst_QQuickGridView::indexAt_itemAt()
{
+ QFETCH(qreal, x);
+ QFETCH(qreal, y);
+ QFETCH(int, index);
+
QQuickView *canvas = createView();
TestModel model;
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
QTRY_COMPARE(gridview->count(), model.count());
- QCOMPARE(gridview->indexAt(0, 0), 0);
- QCOMPARE(gridview->indexAt(79, 59), 0);
- QCOMPARE(gridview->indexAt(80, 0), 1);
- QCOMPARE(gridview->indexAt(0, 60), 3);
- QCOMPARE(gridview->indexAt(240, 0), -1);
+ QQuickItem *item = 0;
+ if (index >= 0) {
+ item = findItem<QQuickItem>(contentItem, "wrapper", index);
+ QVERIFY(item);
+ }
+ QCOMPARE(gridview->indexAt(x, y), index);
+ QVERIFY(gridview->itemAt(x, y) == item);
delete canvas;
}
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("delegateWidth", delegateWidth);
ctxt->setContextProperty("delegateHeight", delegateHeight);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("attachedSignals.qml")));
+ canvas->setSource(testFileUrl("attachedSignals.qml"));
QObject *object = canvas->rootObject();
object->setProperty("width", canvas->width());
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("delegateWidth", delegateWidth);
ctxt->setContextProperty("delegateHeight", delegateHeight);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("attachedSignals.qml")));
+ canvas->setSource(testFileUrl("attachedSignals.qml"));
QObject *object = canvas->rootObject();
model.removeItems(indexToRemove, removeCount);
void tst_QQuickGridView::columnCount()
{
QQuickView canvas;
- canvas.setSource(QUrl::fromLocalFile(TESTDATA("gridview4.qml")));
+ canvas.setSource(testFileUrl("gridview4.qml"));
canvas.show();
canvas.requestActivateWindow();
QTest::qWaitForWindowShown(&canvas);
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("testRightToLeft", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("margins.qml")));
+ canvas->setSource(testFileUrl("margins.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("testRightToLeft", QVariant(true));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("margins.qml")));
+ canvas->setSource(testFileUrl("margins.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
{
QQuickView canvas;
canvas.setGeometry(0,0,240,320);
- canvas.setSource(QUrl::fromLocalFile(TESTDATA("creationContext.qml")));
+ canvas.setSource(testFileUrl("creationContext.qml"));
qApp->processEvents();
QQuickItem *rootItem = qobject_cast<QQuickItem *>(canvas.rootObject());
QQuickView *canvas = createView();
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("snapToRow.qml")));
+ canvas->setSource(testFileUrl("snapToRow.qml"));
canvas->show();
qApp->processEvents();
QQuickView *canvas = createView();
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("snapOneRow.qml")));
+ canvas->setSource(testFileUrl("snapOneRow.qml"));
canvas->show();
qApp->processEvents();
QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("unaligned.qml")));
+ canvas->setSource(testFileUrl("unaligned.qml"));
qApp->processEvents();
QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
for (int i = 0; i < pointCount; ++i) {
QMouseEvent mv(QEvent::MouseMove, from + (i+1)*diff/pointCount, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
- QApplication::sendEvent(canvas, &mv);
+ QGuiApplication::sendEvent(canvas, &mv);
QTest::qWait(duration/pointCount);
QCoreApplication::processEvents();
}
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->setSource(testFileUrl("gridview1.qml"));
canvas->show();
qApp->processEvents();
QDeclarativeIncubationController controller;
canvas->engine()->setIncubationController(&controller);
- canvas->setSource(TESTDATA("asyncloader.qml"));
+ canvas->setSource(testFile("asyncloader.qml"));
QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject());
QVERIFY(rootObject);
delete canvas;
}
+void tst_QQuickGridView::unrequestedVisibility()
+{
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i));
+
+ QQuickView *canvas = new QQuickView(0);
+ canvas->setGeometry(0,0,240,320);
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testWrap", QVariant(false));
+
+ canvas->setSource(testFileUrl("unrequestedItems.qml"));
+
+ canvas->show();
+
+ qApp->processEvents();
+
+ QQuickGridView *leftview = findItem<QQuickGridView>(canvas->rootObject(), "leftGrid");
+ QTRY_VERIFY(leftview != 0);
+
+ QQuickGridView *rightview = findItem<QQuickGridView>(canvas->rootObject(), "rightGrid");
+ QTRY_VERIFY(rightview != 0);
+
+ QQuickItem *leftContent = leftview->contentItem();
+ QTRY_VERIFY(leftContent != 0);
+
+ QQuickItem *rightContent = rightview->contentItem();
+ QTRY_VERIFY(rightContent != 0);
+
+ rightview->setCurrentIndex(12);
+
+ QTRY_COMPARE(leftview->contentY(), 0.0);
+ QTRY_COMPARE(rightview->contentY(), 240.0);
+
+ QQuickItem *item;
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), false);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 11));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 11));
+ QCOMPARE(item->isVisible(), true);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 9));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 10));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 3));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 4));
+ QCOMPARE(item->isVisible(), true);
+
+ rightview->setCurrentIndex(0);
+
+ QTRY_COMPARE(leftview->contentY(), 0.0);
+ QTRY_COMPARE(rightview->contentY(), 0.0);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
+ QTRY_COMPARE(item->isVisible(), true);
+
+ QVERIFY(!findItem<QQuickItem>(leftContent, "wrapper", 11));
+ QVERIFY(!findItem<QQuickItem>(rightContent, "wrapper", 11));
+
+ leftview->setCurrentIndex(12);
+
+ QTRY_COMPARE(leftview->contentY(), 240.0);
+ QTRY_COMPARE(rightview->contentY(), 0.0);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QTRY_COMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), true);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 11));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 11));
+ QCOMPARE(item->isVisible(), false);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 4));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
+ QCOMPARE(item->isVisible(), false);
+
+ model.moveItems(19, 1, 1);
+ QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
+
+ QTRY_VERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), true);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 11));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 11));
+ QCOMPARE(item->isVisible(), false);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 4));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
+ QCOMPARE(item->isVisible(), false);
+
+ model.moveItems(3, 4, 1);
+ QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 2));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
+ QCOMPARE(item->isVisible(), false);
+
+ model.moveItems(4, 5, 1);
+ QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 2));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
+ QCOMPARE(item->isVisible(), false);
+
+ model.moveItems(9, 10, 1);
+ QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 2));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
+ QCOMPARE(item->isVisible(), false);
+
+ model.moveItems(10, 9, 1);
+ QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
+
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
+ QCOMPARE(item->isVisible(), false);
+ QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 2));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
+ QCOMPARE(item->isVisible(), true);
+ QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
+ QCOMPARE(item->isVisible(), false);
+
+ 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