1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtTest/QtTest>
43 #include <QtGui/qstringlistmodel.h>
44 #include <QtDeclarative/qsgview.h>
45 #include <QtDeclarative/qdeclarativeengine.h>
46 #include <QtDeclarative/qdeclarativecomponent.h>
47 #include <QtDeclarative/qdeclarativecontext.h>
48 #include <QtDeclarative/qdeclarativeexpression.h>
49 #include <QtDeclarative/private/qsgitem_p.h>
50 #include <QtDeclarative/private/qlistmodelinterface_p.h>
51 #include <QtDeclarative/private/qsggridview_p.h>
52 #include <QtDeclarative/private/qsgtext_p.h>
53 #include <QtDeclarative/private/qdeclarativelistmodel_p.h>
54 #include "../../../shared/util.h"
55 #include <QtOpenGL/QGLShaderProgram>
58 // In Symbian OS test data is located in applications private dir
62 Q_DECLARE_METATYPE(Qt::LayoutDirection)
63 Q_DECLARE_METATYPE(QSGGridView::Flow)
65 class tst_QSGGridView : public QObject
73 void cleanupTestCase();
81 void swapWithFirstItem();
84 void noCurrentIndex();
87 void propertyChanges();
88 void componentChanges();
90 void positionViewAtIndex();
91 void positionViewAtIndex_rightToLeft();
96 void enforceRange_rightToLeft();
98 void manualHighlight();
107 void onRemove_data();
108 void testQtQuick11Attributes();
109 void testQtQuick11Attributes_data();
112 QSGView *createView();
114 T *findItem(QSGItem *parent, const QString &id, int index=-1);
116 QList<T*> findItems(QSGItem *parent, const QString &objectName);
117 void dumpTree(QSGItem *parent, int depth = 0);
121 void tst_qsggridview_move(int from, int to, int n, T *items)
124 items->move(from, to);
128 typename T::ConstIterator it=items->begin(); it += from+n;
129 for (; i<to-from; ++i,++it)
130 replaced.append(*it);
132 it=items->begin(); it += from;
133 for (; i<n; ++i,++it)
134 replaced.append(*it);
135 typename T::ConstIterator f=replaced.begin();
136 typename T::Iterator t=items->begin(); t += from;
137 for (; f != replaced.end(); ++f, ++t)
142 void tst_QSGGridView::initTestCase()
145 if (!QGLShaderProgram::hasOpenGLShaderPrograms(canvas.context()))
146 QSKIP("QSGGridView needs OpenGL 2.0", SkipAll);
149 void tst_QSGGridView::cleanupTestCase()
153 class TestModel : public QAbstractListModel
156 enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 };
158 TestModel(QObject *parent=0) : QAbstractListModel(parent) {
159 QHash<int, QByteArray> roles;
160 roles[Name] = "name";
161 roles[Number] = "number";
165 int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); }
166 QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const {
169 rv = list.at(index.row()).first;
170 else if (role == Number)
171 rv = list.at(index.row()).second;
176 int count() const { return rowCount(); }
177 QString name(int index) const { return list.at(index).first; }
178 QString number(int index) const { return list.at(index).second; }
180 void addItem(const QString &name, const QString &number) {
181 emit beginInsertRows(QModelIndex(), list.count(), list.count());
182 list.append(QPair<QString,QString>(name, number));
183 emit endInsertRows();
186 void addItems(const QList<QPair<QString, QString> > &items) {
187 emit beginInsertRows(QModelIndex(), list.count(), list.count()+items.count()-1);
188 for (int i=0; i<items.count(); i++)
189 list.append(QPair<QString,QString>(items[i].first, items[i].second));
190 emit endInsertRows();
193 void insertItem(int index, const QString &name, const QString &number) {
194 emit beginInsertRows(QModelIndex(), index, index);
195 list.insert(index, QPair<QString,QString>(name, number));
196 emit endInsertRows();
199 void removeItem(int index) {
200 emit beginRemoveRows(QModelIndex(), index, index);
201 list.removeAt(index);
202 emit endRemoveRows();
205 void removeItems(int index, int count) {
206 emit beginRemoveRows(QModelIndex(), index, index+count-1);
208 list.removeAt(index);
209 emit endRemoveRows();
212 void moveItem(int from, int to) {
213 emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
218 void moveItems(int from, int to, int count) {
219 emit beginMoveRows(QModelIndex(), from, from+count-1, QModelIndex(), to > from ? to+count : to);
220 tst_qsggridview_move(from, to, count, &list);
224 void modifyItem(int idx, const QString &name, const QString &number) {
225 list[idx] = QPair<QString,QString>(name, number);
226 emit dataChanged(index(idx,0), index(idx,0));
230 int count = list.count();
231 emit beginRemoveRows(QModelIndex(), 0, count-1);
233 emit endRemoveRows();
238 QList<QPair<QString,QString> > list;
241 tst_QSGGridView::tst_QSGGridView()
245 void tst_QSGGridView::items()
247 QSGView *canvas = createView();
250 model.addItem("Fred", "12345");
251 model.addItem("John", "2345");
252 model.addItem("Bob", "54321");
253 model.addItem("Billy", "22345");
254 model.addItem("Sam", "2945");
255 model.addItem("Ben", "04321");
256 model.addItem("Jim", "0780");
258 QDeclarativeContext *ctxt = canvas->rootContext();
259 ctxt->setContextProperty("testModel", &model);
260 ctxt->setContextProperty("testRightToLeft", QVariant(false));
261 ctxt->setContextProperty("testTopToBottom", QVariant(false));
263 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
264 qApp->processEvents();
266 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
267 QTRY_VERIFY(gridview != 0);
269 QSGItem *contentItem = gridview->contentItem();
270 QTRY_VERIFY(contentItem != 0);
272 QTRY_COMPARE(gridview->count(), model.count());
273 QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
274 QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
276 for (int i = 0; i < model.count(); ++i) {
277 QSGText *name = findItem<QSGText>(contentItem, "textName", i);
278 QTRY_VERIFY(name != 0);
279 QTRY_COMPARE(name->text(), model.name(i));
280 QSGText *number = findItem<QSGText>(contentItem, "textNumber", i);
281 QTRY_VERIFY(number != 0);
282 QTRY_COMPARE(number->text(), model.number(i));
285 // set an empty model and confirm that items are destroyed
287 ctxt->setContextProperty("testModel", &model2);
289 int itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
290 QTRY_VERIFY(itemCount == 0);
295 void tst_QSGGridView::changed()
297 QSGView *canvas = createView();
300 model.addItem("Fred", "12345");
301 model.addItem("John", "2345");
302 model.addItem("Bob", "54321");
303 model.addItem("Billy", "22345");
304 model.addItem("Sam", "2945");
305 model.addItem("Ben", "04321");
306 model.addItem("Jim", "0780");
308 QDeclarativeContext *ctxt = canvas->rootContext();
309 ctxt->setContextProperty("testModel", &model);
310 ctxt->setContextProperty("testRightToLeft", QVariant(false));
311 ctxt->setContextProperty("testTopToBottom", QVariant(false));
313 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
314 qApp->processEvents();
316 QSGFlickable *gridview = findItem<QSGFlickable>(canvas->rootObject(), "grid");
317 QTRY_VERIFY(gridview != 0);
319 QSGItem *contentItem = gridview->contentItem();
320 QTRY_VERIFY(contentItem != 0);
322 model.modifyItem(1, "Will", "9876");
323 QSGText *name = findItem<QSGText>(contentItem, "textName", 1);
324 QTRY_VERIFY(name != 0);
325 QTRY_COMPARE(name->text(), model.name(1));
326 QSGText *number = findItem<QSGText>(contentItem, "textNumber", 1);
327 QTRY_VERIFY(number != 0);
328 QTRY_COMPARE(number->text(), model.number(1));
333 void tst_QSGGridView::inserted()
335 QSGView *canvas = createView();
339 model.addItem("Fred", "12345");
340 model.addItem("John", "2345");
341 model.addItem("Bob", "54321");
343 QDeclarativeContext *ctxt = canvas->rootContext();
344 ctxt->setContextProperty("testModel", &model);
345 ctxt->setContextProperty("testRightToLeft", QVariant(false));
346 ctxt->setContextProperty("testTopToBottom", QVariant(false));
348 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
349 qApp->processEvents();
351 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
352 QTRY_VERIFY(gridview != 0);
354 QSGItem *contentItem = gridview->contentItem();
355 QTRY_VERIFY(contentItem != 0);
357 model.insertItem(1, "Will", "9876");
358 QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
360 QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
362 QSGText *name = findItem<QSGText>(contentItem, "textName", 1);
363 QTRY_VERIFY(name != 0);
364 QTRY_COMPARE(name->text(), model.name(1));
365 QSGText *number = findItem<QSGText>(contentItem, "textNumber", 1);
366 QTRY_VERIFY(number != 0);
367 QTRY_COMPARE(number->text(), model.number(1));
369 // Checks that onAdd is called
370 int added = canvas->rootObject()->property("added").toInt();
371 QTRY_COMPARE(added, 1);
373 // Confirm items positioned correctly
374 for (int i = 0; i < model.count(); ++i) {
375 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
376 QTRY_COMPARE(item->x(), (i%3)*80.0);
377 QTRY_COMPARE(item->y(), (i/3)*60.0);
380 model.insertItem(0, "Foo", "1111"); // zero index, and current item
382 QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
384 name = findItem<QSGText>(contentItem, "textName", 0);
385 QTRY_VERIFY(name != 0);
386 QTRY_COMPARE(name->text(), model.name(0));
387 number = findItem<QSGText>(contentItem, "textNumber", 0);
388 QTRY_VERIFY(number != 0);
389 QTRY_COMPARE(number->text(), model.number(0));
391 QTRY_COMPARE(gridview->currentIndex(), 1);
393 // Confirm items positioned correctly
394 for (int i = 0; i < model.count(); ++i) {
395 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
396 QTRY_VERIFY(item->x() == (i%3)*80);
397 QTRY_VERIFY(item->y() == (i/3)*60);
400 for (int i = model.count(); i < 30; ++i)
401 model.insertItem(i, "Hello", QString::number(i));
403 gridview->setContentY(120);
405 // Insert item outside visible area
406 model.insertItem(1, "Hello", "1324");
408 QTRY_VERIFY(gridview->contentY() == 120);
413 void tst_QSGGridView::removed()
415 QSGView *canvas = createView();
419 for (int i = 0; i < 40; i++)
420 model.addItem("Item" + QString::number(i), "");
422 QDeclarativeContext *ctxt = canvas->rootContext();
423 ctxt->setContextProperty("testModel", &model);
424 ctxt->setContextProperty("testRightToLeft", QVariant(false));
425 ctxt->setContextProperty("testTopToBottom", QVariant(false));
427 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
428 qApp->processEvents();
430 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
431 QTRY_VERIFY(gridview != 0);
433 QSGItem *contentItem = gridview->contentItem();
434 QTRY_VERIFY(contentItem != 0);
437 QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
439 QSGText *name = findItem<QSGText>(contentItem, "textName", 1);
440 QTRY_VERIFY(name != 0);
441 QTRY_COMPARE(name->text(), model.name(1));
442 QSGText *number = findItem<QSGText>(contentItem, "textNumber", 1);
443 QTRY_VERIFY(number != 0);
444 QTRY_COMPARE(number->text(), model.number(1));
446 // Checks that onRemove is called
447 QString removed = canvas->rootObject()->property("removed").toString();
448 QTRY_COMPARE(removed, QString("Item1"));
450 // Confirm items positioned correctly
451 int itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
452 for (int i = 0; i < model.count() && i < itemCount; ++i) {
453 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
454 if (!item) qWarning() << "Item" << i << "not found";
456 QTRY_VERIFY(item->x() == (i%3)*80);
457 QTRY_VERIFY(item->y() == (i/3)*60);
460 // Remove first item (which is the current item);
463 name = findItem<QSGText>(contentItem, "textName", 0);
464 QTRY_VERIFY(name != 0);
465 QTRY_COMPARE(name->text(), model.name(0));
466 number = findItem<QSGText>(contentItem, "textNumber", 0);
467 QTRY_VERIFY(number != 0);
468 QTRY_COMPARE(number->text(), model.number(0));
470 // Confirm items positioned correctly
471 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
472 for (int i = 0; i < model.count() && i < itemCount; ++i) {
473 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
474 if (!item) qWarning() << "Item" << i << "not found";
476 QTRY_VERIFY(item->x() == (i%3)*80);
477 QTRY_VERIFY(item->y() == (i/3)*60);
480 // Remove items not visible
481 model.removeItem(25);
483 // Confirm items positioned correctly
484 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
485 for (int i = 0; i < model.count() && i < itemCount; ++i) {
486 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
487 if (!item) qWarning() << "Item" << i << "not found";
489 QTRY_VERIFY(item->x() == (i%3)*80);
490 QTRY_VERIFY(item->y() == (i/3)*60);
493 // Remove items before visible
494 gridview->setContentY(120);
495 gridview->setCurrentIndex(10);
497 // Setting currentIndex above shouldn't cause view to scroll
498 QTRY_COMPARE(gridview->contentY(), 120.0);
502 // Confirm items positioned correctly
503 for (int i = 6; i < 18; ++i) {
504 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
505 if (!item) qWarning() << "Item" << i << "not found";
507 QTRY_VERIFY(item->x() == (i%3)*80);
508 QTRY_VERIFY(item->y() == (i/3)*60);
511 // Remove currentIndex
512 QSGItem *oldCurrent = gridview->currentItem();
515 QTRY_COMPARE(gridview->currentIndex(), 9);
516 QTRY_VERIFY(gridview->currentItem() != oldCurrent);
518 gridview->setContentY(0);
519 // let transitions settle.
522 // Confirm items positioned correctly
523 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
524 for (int i = 0; i < model.count() && i < itemCount; ++i) {
525 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
526 if (!item) qWarning() << "Item" << i << "not found";
528 QTRY_VERIFY(item->x() == (i%3)*80);
529 QTRY_VERIFY(item->y() == (i/3)*60);
532 // remove item outside current view.
533 gridview->setCurrentIndex(32);
534 gridview->setContentY(240);
536 model.removeItem(30);
537 QTRY_VERIFY(gridview->currentIndex() == 31);
539 // remove current item beyond visible items.
540 gridview->setCurrentIndex(20);
541 gridview->setContentY(0);
542 model.removeItem(20);
544 QTRY_COMPARE(gridview->currentIndex(), 20);
545 QTRY_VERIFY(gridview->currentItem() != 0);
547 // remove item before current, but visible
548 gridview->setCurrentIndex(8);
549 gridview->setContentY(240);
550 oldCurrent = gridview->currentItem();
553 QTRY_COMPARE(gridview->currentIndex(), 7);
554 QTRY_VERIFY(gridview->currentItem() == oldCurrent);
559 void tst_QSGGridView::clear()
561 QSGView *canvas = createView();
564 for (int i = 0; i < 30; i++)
565 model.addItem("Item" + QString::number(i), "");
567 QDeclarativeContext *ctxt = canvas->rootContext();
568 ctxt->setContextProperty("testModel", &model);
569 ctxt->setContextProperty("testRightToLeft", QVariant(false));
570 ctxt->setContextProperty("testTopToBottom", QVariant(false));
572 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
573 qApp->processEvents();
575 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
576 QVERIFY(gridview != 0);
578 QSGItem *contentItem = gridview->contentItem();
579 QVERIFY(contentItem != 0);
583 QVERIFY(gridview->count() == 0);
584 QVERIFY(gridview->currentItem() == 0);
585 QVERIFY(gridview->contentY() == 0);
586 QVERIFY(gridview->currentIndex() == -1);
588 // confirm sanity when adding an item to cleared list
589 model.addItem("New", "1");
590 QVERIFY(gridview->count() == 1);
591 QVERIFY(gridview->currentItem() != 0);
592 QVERIFY(gridview->currentIndex() == 0);
597 void tst_QSGGridView::moved()
599 QFETCH(qreal, contentY);
603 QFETCH(qreal, itemsOffsetAfterMove);
607 QSGView *canvas = createView();
611 for (int i = 0; i < 30; i++)
612 model.addItem("Item" + QString::number(i), "");
614 QDeclarativeContext *ctxt = canvas->rootContext();
615 ctxt->setContextProperty("testModel", &model);
616 ctxt->setContextProperty("testRightToLeft", QVariant(false));
617 ctxt->setContextProperty("testTopToBottom", QVariant(false));
619 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
620 qApp->processEvents();
622 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
623 QTRY_VERIFY(gridview != 0);
625 QSGItem *contentItem = gridview->contentItem();
626 QTRY_VERIFY(contentItem != 0);
628 QSGItem *currentItem = gridview->currentItem();
629 QTRY_VERIFY(currentItem != 0);
631 gridview->setContentY(contentY);
632 model.moveItems(from, to, count);
634 // Confirm items positioned correctly and indexes correct
635 int firstVisibleIndex = qCeil(contentY / 60.0) * 3;
636 int itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
638 for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
639 if (i >= firstVisibleIndex + 18) // index has moved out of view
641 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
642 QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
644 QTRY_COMPARE(item->x(), (i%3)*80.0);
645 QTRY_COMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
647 name = findItem<QSGText>(contentItem, "textName", i);
649 QTRY_COMPARE(name->text(), model.name(i));
650 number = findItem<QSGText>(contentItem, "textNumber", i);
651 QVERIFY(number != 0);
652 QTRY_COMPARE(number->text(), model.number(i));
654 // current index should have been updated
655 if (item == currentItem)
656 QTRY_COMPARE(gridview->currentIndex(), i);
662 void tst_QSGGridView::moved_data()
664 QTest::addColumn<qreal>("contentY");
665 QTest::addColumn<int>("from");
666 QTest::addColumn<int>("to");
667 QTest::addColumn<int>("count");
668 QTest::addColumn<qreal>("itemsOffsetAfterMove");
670 // model starts with 30 items, each 80x60, in area 240x320
671 // 18 items should be visible at a time
673 QTest::newRow("move 1 forwards, within visible items")
678 QTest::newRow("move 1 forwards, from non-visible -> visible")
679 << 120.0 // show 6-23
683 QTest::newRow("move 1 forwards, from non-visible -> visible (move first item)")
684 << 120.0 // // show 6-23
688 QTest::newRow("move 1 forwards, from visible -> non-visible")
693 QTest::newRow("move 1 forwards, from visible -> non-visible (move first item)")
699 QTest::newRow("move 1 backwards, within visible items")
704 QTest::newRow("move 1 backwards, from non-visible -> visible")
709 QTest::newRow("move 1 backwards, from non-visible -> visible (move last item)")
714 QTest::newRow("move 1 backwards, from visible -> non-visible")
715 << 120.0 // show 6-23
717 << 60.0 * 2; // this results in a forward movement that removes 6 items (2 rows)
719 QTest::newRow("move 1 backwards, from visible -> non-visible (move first item)")
720 << 120.0 // show 6-23
722 << 60.0 * 2; // first visible item moved, so all items shift 2 rows down with it
725 QTest::newRow("move multiple forwards, within visible items")
728 << 60.0; // moved 3 items (i.e. 1 row) down
730 QTest::newRow("move multiple forwards, from non-visible -> visible")
731 << 120.0 // show 6-23
733 << 60.0; // top row moved, all items should shift down by 1 row
735 QTest::newRow("move multiple forwards, from non-visible -> visible (move first item)")
736 << 120.0 // show 6-23
738 << 60.0; // top row moved, all items should shift down by 1 row
740 QTest::newRow("move multiple forwards, from visible -> non-visible")
745 QTest::newRow("move multiple forwards, from visible -> non-visible (move first item)")
751 QTest::newRow("move multiple backwards, within visible items")
756 QTest::newRow("move multiple backwards, from non-visible -> visible")
761 QTest::newRow("move multiple backwards, from non-visible -> visible (move last item)")
766 QTest::newRow("move multiple backwards, from visible -> non-visible")
767 << 120.0 // show 6-23
769 << 60.0 * 5; // this results in a forward movement that removes 15 items (5 rows)
771 QTest::newRow("move multiple backwards, from visible -> non-visible (move first item)")
772 << 120.0 // show 6-23
774 << 60.0 * 5; // this results in a forward movement that removes 16 items (5 rows)
777 void tst_QSGGridView::swapWithFirstItem()
780 QSGView *canvas = createView();
784 for (int i = 0; i < 30; i++)
785 model.addItem("Item" + QString::number(i), "");
787 QDeclarativeContext *ctxt = canvas->rootContext();
788 ctxt->setContextProperty("testModel", &model);
789 ctxt->setContextProperty("testRightToLeft", QVariant(false));
790 ctxt->setContextProperty("testTopToBottom", QVariant(false));
792 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
793 qApp->processEvents();
795 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
796 QTRY_VERIFY(gridview != 0);
798 // ensure content position is stable
799 gridview->setContentY(0);
800 model.moveItem(10, 0);
801 QTRY_VERIFY(gridview->contentY() == 0);
806 void tst_QSGGridView::currentIndex()
809 for (int i = 0; i < 60; i++)
810 model.addItem("Item" + QString::number(i), QString::number(i));
812 QSGView *canvas = new QSGView(0);
813 canvas->setFixedSize(240,320);
816 QDeclarativeContext *ctxt = canvas->rootContext();
817 ctxt->setContextProperty("testModel", &model);
819 QString filename(SRCDIR "/data/gridview-initCurrent.qml");
820 canvas->setSource(QUrl::fromLocalFile(filename));
822 qApp->processEvents();
824 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
825 QVERIFY(gridview != 0);
827 QSGItem *contentItem = gridview->contentItem();
828 QVERIFY(contentItem != 0);
830 // current item should be third item
831 QCOMPARE(gridview->currentIndex(), 35);
832 QCOMPARE(gridview->currentItem(), findItem<QSGItem>(contentItem, "wrapper", 35));
833 QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y());
834 QCOMPARE(gridview->contentY(), 400.0);
836 gridview->moveCurrentIndexRight();
837 QCOMPARE(gridview->currentIndex(), 36);
838 gridview->moveCurrentIndexDown();
839 QCOMPARE(gridview->currentIndex(), 39);
840 gridview->moveCurrentIndexUp();
841 QCOMPARE(gridview->currentIndex(), 36);
842 gridview->moveCurrentIndexLeft();
843 QCOMPARE(gridview->currentIndex(), 35);
846 gridview->setCurrentIndex(0);
847 QCOMPARE(gridview->currentIndex(), 0);
848 // confirm that the velocity is updated
849 QTRY_VERIFY(gridview->verticalVelocity() != 0.0);
851 gridview->moveCurrentIndexUp();
852 QCOMPARE(gridview->currentIndex(), 0);
854 gridview->moveCurrentIndexLeft();
855 QCOMPARE(gridview->currentIndex(), 0);
857 gridview->setCurrentIndex(model.count()-1);
858 QCOMPARE(gridview->currentIndex(), model.count()-1);
860 gridview->moveCurrentIndexRight();
861 QCOMPARE(gridview->currentIndex(), model.count()-1);
863 gridview->moveCurrentIndexDown();
864 QCOMPARE(gridview->currentIndex(), model.count()-1);
867 gridview->setWrapEnabled(true);
869 gridview->setCurrentIndex(0);
870 QCOMPARE(gridview->currentIndex(), 0);
872 gridview->moveCurrentIndexLeft();
873 QCOMPARE(gridview->currentIndex(), model.count()-1);
875 qApp->processEvents();
876 QTRY_COMPARE(gridview->contentY(), 880.0);
878 gridview->moveCurrentIndexRight();
879 QCOMPARE(gridview->currentIndex(), 0);
881 QTRY_COMPARE(gridview->contentY(), 0.0);
884 qApp->setActiveWindow(canvas);
886 // to be safe and avoid failing setFocus with window managers
887 qt_x11_wait_for_window_manager(canvas);
889 QTRY_VERIFY(canvas->hasFocus());
890 qApp->processEvents();
892 QTest::keyClick(canvas, Qt::Key_Down);
893 QCOMPARE(gridview->currentIndex(), 3);
895 QTest::keyClick(canvas, Qt::Key_Up);
896 QCOMPARE(gridview->currentIndex(), 0);
898 // hold down Key_Down
899 for (int i=0; i<(model.count() / 3) - 1; i++) {
900 QTest::simulateEvent(canvas, true, Qt::Key_Down, Qt::NoModifier, "", true);
901 QTRY_COMPARE(gridview->currentIndex(), i*3 + 3);
903 QTest::keyRelease(canvas, Qt::Key_Down);
904 QTRY_COMPARE(gridview->currentIndex(), 57);
905 QTRY_COMPARE(gridview->contentY(), 880.0);
908 for (int i=(model.count() / 3) - 1; i > 0; i--) {
909 QTest::simulateEvent(canvas, true, Qt::Key_Up, Qt::NoModifier, "", true);
910 QTRY_COMPARE(gridview->currentIndex(), i*3 - 3);
912 QTest::keyRelease(canvas, Qt::Key_Up);
913 QTRY_COMPARE(gridview->currentIndex(), 0);
914 QTRY_COMPARE(gridview->contentY(), 0.0);
917 gridview->setFlow(QSGGridView::TopToBottom);
919 qApp->setActiveWindow(canvas);
921 // to be safe and avoid failing setFocus with window managers
922 qt_x11_wait_for_window_manager(canvas);
924 QTRY_VERIFY(canvas->hasFocus());
925 qApp->processEvents();
927 QTest::keyClick(canvas, Qt::Key_Right);
928 QCOMPARE(gridview->currentIndex(), 5);
930 QTest::keyClick(canvas, Qt::Key_Left);
931 QCOMPARE(gridview->currentIndex(), 0);
933 QTest::keyClick(canvas, Qt::Key_Down);
934 QCOMPARE(gridview->currentIndex(), 1);
936 QTest::keyClick(canvas, Qt::Key_Up);
937 QCOMPARE(gridview->currentIndex(), 0);
939 // hold down Key_Right
940 for (int i=0; i<(model.count() / 5) - 1; i++) {
941 QTest::simulateEvent(canvas, true, Qt::Key_Right, Qt::NoModifier, "", true);
942 QTRY_COMPARE(gridview->currentIndex(), i*5 + 5);
944 QTest::keyRelease(canvas, Qt::Key_Right);
945 QTRY_COMPARE(gridview->currentIndex(), 55);
946 QTRY_COMPARE(gridview->contentX(), 720.0);
948 // hold down Key_Left
949 for (int i=(model.count() / 5) - 1; i > 0; i--) {
950 QTest::simulateEvent(canvas, true, Qt::Key_Left, Qt::NoModifier, "", true);
951 QTRY_COMPARE(gridview->currentIndex(), i*5 - 5);
953 QTest::keyRelease(canvas, Qt::Key_Left);
954 QTRY_COMPARE(gridview->currentIndex(), 0);
955 QTRY_COMPARE(gridview->contentX(), 0.0);
958 // turn off auto highlight
959 gridview->setHighlightFollowsCurrentItem(false);
960 QVERIFY(gridview->highlightFollowsCurrentItem() == false);
961 QVERIFY(gridview->highlightItem());
962 qreal hlPosX = gridview->highlightItem()->x();
963 qreal hlPosY = gridview->highlightItem()->y();
965 gridview->setCurrentIndex(5);
966 QTRY_COMPARE(gridview->highlightItem()->x(), hlPosX);
967 QTRY_COMPARE(gridview->highlightItem()->y(), hlPosY);
969 // insert item before currentIndex
970 gridview->setCurrentIndex(28);
971 model.insertItem(0, "Foo", "1111");
972 QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29);
974 // check removing highlight by setting currentIndex to -1;
975 gridview->setCurrentIndex(-1);
977 QCOMPARE(gridview->currentIndex(), -1);
978 QVERIFY(!gridview->highlightItem());
979 QVERIFY(!gridview->currentItem());
981 gridview->setHighlightFollowsCurrentItem(true);
983 gridview->setFlow(QSGGridView::LeftToRight);
984 gridview->setLayoutDirection(Qt::RightToLeft);
986 qApp->setActiveWindow(canvas);
988 // to be safe and avoid failing setFocus with window managers
989 qt_x11_wait_for_window_manager(canvas);
991 QTRY_VERIFY(canvas->hasFocus());
992 qApp->processEvents();
994 gridview->setCurrentIndex(35);
996 QTest::keyClick(canvas, Qt::Key_Right);
997 QCOMPARE(gridview->currentIndex(), 34);
999 QTest::keyClick(canvas, Qt::Key_Down);
1000 QCOMPARE(gridview->currentIndex(), 37);
1002 QTest::keyClick(canvas, Qt::Key_Up);
1003 QCOMPARE(gridview->currentIndex(), 34);
1005 QTest::keyClick(canvas, Qt::Key_Left);
1006 QCOMPARE(gridview->currentIndex(), 35);
1009 // turn off auto highlight
1010 gridview->setHighlightFollowsCurrentItem(false);
1011 QVERIFY(gridview->highlightFollowsCurrentItem() == false);
1012 QVERIFY(gridview->highlightItem());
1013 hlPosX = gridview->highlightItem()->x();
1014 hlPosY = gridview->highlightItem()->y();
1016 gridview->setCurrentIndex(5);
1017 QTRY_COMPARE(gridview->highlightItem()->x(), hlPosX);
1018 QTRY_COMPARE(gridview->highlightItem()->y(), hlPosY);
1020 // insert item before currentIndex
1021 gridview->setCurrentIndex(28);
1022 model.insertItem(0, "Foo", "1111");
1023 QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29);
1025 // check removing highlight by setting currentIndex to -1;
1026 gridview->setCurrentIndex(-1);
1028 QCOMPARE(gridview->currentIndex(), -1);
1029 QVERIFY(!gridview->highlightItem());
1030 QVERIFY(!gridview->currentItem());
1035 void tst_QSGGridView::noCurrentIndex()
1038 for (int i = 0; i < 60; i++)
1039 model.addItem("Item" + QString::number(i), QString::number(i));
1041 QSGView *canvas = new QSGView(0);
1042 canvas->setFixedSize(240,320);
1044 QDeclarativeContext *ctxt = canvas->rootContext();
1045 ctxt->setContextProperty("testModel", &model);
1047 QString filename(SRCDIR "/data/gridview-noCurrent.qml");
1048 canvas->setSource(QUrl::fromLocalFile(filename));
1050 qApp->processEvents();
1052 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1053 QVERIFY(gridview != 0);
1055 QSGItem *contentItem = gridview->contentItem();
1056 QVERIFY(contentItem != 0);
1058 // current index should be -1
1059 QCOMPARE(gridview->currentIndex(), -1);
1060 QVERIFY(!gridview->currentItem());
1061 QVERIFY(!gridview->highlightItem());
1062 QCOMPARE(gridview->contentY(), 0.0);
1064 gridview->setCurrentIndex(5);
1065 QCOMPARE(gridview->currentIndex(), 5);
1066 QVERIFY(gridview->currentItem());
1067 QVERIFY(gridview->highlightItem());
1072 void tst_QSGGridView::changeFlow()
1074 QSGView *canvas = createView();
1077 for (int i = 0; i < 30; i++)
1078 model.addItem("Item" + QString::number(i), QString::number(i));
1080 QDeclarativeContext *ctxt = canvas->rootContext();
1081 ctxt->setContextProperty("testModel", &model);
1082 ctxt->setContextProperty("testRightToLeft", QVariant(false));
1083 ctxt->setContextProperty("testTopToBottom", QVariant(false));
1085 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
1086 qApp->processEvents();
1088 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1089 QTRY_VERIFY(gridview != 0);
1091 QSGItem *contentItem = gridview->contentItem();
1092 QTRY_VERIFY(contentItem != 0);
1094 // Confirm items positioned correctly and indexes correct
1095 int itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1096 for (int i = 0; i < model.count() && i < itemCount; ++i) {
1097 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1098 if (!item) qWarning() << "Item" << i << "not found";
1100 QTRY_COMPARE(item->x(), qreal((i%3)*80));
1101 QTRY_COMPARE(item->y(), qreal((i/3)*60));
1102 QSGText *name = findItem<QSGText>(contentItem, "textName", i);
1103 QTRY_VERIFY(name != 0);
1104 QTRY_COMPARE(name->text(), model.name(i));
1105 QSGText *number = findItem<QSGText>(contentItem, "textNumber", i);
1106 QTRY_VERIFY(number != 0);
1107 QTRY_COMPARE(number->text(), model.number(i));
1110 ctxt->setContextProperty("testTopToBottom", QVariant(true));
1112 // Confirm items positioned correctly and indexes correct
1113 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1114 for (int i = 0; i < model.count() && i < itemCount; ++i) {
1115 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1116 if (!item) qWarning() << "Item" << i << "not found";
1118 QTRY_COMPARE(item->x(), qreal((i/5)*80));
1119 QTRY_COMPARE(item->y(), qreal((i%5)*60));
1120 QSGText *name = findItem<QSGText>(contentItem, "textName", i);
1121 QTRY_VERIFY(name != 0);
1122 QTRY_COMPARE(name->text(), model.name(i));
1123 QSGText *number = findItem<QSGText>(contentItem, "textNumber", i);
1124 QTRY_VERIFY(number != 0);
1125 QTRY_COMPARE(number->text(), model.number(i));
1128 ctxt->setContextProperty("testRightToLeft", QVariant(true));
1130 // Confirm items positioned correctly and indexes correct
1131 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1132 for (int i = 0; i < model.count() && i < itemCount; ++i) {
1133 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1134 if (!item) qWarning() << "Item" << i << "not found";
1136 QTRY_COMPARE(item->x(), qreal(-(i/5)*80 - item->width()));
1137 QTRY_COMPARE(item->y(), qreal((i%5)*60));
1138 QSGText *name = findItem<QSGText>(contentItem, "textName", i);
1139 QTRY_VERIFY(name != 0);
1140 QTRY_COMPARE(name->text(), model.name(i));
1141 QSGText *number = findItem<QSGText>(contentItem, "textNumber", i);
1142 QTRY_VERIFY(number != 0);
1143 QTRY_COMPARE(number->text(), model.number(i));
1145 gridview->setContentX(100);
1146 QTRY_COMPARE(gridview->contentX(), 100.);
1147 ctxt->setContextProperty("testTopToBottom", QVariant(false));
1148 QTRY_COMPARE(gridview->contentX(), 0.);
1150 // Confirm items positioned correctly and indexes correct
1151 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1152 for (int i = 0; i < model.count() && i < itemCount; ++i) {
1153 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1154 if (!item) qWarning() << "Item" << i << "not found";
1156 QTRY_COMPARE(item->x(), qreal(240 - (i%3+1)*80));
1157 QTRY_COMPARE(item->y(), qreal((i/3)*60));
1158 QSGText *name = findItem<QSGText>(contentItem, "textName", i);
1159 QTRY_VERIFY(name != 0);
1160 QTRY_COMPARE(name->text(), model.name(i));
1161 QSGText *number = findItem<QSGText>(contentItem, "textNumber", i);
1162 QTRY_VERIFY(number != 0);
1163 QTRY_COMPARE(number->text(), model.number(i));
1169 void tst_QSGGridView::defaultValues()
1171 QDeclarativeEngine engine;
1172 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/gridview3.qml"));
1173 QSGGridView *obj = qobject_cast<QSGGridView*>(c.create());
1175 QTRY_VERIFY(obj != 0);
1176 QTRY_VERIFY(obj->model() == QVariant());
1177 QTRY_VERIFY(obj->delegate() == 0);
1178 QTRY_COMPARE(obj->currentIndex(), -1);
1179 QTRY_VERIFY(obj->currentItem() == 0);
1180 QTRY_COMPARE(obj->count(), 0);
1181 QTRY_VERIFY(obj->highlight() == 0);
1182 QTRY_VERIFY(obj->highlightItem() == 0);
1183 QTRY_COMPARE(obj->highlightFollowsCurrentItem(), true);
1184 QTRY_VERIFY(obj->flow() == 0);
1185 QTRY_COMPARE(obj->isWrapEnabled(), false);
1186 QTRY_COMPARE(obj->cacheBuffer(), 0);
1187 QTRY_COMPARE(obj->cellWidth(), 100); //### Should 100 be the default?
1188 QTRY_COMPARE(obj->cellHeight(), 100);
1192 void tst_QSGGridView::properties()
1194 QDeclarativeEngine engine;
1195 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/gridview2.qml"));
1196 QSGGridView *obj = qobject_cast<QSGGridView*>(c.create());
1198 QTRY_VERIFY(obj != 0);
1199 QTRY_VERIFY(obj->model() != QVariant());
1200 QTRY_VERIFY(obj->delegate() != 0);
1201 QTRY_COMPARE(obj->currentIndex(), 0);
1202 QTRY_VERIFY(obj->currentItem() != 0);
1203 QTRY_COMPARE(obj->count(), 4);
1204 QTRY_VERIFY(obj->highlight() != 0);
1205 QTRY_VERIFY(obj->highlightItem() != 0);
1206 QTRY_COMPARE(obj->highlightFollowsCurrentItem(), false);
1207 QTRY_VERIFY(obj->flow() == 0);
1208 QTRY_COMPARE(obj->isWrapEnabled(), true);
1209 QTRY_COMPARE(obj->cacheBuffer(), 200);
1210 QTRY_COMPARE(obj->cellWidth(), 100);
1211 QTRY_COMPARE(obj->cellHeight(), 100);
1215 void tst_QSGGridView::propertyChanges()
1217 QSGView *canvas = createView();
1218 QTRY_VERIFY(canvas);
1219 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml"));
1221 QSGGridView *gridView = canvas->rootObject()->findChild<QSGGridView*>("gridView");
1222 QTRY_VERIFY(gridView);
1224 QSignalSpy keyNavigationWrapsSpy(gridView, SIGNAL(keyNavigationWrapsChanged()));
1225 QSignalSpy cacheBufferSpy(gridView, SIGNAL(cacheBufferChanged()));
1226 QSignalSpy layoutSpy(gridView, SIGNAL(layoutDirectionChanged()));
1227 QSignalSpy flowSpy(gridView, SIGNAL(flowChanged()));
1229 QTRY_COMPARE(gridView->isWrapEnabled(), true);
1230 QTRY_COMPARE(gridView->cacheBuffer(), 10);
1231 QTRY_COMPARE(gridView->flow(), QSGGridView::LeftToRight);
1233 gridView->setWrapEnabled(false);
1234 gridView->setCacheBuffer(3);
1235 gridView->setFlow(QSGGridView::TopToBottom);
1237 QTRY_COMPARE(gridView->isWrapEnabled(), false);
1238 QTRY_COMPARE(gridView->cacheBuffer(), 3);
1239 QTRY_COMPARE(gridView->flow(), QSGGridView::TopToBottom);
1241 QTRY_COMPARE(keyNavigationWrapsSpy.count(),1);
1242 QTRY_COMPARE(cacheBufferSpy.count(),1);
1243 QTRY_COMPARE(flowSpy.count(),1);
1245 gridView->setWrapEnabled(false);
1246 gridView->setCacheBuffer(3);
1247 gridView->setFlow(QSGGridView::TopToBottom);
1249 QTRY_COMPARE(keyNavigationWrapsSpy.count(),1);
1250 QTRY_COMPARE(cacheBufferSpy.count(),1);
1251 QTRY_COMPARE(flowSpy.count(),1);
1253 gridView->setFlow(QSGGridView::LeftToRight);
1254 QTRY_COMPARE(gridView->flow(), QSGGridView::LeftToRight);
1256 gridView->setWrapEnabled(true);
1257 gridView->setCacheBuffer(5);
1258 gridView->setLayoutDirection(Qt::RightToLeft);
1260 QTRY_COMPARE(gridView->isWrapEnabled(), true);
1261 QTRY_COMPARE(gridView->cacheBuffer(), 5);
1262 QTRY_COMPARE(gridView->layoutDirection(), Qt::RightToLeft);
1264 QTRY_COMPARE(keyNavigationWrapsSpy.count(),2);
1265 QTRY_COMPARE(cacheBufferSpy.count(),2);
1266 QTRY_COMPARE(layoutSpy.count(),1);
1267 QTRY_COMPARE(flowSpy.count(),2);
1269 gridView->setWrapEnabled(true);
1270 gridView->setCacheBuffer(5);
1271 gridView->setLayoutDirection(Qt::RightToLeft);
1273 QTRY_COMPARE(keyNavigationWrapsSpy.count(),2);
1274 QTRY_COMPARE(cacheBufferSpy.count(),2);
1275 QTRY_COMPARE(layoutSpy.count(),1);
1276 QTRY_COMPARE(flowSpy.count(),2);
1278 gridView->setFlow(QSGGridView::TopToBottom);
1279 QTRY_COMPARE(gridView->flow(), QSGGridView::TopToBottom);
1280 QTRY_COMPARE(flowSpy.count(),3);
1282 gridView->setFlow(QSGGridView::TopToBottom);
1283 QTRY_COMPARE(flowSpy.count(),3);
1288 void tst_QSGGridView::componentChanges()
1290 QSGView *canvas = createView();
1291 QTRY_VERIFY(canvas);
1292 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml"));
1294 QSGGridView *gridView = canvas->rootObject()->findChild<QSGGridView*>("gridView");
1295 QTRY_VERIFY(gridView);
1297 QDeclarativeComponent component(canvas->engine());
1298 component.setData("import QtQuick 1.0; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile(""));
1300 QDeclarativeComponent delegateComponent(canvas->engine());
1301 delegateComponent.setData("import QtQuick 1.0; Text { text: '<b>Name:</b> ' + name }", QUrl::fromLocalFile(""));
1303 QSignalSpy highlightSpy(gridView, SIGNAL(highlightChanged()));
1304 QSignalSpy delegateSpy(gridView, SIGNAL(delegateChanged()));
1305 QSignalSpy headerSpy(gridView, SIGNAL(headerChanged()));
1306 QSignalSpy footerSpy(gridView, SIGNAL(footerChanged()));
1308 gridView->setHighlight(&component);
1309 gridView->setDelegate(&delegateComponent);
1310 gridView->setHeader(&component);
1311 gridView->setFooter(&component);
1313 QTRY_COMPARE(gridView->highlight(), &component);
1314 QTRY_COMPARE(gridView->delegate(), &delegateComponent);
1315 QTRY_COMPARE(gridView->header(), &component);
1316 QTRY_COMPARE(gridView->footer(), &component);
1318 QTRY_COMPARE(highlightSpy.count(),1);
1319 QTRY_COMPARE(delegateSpy.count(),1);
1320 QTRY_COMPARE(headerSpy.count(),1);
1321 QTRY_COMPARE(footerSpy.count(),1);
1323 gridView->setHighlight(&component);
1324 gridView->setDelegate(&delegateComponent);
1325 gridView->setHeader(&component);
1326 gridView->setFooter(&component);
1328 QTRY_COMPARE(highlightSpy.count(),1);
1329 QTRY_COMPARE(delegateSpy.count(),1);
1330 QTRY_COMPARE(headerSpy.count(),1);
1331 QTRY_COMPARE(footerSpy.count(),1);
1336 void tst_QSGGridView::modelChanges()
1338 QSGView *canvas = createView();
1339 QTRY_VERIFY(canvas);
1340 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml"));
1342 QSGGridView *gridView = canvas->rootObject()->findChild<QSGGridView*>("gridView");
1343 QTRY_VERIFY(gridView);
1345 QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild<QDeclarativeListModel*>("alternateModel");
1346 QTRY_VERIFY(alternateModel);
1347 QVariant modelVariant = QVariant::fromValue<QObject *>(alternateModel);
1348 QSignalSpy modelSpy(gridView, SIGNAL(modelChanged()));
1350 gridView->setModel(modelVariant);
1351 QTRY_COMPARE(gridView->model(), modelVariant);
1352 QTRY_COMPARE(modelSpy.count(),1);
1354 gridView->setModel(modelVariant);
1355 QTRY_COMPARE(modelSpy.count(),1);
1357 gridView->setModel(QVariant());
1358 QTRY_COMPARE(modelSpy.count(),2);
1362 void tst_QSGGridView::positionViewAtIndex()
1364 QSGView *canvas = createView();
1367 for (int i = 0; i < 40; i++)
1368 model.addItem("Item" + QString::number(i), "");
1370 QDeclarativeContext *ctxt = canvas->rootContext();
1371 ctxt->setContextProperty("testModel", &model);
1372 ctxt->setContextProperty("testRightToLeft", QVariant(false));
1373 ctxt->setContextProperty("testTopToBottom", QVariant(false));
1375 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
1376 qApp->processEvents();
1378 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1379 QTRY_VERIFY(gridview != 0);
1381 QSGItem *contentItem = gridview->contentItem();
1382 QTRY_VERIFY(contentItem != 0);
1384 // Confirm items positioned correctly
1385 int itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1386 for (int i = 0; i < model.count() && i < itemCount-1; ++i) {
1387 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1388 if (!item) qWarning() << "Item" << i << "not found";
1390 QTRY_COMPARE(item->x(), (i%3)*80.);
1391 QTRY_COMPARE(item->y(), (i/3)*60.);
1394 // Position on a currently visible item
1395 gridview->positionViewAtIndex(4, QSGGridView::Beginning);
1396 QTRY_COMPARE(gridview->indexAt(120, 90), 4);
1397 QTRY_COMPARE(gridview->contentY(), 60.);
1399 // Confirm items positioned correctly
1400 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1401 for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) {
1402 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1403 if (!item) qWarning() << "Item" << i << "not found";
1405 QTRY_COMPARE(item->x(), (i%3)*80.);
1406 QTRY_COMPARE(item->y(), (i/3)*60.);
1409 // Position on an item beyond the visible items
1410 gridview->positionViewAtIndex(21, QSGGridView::Beginning);
1411 QTRY_COMPARE(gridview->indexAt(40, 450), 21);
1412 QTRY_COMPARE(gridview->contentY(), 420.);
1414 // Confirm items positioned correctly
1415 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1416 for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) {
1417 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1418 if (!item) qWarning() << "Item" << i << "not found";
1420 QTRY_COMPARE(item->x(), (i%3)*80.);
1421 QTRY_COMPARE(item->y(), (i/3)*60.);
1424 // Position on an item that would leave empty space if positioned at the top
1425 gridview->positionViewAtIndex(31, QSGGridView::Beginning);
1426 QTRY_COMPARE(gridview->indexAt(120, 630), 31);
1427 QTRY_COMPARE(gridview->contentY(), 520.);
1429 // Confirm items positioned correctly
1430 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1431 for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) {
1432 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1433 if (!item) qWarning() << "Item" << i << "not found";
1435 QTRY_COMPARE(item->x(), (i%3)*80.);
1436 QTRY_COMPARE(item->y(), (i/3)*60.);
1439 // Position at the beginning again
1440 gridview->positionViewAtIndex(0, QSGGridView::Beginning);
1441 QTRY_COMPARE(gridview->indexAt(0, 0), 0);
1442 QTRY_COMPARE(gridview->indexAt(40, 30), 0);
1443 QTRY_COMPARE(gridview->indexAt(80, 60), 4);
1444 QTRY_COMPARE(gridview->contentY(), 0.);
1446 // Confirm items positioned correctly
1447 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1448 for (int i = 0; i < model.count() && i < itemCount-1; ++i) {
1449 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1450 if (!item) qWarning() << "Item" << i << "not found";
1452 QTRY_COMPARE(item->x(), (i%3)*80.);
1453 QTRY_COMPARE(item->y(), (i/3)*60.);
1457 gridview->positionViewAtIndex(30, QSGGridView::End);
1458 QTRY_COMPARE(gridview->contentY(), 340.);
1460 // Position in Center
1461 gridview->positionViewAtIndex(15, QSGGridView::Center);
1462 QTRY_COMPARE(gridview->contentY(), 170.);
1464 // Ensure at least partially visible
1465 gridview->positionViewAtIndex(15, QSGGridView::Visible);
1466 QTRY_COMPARE(gridview->contentY(), 170.);
1468 gridview->setContentY(302);
1469 gridview->positionViewAtIndex(15, QSGGridView::Visible);
1470 QTRY_COMPARE(gridview->contentY(), 302.);
1472 gridview->setContentY(360);
1473 gridview->positionViewAtIndex(15, QSGGridView::Visible);
1474 QTRY_COMPARE(gridview->contentY(), 300.);
1476 gridview->setContentY(60);
1477 gridview->positionViewAtIndex(20, QSGGridView::Visible);
1478 QTRY_COMPARE(gridview->contentY(), 60.);
1480 gridview->setContentY(20);
1481 gridview->positionViewAtIndex(20, QSGGridView::Visible);
1482 QTRY_COMPARE(gridview->contentY(), 100.);
1484 // Ensure completely visible
1485 gridview->setContentY(120);
1486 gridview->positionViewAtIndex(20, QSGGridView::Contain);
1487 QTRY_COMPARE(gridview->contentY(), 120.);
1489 gridview->setContentY(302);
1490 gridview->positionViewAtIndex(15, QSGGridView::Contain);
1491 QTRY_COMPARE(gridview->contentY(), 300.);
1493 gridview->setContentY(60);
1494 gridview->positionViewAtIndex(20, QSGGridView::Contain);
1495 QTRY_COMPARE(gridview->contentY(), 100.);
1497 // Test for Top To Bottom layout
1498 ctxt->setContextProperty("testTopToBottom", QVariant(true));
1500 // Confirm items positioned correctly
1501 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1502 for (int i = 0; i < model.count() && i < itemCount-1; ++i) {
1503 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1504 if (!item) qWarning() << "Item" << i << "not found";
1506 QTRY_COMPARE(item->x(), (i/5)*80.);
1507 QTRY_COMPARE(item->y(), (i%5)*60.);
1511 gridview->positionViewAtIndex(30, QSGGridView::End);
1512 QTRY_COMPARE(gridview->contentX(), 320.);
1513 QTRY_COMPARE(gridview->contentY(), 0.);
1515 // Position in Center
1516 gridview->positionViewAtIndex(15, QSGGridView::Center);
1517 QTRY_COMPARE(gridview->contentX(), 160.);
1519 // Ensure at least partially visible
1520 gridview->positionViewAtIndex(15, QSGGridView::Visible);
1521 QTRY_COMPARE(gridview->contentX(), 160.);
1523 gridview->setContentX(170);
1524 gridview->positionViewAtIndex(25, QSGGridView::Visible);
1525 QTRY_COMPARE(gridview->contentX(), 170.);
1527 gridview->positionViewAtIndex(30, QSGGridView::Visible);
1528 QTRY_COMPARE(gridview->contentX(), 320.);
1530 gridview->setContentX(170);
1531 gridview->positionViewAtIndex(25, QSGGridView::Contain);
1532 QTRY_COMPARE(gridview->contentX(), 240.);
1534 // positionViewAtBeginning
1535 gridview->positionViewAtBeginning();
1536 QTRY_COMPARE(gridview->contentX(), 0.);
1538 gridview->setContentX(80);
1539 canvas->rootObject()->setProperty("showHeader", true);
1540 gridview->positionViewAtBeginning();
1541 QTRY_COMPARE(gridview->contentX(), -30.);
1543 // positionViewAtEnd
1544 gridview->positionViewAtEnd();
1545 QTRY_COMPARE(gridview->contentX(), 400.); // 8*80 - 240 (8 columns)
1547 gridview->setContentX(80);
1548 canvas->rootObject()->setProperty("showFooter", true);
1549 gridview->positionViewAtEnd();
1550 QTRY_COMPARE(gridview->contentX(), 430.);
1552 // set current item to outside visible view, position at beginning
1553 // and ensure highlight moves to current item
1554 gridview->setCurrentIndex(6);
1555 gridview->positionViewAtBeginning();
1556 QTRY_COMPARE(gridview->contentX(), -30.);
1557 QVERIFY(gridview->highlightItem());
1558 QCOMPARE(gridview->highlightItem()->x(), 80.);
1563 void tst_QSGGridView::snapping()
1565 QSGView *canvas = createView();
1568 for (int i = 0; i < 40; i++)
1569 model.addItem("Item" + QString::number(i), "");
1571 QDeclarativeContext *ctxt = canvas->rootContext();
1572 ctxt->setContextProperty("testModel", &model);
1573 ctxt->setContextProperty("testTopToBottom", QVariant(false));
1574 ctxt->setContextProperty("testRightToLeft", QVariant(false));
1576 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
1577 qApp->processEvents();
1579 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1580 QTRY_VERIFY(gridview != 0);
1582 gridview->setHeight(220);
1583 QCOMPARE(gridview->height(), 220.);
1585 gridview->positionViewAtIndex(12, QSGGridView::Visible);
1586 QCOMPARE(gridview->contentY(), 80.);
1588 gridview->setContentY(0);
1589 QCOMPARE(gridview->contentY(), 0.);
1591 gridview->setSnapMode(QSGGridView::SnapToRow);
1592 QCOMPARE(gridview->snapMode(), QSGGridView::SnapToRow);
1594 gridview->positionViewAtIndex(12, QSGGridView::Visible);
1595 QCOMPARE(gridview->contentY(), 60.);
1597 gridview->positionViewAtIndex(15, QSGGridView::End);
1598 QCOMPARE(gridview->contentY(), 120.);
1604 void tst_QSGGridView::mirroring()
1606 QSGView *canvasA = createView();
1607 canvasA->setSource(QUrl::fromLocalFile(SRCDIR "/data/mirroring.qml"));
1608 QSGGridView *gridviewA = findItem<QSGGridView>(canvasA->rootObject(), "view");
1609 QTRY_VERIFY(gridviewA != 0);
1611 QSGView *canvasB = createView();
1612 canvasB->setSource(QUrl::fromLocalFile(SRCDIR "/data/mirroring.qml"));
1613 QSGGridView *gridviewB = findItem<QSGGridView>(canvasB->rootObject(), "view");
1614 QTRY_VERIFY(gridviewA != 0);
1615 qApp->processEvents();
1617 QList<QString> objectNames;
1618 objectNames << "item1" << "item2"; // << "item3"
1620 gridviewA->setProperty("layoutDirection", Qt::LeftToRight);
1621 gridviewB->setProperty("layoutDirection", Qt::RightToLeft);
1622 QCOMPARE(gridviewA->layoutDirection(), gridviewA->effectiveLayoutDirection());
1625 foreach(const QString objectName, objectNames)
1626 QVERIFY(findItem<QSGItem>(gridviewA, objectName)->x() != findItem<QSGItem>(gridviewB, objectName)->x());
1628 gridviewA->setProperty("layoutDirection", Qt::LeftToRight);
1629 gridviewB->setProperty("layoutDirection", Qt::LeftToRight);
1632 foreach(const QString objectName, objectNames)
1633 QCOMPARE(findItem<QSGItem>(gridviewA, objectName)->x(), findItem<QSGItem>(gridviewB, objectName)->x());
1635 QVERIFY(gridviewB->layoutDirection() == gridviewB->effectiveLayoutDirection());
1636 QSGItemPrivate::get(gridviewB)->setLayoutMirror(true);
1637 QVERIFY(gridviewB->layoutDirection() != gridviewB->effectiveLayoutDirection());
1639 // LTR != LTR+mirror
1640 foreach(const QString objectName, objectNames)
1641 QVERIFY(findItem<QSGItem>(gridviewA, objectName)->x() != findItem<QSGItem>(gridviewB, objectName)->x());
1643 gridviewA->setProperty("layoutDirection", Qt::RightToLeft);
1645 // RTL == LTR+mirror
1646 foreach(const QString objectName, objectNames)
1647 QCOMPARE(findItem<QSGItem>(gridviewA, objectName)->x(), findItem<QSGItem>(gridviewB, objectName)->x());
1649 gridviewB->setProperty("layoutDirection", Qt::RightToLeft);
1651 // RTL != RTL+mirror
1652 foreach(const QString objectName, objectNames)
1653 QVERIFY(findItem<QSGItem>(gridviewA, objectName)->x() != findItem<QSGItem>(gridviewB, objectName)->x());
1655 gridviewA->setProperty("layoutDirection", Qt::LeftToRight);
1657 // LTR == RTL+mirror
1658 foreach(const QString objectName, objectNames)
1659 QCOMPARE(findItem<QSGItem>(gridviewA, objectName)->x(), findItem<QSGItem>(gridviewB, objectName)->x());
1665 void tst_QSGGridView::positionViewAtIndex_rightToLeft()
1667 QSGView *canvas = createView();
1670 for (int i = 0; i < 40; i++)
1671 model.addItem("Item" + QString::number(i), "");
1673 QDeclarativeContext *ctxt = canvas->rootContext();
1674 ctxt->setContextProperty("testModel", &model);
1675 ctxt->setContextProperty("testTopToBottom", QVariant(true));
1676 ctxt->setContextProperty("testRightToLeft", QVariant(true));
1678 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
1679 qApp->processEvents();
1681 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1682 QTRY_VERIFY(gridview != 0);
1684 QSGItem *contentItem = gridview->contentItem();
1685 QTRY_VERIFY(contentItem != 0);
1687 // Confirm items positioned correctly
1688 int itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1689 for (int i = 0; i < model.count() && i < itemCount-1; ++i) {
1690 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1691 if (!item) qWarning() << "Item" << i << "not found";
1693 QTRY_COMPARE(item->x(), qreal(-(i/5)*80-item->width()));
1694 QTRY_COMPARE(item->y(), qreal((i%5)*60));
1697 // Position on a currently visible item
1698 gridview->positionViewAtIndex(6, QSGGridView::Beginning);
1699 QTRY_COMPARE(gridview->contentX(), -320.);
1701 // Confirm items positioned correctly
1702 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1703 for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) {
1704 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1705 if (!item) qWarning() << "Item" << i << "not found";
1707 QTRY_COMPARE(item->x(), qreal(-(i/5)*80-item->width()));
1708 QTRY_COMPARE(item->y(), qreal((i%5)*60));
1711 // Position on an item beyond the visible items
1712 gridview->positionViewAtIndex(21, QSGGridView::Beginning);
1713 QTRY_COMPARE(gridview->contentX(), -560.);
1715 // Confirm items positioned correctly
1716 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1717 for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) {
1718 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1719 if (!item) qWarning() << "Item" << i << "not found";
1721 QTRY_COMPARE(item->x(), qreal(-(i/5)*80-item->width()));
1722 QTRY_COMPARE(item->y(), qreal((i%5)*60));
1725 // Position on an item that would leave empty space if positioned at the top
1726 gridview->positionViewAtIndex(31, QSGGridView::Beginning);
1727 QTRY_COMPARE(gridview->contentX(), -640.);
1729 // Confirm items positioned correctly
1730 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1731 for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) {
1732 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1733 if (!item) qWarning() << "Item" << i << "not found";
1735 QTRY_COMPARE(item->x(), qreal(-(i/5)*80-item->width()));
1736 QTRY_COMPARE(item->y(), qreal((i%5)*60));
1739 // Position at the beginning again
1740 gridview->positionViewAtIndex(0, QSGGridView::Beginning);
1741 QTRY_COMPARE(gridview->contentX(), -240.);
1743 // Confirm items positioned correctly
1744 itemCount = findItems<QSGItem>(contentItem, "wrapper").count();
1745 for (int i = 0; i < model.count() && i < itemCount-1; ++i) {
1746 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", i);
1747 if (!item) qWarning() << "Item" << i << "not found";
1749 QTRY_COMPARE(item->x(), qreal(-(i/5)*80-item->width()));
1750 QTRY_COMPARE(item->y(), qreal((i%5)*60));
1754 gridview->positionViewAtIndex(30, QSGGridView::End);
1755 QTRY_COMPARE(gridview->contentX(), -560.);
1757 // Position in Center
1758 gridview->positionViewAtIndex(15, QSGGridView::Center);
1759 QTRY_COMPARE(gridview->contentX(), -400.);
1761 // Ensure at least partially visible
1762 gridview->positionViewAtIndex(15, QSGGridView::Visible);
1763 QTRY_COMPARE(gridview->contentX(), -400.);
1765 gridview->setContentX(-555.);
1766 gridview->positionViewAtIndex(15, QSGGridView::Visible);
1767 QTRY_COMPARE(gridview->contentX(), -555.);
1769 gridview->setContentX(-239);
1770 gridview->positionViewAtIndex(15, QSGGridView::Visible);
1771 QTRY_COMPARE(gridview->contentX(), -320.);
1773 gridview->setContentX(-239);
1774 gridview->positionViewAtIndex(20, QSGGridView::Visible);
1775 QTRY_COMPARE(gridview->contentX(), -400.);
1777 gridview->setContentX(-640);
1778 gridview->positionViewAtIndex(20, QSGGridView::Visible);
1779 QTRY_COMPARE(gridview->contentX(), -560.);
1781 // Ensure completely visible
1782 gridview->setContentX(-400);
1783 gridview->positionViewAtIndex(20, QSGGridView::Contain);
1784 QTRY_COMPARE(gridview->contentX(), -400.);
1786 gridview->setContentX(-315);
1787 gridview->positionViewAtIndex(15, QSGGridView::Contain);
1788 QTRY_COMPARE(gridview->contentX(), -320.);
1790 gridview->setContentX(-640);
1791 gridview->positionViewAtIndex(20, QSGGridView::Contain);
1792 QTRY_COMPARE(gridview->contentX(), -560.);
1797 void tst_QSGGridView::resetModel()
1799 QSGView *canvas = createView();
1801 QStringList strings;
1802 strings << "one" << "two" << "three";
1803 QStringListModel model(strings);
1805 QDeclarativeContext *ctxt = canvas->rootContext();
1806 ctxt->setContextProperty("testModel", &model);
1808 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/displaygrid.qml"));
1809 qApp->processEvents();
1811 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1812 QTRY_VERIFY(gridview != 0);
1814 QSGItem *contentItem = gridview->contentItem();
1815 QTRY_VERIFY(contentItem != 0);
1817 QTRY_COMPARE(gridview->count(), model.rowCount());
1819 for (int i = 0; i < model.rowCount(); ++i) {
1820 QSGText *display = findItem<QSGText>(contentItem, "displayText", i);
1821 QTRY_VERIFY(display != 0);
1822 QTRY_COMPARE(display->text(), strings.at(i));
1826 strings << "four" << "five" << "six" << "seven";
1827 model.setStringList(strings);
1829 QTRY_COMPARE(gridview->count(), model.rowCount());
1831 for (int i = 0; i < model.rowCount(); ++i) {
1832 QSGText *display = findItem<QSGText>(contentItem, "displayText", i);
1833 QTRY_VERIFY(display != 0);
1834 QTRY_COMPARE(display->text(), strings.at(i));
1840 void tst_QSGGridView::enforceRange()
1842 QSGView *canvas = createView();
1845 for (int i = 0; i < 30; i++)
1846 model.addItem("Item" + QString::number(i), "");
1848 QDeclarativeContext *ctxt = canvas->rootContext();
1849 ctxt->setContextProperty("testModel", &model);
1850 ctxt->setContextProperty("testRightToLeft", QVariant(false));
1851 ctxt->setContextProperty("testTopToBottom", QVariant(false));
1853 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview-enforcerange.qml"));
1854 qApp->processEvents();
1855 QVERIFY(canvas->rootObject() != 0);
1857 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1858 QTRY_VERIFY(gridview != 0);
1860 QTRY_COMPARE(gridview->preferredHighlightBegin(), 100.0);
1861 QTRY_COMPARE(gridview->preferredHighlightEnd(), 100.0);
1862 QTRY_COMPARE(gridview->highlightRangeMode(), QSGGridView::StrictlyEnforceRange);
1864 QSGItem *contentItem = gridview->contentItem();
1865 QTRY_VERIFY(contentItem != 0);
1867 // view should be positioned at the top of the range.
1868 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", 0);
1870 QTRY_COMPARE(gridview->contentY(), -100.0);
1872 QSGText *name = findItem<QSGText>(contentItem, "textName", 0);
1873 QTRY_VERIFY(name != 0);
1874 QTRY_COMPARE(name->text(), model.name(0));
1875 QSGText *number = findItem<QSGText>(contentItem, "textNumber", 0);
1876 QTRY_VERIFY(number != 0);
1877 QTRY_COMPARE(number->text(), model.number(0));
1879 // Check currentIndex is updated when contentItem moves
1880 gridview->setContentY(0);
1881 QTRY_COMPARE(gridview->currentIndex(), 2);
1883 gridview->setCurrentIndex(5);
1884 QTRY_COMPARE(gridview->contentY(), 100.);
1887 for (int i = 0; i < 5; i++)
1888 model2.addItem("Item" + QString::number(i), "");
1890 ctxt->setContextProperty("testModel", &model2);
1891 QCOMPARE(gridview->count(), 5);
1896 void tst_QSGGridView::enforceRange_rightToLeft()
1898 QSGView *canvas = createView();
1901 for (int i = 0; i < 30; i++)
1902 model.addItem("Item" + QString::number(i), "");
1904 QDeclarativeContext *ctxt = canvas->rootContext();
1905 ctxt->setContextProperty("testModel", &model);
1906 ctxt->setContextProperty("testRightToLeft", QVariant(true));
1907 ctxt->setContextProperty("testTopToBottom", QVariant(true));
1909 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview-enforcerange.qml"));
1910 qApp->processEvents();
1911 QVERIFY(canvas->rootObject() != 0);
1913 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1914 QTRY_VERIFY(gridview != 0);
1916 QTRY_COMPARE(gridview->preferredHighlightBegin(), 100.0);
1917 QTRY_COMPARE(gridview->preferredHighlightEnd(), 100.0);
1918 QTRY_COMPARE(gridview->highlightRangeMode(), QSGGridView::StrictlyEnforceRange);
1920 QSGItem *contentItem = gridview->contentItem();
1921 QTRY_VERIFY(contentItem != 0);
1923 // view should be positioned at the top of the range.
1924 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", 0);
1926 QTRY_COMPARE(gridview->contentX(), -100.);
1927 QTRY_COMPARE(gridview->contentY(), 0.0);
1929 QSGText *name = findItem<QSGText>(contentItem, "textName", 0);
1930 QTRY_VERIFY(name != 0);
1931 QTRY_COMPARE(name->text(), model.name(0));
1932 QSGText *number = findItem<QSGText>(contentItem, "textNumber", 0);
1933 QTRY_VERIFY(number != 0);
1934 QTRY_COMPARE(number->text(), model.number(0));
1936 // Check currentIndex is updated when contentItem moves
1937 gridview->setContentX(-200);
1938 QTRY_COMPARE(gridview->currentIndex(), 3);
1940 gridview->setCurrentIndex(7);
1941 QTRY_COMPARE(gridview->contentX(), -300.);
1942 QTRY_COMPARE(gridview->contentY(), 0.0);
1945 for (int i = 0; i < 5; i++)
1946 model2.addItem("Item" + QString::number(i), "");
1948 ctxt->setContextProperty("testModel", &model2);
1949 QCOMPARE(gridview->count(), 5);
1954 void tst_QSGGridView::QTBUG_8456()
1956 QSGView *canvas = createView();
1958 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/setindex.qml"));
1959 qApp->processEvents();
1961 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1962 QTRY_VERIFY(gridview != 0);
1964 QTRY_COMPARE(gridview->currentIndex(), 0);
1969 void tst_QSGGridView::manualHighlight()
1971 QSGView *canvas = createView();
1973 QString filename(SRCDIR "/data/manual-highlight.qml");
1974 canvas->setSource(QUrl::fromLocalFile(filename));
1976 qApp->processEvents();
1978 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
1979 QTRY_VERIFY(gridview != 0);
1981 QSGItem *contentItem = gridview->contentItem();
1982 QTRY_VERIFY(contentItem != 0);
1984 QTRY_COMPARE(gridview->currentIndex(), 0);
1985 QTRY_COMPARE(gridview->currentItem(), findItem<QSGItem>(contentItem, "wrapper", 0));
1986 QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y());
1987 QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x());
1989 gridview->setCurrentIndex(2);
1991 QTRY_COMPARE(gridview->currentIndex(), 2);
1992 QTRY_COMPARE(gridview->currentItem(), findItem<QSGItem>(contentItem, "wrapper", 2));
1993 QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y());
1994 QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x());
1996 gridview->positionViewAtIndex(8, QSGGridView::Contain);
1998 QTRY_COMPARE(gridview->currentIndex(), 2);
1999 QTRY_COMPARE(gridview->currentItem(), findItem<QSGItem>(contentItem, "wrapper", 2));
2000 QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y());
2001 QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x());
2003 gridview->setFlow(QSGGridView::TopToBottom);
2004 QTRY_COMPARE(gridview->flow(), QSGGridView::TopToBottom);
2006 gridview->setCurrentIndex(0);
2007 QTRY_COMPARE(gridview->currentIndex(), 0);
2008 QTRY_COMPARE(gridview->currentItem(), findItem<QSGItem>(contentItem, "wrapper", 0));
2009 QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y());
2010 QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x());
2016 void tst_QSGGridView::footer()
2018 QFETCH(QSGGridView::Flow, flow);
2019 QFETCH(Qt::LayoutDirection, layoutDirection);
2020 QFETCH(QPointF, initialFooterPos);
2021 QFETCH(QPointF, changedFooterPos);
2022 QFETCH(QPointF, initialContentPos);
2023 QFETCH(QPointF, changedContentPos);
2024 QFETCH(QPointF, firstDelegatePos);
2026 QSGView *canvas = createView();
2030 for (int i = 0; i < 7; i++)
2031 model.addItem("Item" + QString::number(i), "");
2033 QDeclarativeContext *ctxt = canvas->rootContext();
2034 ctxt->setContextProperty("testModel", &model);
2036 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/footer.qml"));
2037 qApp->processEvents();
2039 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
2040 QTRY_VERIFY(gridview != 0);
2041 gridview->setFlow(flow);
2042 gridview->setLayoutDirection(layoutDirection);
2044 QSGItem *contentItem = gridview->contentItem();
2045 QTRY_VERIFY(contentItem != 0);
2047 QSGText *footer = findItem<QSGText>(contentItem, "footer");
2050 QVERIFY(footer == gridview->footerItem());
2052 QCOMPARE(footer->pos(), initialFooterPos);
2053 QCOMPARE(footer->width(), 100.);
2054 QCOMPARE(footer->height(), 30.);
2055 QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
2057 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", 0);
2059 QCOMPARE(item->pos(), firstDelegatePos);
2061 if (flow == QSGGridView::LeftToRight) {
2062 // shrink by one row
2063 model.removeItem(2);
2064 QTRY_COMPARE(footer->y(), initialFooterPos.y() - gridview->cellHeight());
2066 // shrink by one column
2067 model.removeItem(2);
2068 model.removeItem(3);
2069 if (layoutDirection == Qt::LeftToRight)
2070 QTRY_COMPARE(footer->x(), initialFooterPos.x() - gridview->cellWidth());
2072 QTRY_COMPARE(footer->x(), initialFooterPos.x() + gridview->cellWidth());
2078 QPointF posWhenNoItems(0, 0);
2079 if (layoutDirection == Qt::RightToLeft)
2080 posWhenNoItems.setX(flow == QSGGridView::LeftToRight ? gridview->width() - footer->width() : -footer->width());
2081 QTRY_COMPARE(footer->pos(), posWhenNoItems);
2083 // if header is present, it's at a negative pos, so the footer should not move
2084 canvas->rootObject()->setProperty("showHeader", true);
2085 QVERIFY(findItem<QSGItem>(contentItem, "header") != 0);
2086 QTRY_COMPARE(footer->pos(), posWhenNoItems);
2087 canvas->rootObject()->setProperty("showHeader", false);
2090 for (int i = 0; i < 30; i++)
2091 model.addItem("Item" + QString::number(i), "");
2093 QSignalSpy footerItemSpy(gridview, SIGNAL(footerItemChanged()));
2094 QMetaObject::invokeMethod(canvas->rootObject(), "changeFooter");
2096 QCOMPARE(footerItemSpy.count(), 1);
2098 footer = findItem<QSGText>(contentItem, "footer");
2100 footer = findItem<QSGText>(contentItem, "footer2");
2103 QVERIFY(footer == gridview->footerItem());
2105 QCOMPARE(footer->pos(), changedFooterPos);
2106 QCOMPARE(footer->width(), 50.);
2107 QCOMPARE(footer->height(), 20.);
2108 QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), changedContentPos);
2110 item = findItem<QSGItem>(contentItem, "wrapper", 0);
2112 QCOMPARE(item->pos(), firstDelegatePos);
2117 void tst_QSGGridView::footer_data()
2119 QTest::addColumn<QSGGridView::Flow>("flow");
2120 QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
2121 QTest::addColumn<QPointF>("initialFooterPos");
2122 QTest::addColumn<QPointF>("changedFooterPos");
2123 QTest::addColumn<QPointF>("initialContentPos");
2124 QTest::addColumn<QPointF>("changedContentPos");
2125 QTest::addColumn<QPointF>("firstDelegatePos");
2127 // footer1 = 100 x 30
2128 // footer2 = 100 x 20
2132 // footer below items, bottom left
2133 QTest::newRow("flow left to right") << QSGGridView::LeftToRight << Qt::LeftToRight
2134 << QPointF(0, 3 * 60) // 180 = height of 3 rows (cell height is 60)
2135 << QPointF(0, 10 * 60) // 30 items = 10 rows
2140 // footer below items, bottom right
2141 QTest::newRow("flow left to right, layout right to left") << QSGGridView::LeftToRight << Qt::RightToLeft
2142 << QPointF(240 - 100, 3 * 60)
2143 << QPointF((240 - 100) + 50, 10 * 60) // 50 = width diff between old and new footers
2146 << QPointF(240 - 80, 0);
2148 // footer to right of items
2149 QTest::newRow("flow top to bottom, layout left to right") << QSGGridView::TopToBottom << Qt::LeftToRight
2150 << QPointF(2 * 80, 0) // 2 columns, cell width 80
2151 << QPointF(6 * 80, 0) // 30 items = 6 columns
2156 // footer to left of items
2157 QTest::newRow("flow top to bottom, layout right to left") << QSGGridView::TopToBottom << Qt::RightToLeft
2158 << QPointF(-(2 * 80) - 100, 0)
2159 << QPointF(-(6 * 80) - 50, 0) // 50 = new footer width
2161 << QPointF(-240, 0) // unchanged, footer change doesn't change content pos
2165 void tst_QSGGridView::header()
2167 QFETCH(QSGGridView::Flow, flow);
2168 QFETCH(Qt::LayoutDirection, layoutDirection);
2169 QFETCH(QPointF, initialHeaderPos);
2170 QFETCH(QPointF, changedHeaderPos);
2171 QFETCH(QPointF, initialContentPos);
2172 QFETCH(QPointF, changedContentPos);
2173 QFETCH(QPointF, firstDelegatePos);
2175 QSGView *canvas = createView();
2178 for (int i = 0; i < 30; i++)
2179 model.addItem("Item" + QString::number(i), "");
2181 QDeclarativeContext *ctxt = canvas->rootContext();
2182 ctxt->setContextProperty("testModel", &model);
2184 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header.qml"));
2185 qApp->processEvents();
2187 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
2188 QTRY_VERIFY(gridview != 0);
2189 gridview->setFlow(flow);
2190 gridview->setLayoutDirection(layoutDirection);
2192 QSGItem *contentItem = gridview->contentItem();
2193 QTRY_VERIFY(contentItem != 0);
2195 QSGText *header = findItem<QSGText>(contentItem, "header");
2198 QVERIFY(header == gridview->headerItem());
2200 QCOMPARE(header->pos(), initialHeaderPos);
2201 QCOMPARE(header->width(), 100.);
2202 QCOMPARE(header->height(), 30.);
2203 QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
2205 QSGItem *item = findItem<QSGItem>(contentItem, "wrapper", 0);
2207 QCOMPARE(item->pos(), firstDelegatePos);
2210 QCOMPARE(header->pos(), initialHeaderPos); // header should stay where it is
2212 for (int i = 0; i < 30; i++)
2213 model.addItem("Item" + QString::number(i), "");
2215 QSignalSpy headerItemSpy(gridview, SIGNAL(headerItemChanged()));
2216 QMetaObject::invokeMethod(canvas->rootObject(), "changeHeader");
2218 QCOMPARE(headerItemSpy.count(), 1);
2220 header = findItem<QSGText>(contentItem, "header");
2222 header = findItem<QSGText>(contentItem, "header2");
2225 QVERIFY(header == gridview->headerItem());
2227 QCOMPARE(header->pos(), changedHeaderPos);
2228 QCOMPARE(header->width(), 50.);
2229 QCOMPARE(header->height(), 20.);
2230 QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), changedContentPos);
2232 item = findItem<QSGItem>(contentItem, "wrapper", 0);
2234 QCOMPARE(item->pos(), firstDelegatePos);
2239 void tst_QSGGridView::header_data()
2241 QTest::addColumn<QSGGridView::Flow>("flow");
2242 QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
2243 QTest::addColumn<QPointF>("initialHeaderPos");
2244 QTest::addColumn<QPointF>("changedHeaderPos");
2245 QTest::addColumn<QPointF>("initialContentPos");
2246 QTest::addColumn<QPointF>("changedContentPos");
2247 QTest::addColumn<QPointF>("firstDelegatePos");
2249 // header1 = 100 x 30
2250 // header2 = 100 x 20
2254 // header above items, top left
2255 QTest::newRow("flow left to right") << QSGGridView::LeftToRight << Qt::LeftToRight
2262 // header above items, top right
2263 QTest::newRow("flow left to right, layout right to left") << QSGGridView::LeftToRight << Qt::RightToLeft
2264 << QPointF(240 - 100, -30)
2265 << QPointF((240 - 100) + 50, -20) // 50 = width diff between old and new headers
2270 // header to left of items
2271 QTest::newRow("flow top to bottom, layout left to right") << QSGGridView::TopToBottom << Qt::LeftToRight
2278 // header to right of items
2279 QTest::newRow("flow top to bottom, layout right to left") << QSGGridView::TopToBottom << Qt::RightToLeft
2282 << QPointF(-(240 - 100), 0)
2283 << QPointF(-(240 - 50), 0)
2287 void tst_QSGGridView::indexAt()
2289 QSGView *canvas = createView();
2292 model.addItem("Fred", "12345");
2293 model.addItem("John", "2345");
2294 model.addItem("Bob", "54321");
2295 model.addItem("Billy", "22345");
2296 model.addItem("Sam", "2945");
2297 model.addItem("Ben", "04321");
2298 model.addItem("Jim", "0780");
2300 QDeclarativeContext *ctxt = canvas->rootContext();
2301 ctxt->setContextProperty("testModel", &model);
2302 ctxt->setContextProperty("testRightToLeft", QVariant(false));
2303 ctxt->setContextProperty("testTopToBottom", QVariant(false));
2305 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
2306 qApp->processEvents();
2308 QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
2309 QTRY_VERIFY(gridview != 0);
2311 QSGItem *contentItem = gridview->contentItem();
2312 QTRY_VERIFY(contentItem != 0);
2314 QTRY_COMPARE(gridview->count(), model.count());
2316 QCOMPARE(gridview->indexAt(0, 0), 0);
2317 QCOMPARE(gridview->indexAt(79, 59), 0);
2318 QCOMPARE(gridview->indexAt(80, 0), 1);
2319 QCOMPARE(gridview->indexAt(0, 60), 3);
2320 QCOMPARE(gridview->indexAt(240, 0), -1);
2325 void tst_QSGGridView::onAdd()
2327 QFETCH(int, initialItemCount);
2328 QFETCH(int, itemsToAdd);
2330 const int delegateWidth = 50;
2331 const int delegateHeight = 100;
2333 QSGView *canvas = createView();
2334 canvas->setFixedSize(5 * delegateWidth, 5 * delegateHeight); // just ensure all items fit
2336 // these initial items should not trigger GridView.onAdd
2337 for (int i=0; i<initialItemCount; i++)
2338 model.addItem("dummy value", "dummy value");
2340 QDeclarativeContext *ctxt = canvas->rootContext();
2341 ctxt->setContextProperty("testModel", &model);
2342 ctxt->setContextProperty("delegateWidth", delegateWidth);
2343 ctxt->setContextProperty("delegateHeight", delegateHeight);
2344 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/attachedSignals.qml"));
2346 QObject *object = canvas->rootObject();
2347 object->setProperty("width", canvas->width());
2348 object->setProperty("height", canvas->height());
2349 qApp->processEvents();
2351 QList<QPair<QString, QString> > items;
2352 for (int i=0; i<itemsToAdd; i++)
2353 items << qMakePair(QString("value %1").arg(i), QString::number(i));
2354 model.addItems(items);
2356 qApp->processEvents();
2358 QVariantList result = object->property("addedDelegates").toList();
2359 QCOMPARE(result.count(), items.count());
2360 for (int i=0; i<items.count(); i++)
2361 QCOMPARE(result[i].toString(), items[i].first);
2366 void tst_QSGGridView::onAdd_data()
2368 QTest::addColumn<int>("initialItemCount");
2369 QTest::addColumn<int>("itemsToAdd");
2371 QTest::newRow("0, add 1") << 0 << 1;
2372 QTest::newRow("0, add 2") << 0 << 2;
2373 QTest::newRow("0, add 10") << 0 << 10;
2375 QTest::newRow("1, add 1") << 1 << 1;
2376 QTest::newRow("1, add 2") << 1 << 2;
2377 QTest::newRow("1, add 10") << 1 << 10;
2379 QTest::newRow("5, add 1") << 5 << 1;
2380 QTest::newRow("5, add 2") << 5 << 2;
2381 QTest::newRow("5, add 10") << 5 << 10;
2384 void tst_QSGGridView::onRemove()
2386 QFETCH(int, initialItemCount);
2387 QFETCH(int, indexToRemove);
2388 QFETCH(int, removeCount);
2390 const int delegateWidth = 50;
2391 const int delegateHeight = 100;
2393 for (int i=0; i<initialItemCount; i++)
2394 model.addItem(QString("value %1").arg(i), "dummy value");
2396 QSGView *canvas = createView();
2397 QDeclarativeContext *ctxt = canvas->rootContext();
2398 ctxt->setContextProperty("testModel", &model);
2399 ctxt->setContextProperty("delegateWidth", delegateWidth);
2400 ctxt->setContextProperty("delegateHeight", delegateHeight);
2401 canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/attachedSignals.qml"));
2402 QObject *object = canvas->rootObject();
2404 qApp->processEvents();
2406 model.removeItems(indexToRemove, removeCount);
2407 qApp->processEvents();
2408 QCOMPARE(object->property("removedDelegateCount"), QVariant(removeCount));
2413 void tst_QSGGridView::onRemove_data()
2415 QTest::addColumn<int>("initialItemCount");
2416 QTest::addColumn<int>("indexToRemove");
2417 QTest::addColumn<int>("removeCount");
2419 QTest::newRow("remove first") << 1 << 0 << 1;
2420 QTest::newRow("two items, remove first") << 2 << 0 << 1;
2421 QTest::newRow("two items, remove last") << 2 << 1 << 1;
2422 QTest::newRow("two items, remove all") << 2 << 0 << 2;
2424 QTest::newRow("four items, remove first") << 4 << 0 << 1;
2425 QTest::newRow("four items, remove 0-2") << 4 << 0 << 2;
2426 QTest::newRow("four items, remove 1-3") << 4 << 1 << 2;
2427 QTest::newRow("four items, remove 2-4") << 4 << 2 << 2;
2428 QTest::newRow("four items, remove last") << 4 << 3 << 1;
2429 QTest::newRow("four items, remove all") << 4 << 0 << 4;
2431 QTest::newRow("ten items, remove 1-8") << 10 << 0 << 8;
2432 QTest::newRow("ten items, remove 2-7") << 10 << 2 << 5;
2433 QTest::newRow("ten items, remove 4-10") << 10 << 4 << 6;
2436 void tst_QSGGridView::testQtQuick11Attributes()
2438 QFETCH(QString, code);
2439 QFETCH(QString, warning);
2440 QFETCH(QString, error);
2442 QDeclarativeEngine engine;
2445 QDeclarativeComponent valid(&engine);
2446 valid.setData("import QtQuick 1.1; GridView { " + code.toUtf8() + " }", QUrl(""));
2447 obj = valid.create();
2449 QVERIFY(valid.errorString().isEmpty());
2452 QDeclarativeComponent invalid(&engine);
2453 invalid.setData("import QtQuick 1.0; GridView { " + code.toUtf8() + " }", QUrl(""));
2454 QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
2455 obj = invalid.create();
2456 QCOMPARE(invalid.errorString(), error);
2460 void tst_QSGGridView::testQtQuick11Attributes_data()
2462 QTest::addColumn<QString>("code");
2463 QTest::addColumn<QString>("warning");
2464 QTest::addColumn<QString>("error");
2466 QTest::newRow("positionViewAtBeginning") << "Component.onCompleted: positionViewAtBeginning()"
2467 << "<Unknown File>:1: ReferenceError: Can't find variable: positionViewAtBeginning"
2470 QTest::newRow("positionViewAtEnd") << "Component.onCompleted: positionViewAtEnd()"
2471 << "<Unknown File>:1: ReferenceError: Can't find variable: positionViewAtEnd"
2475 QSGView *tst_QSGGridView::createView()
2477 QSGView *canvas = new QSGView(0);
2478 canvas->setFixedSize(240,320);
2484 Find an item with the specified objectName. If index is supplied then the
2485 item must also evaluate the {index} expression equal to index
2487 template<typename T>
2488 T *tst_QSGGridView::findItem(QSGItem *parent, const QString &objectName, int index)
2490 const QMetaObject &mo = T::staticMetaObject;
2491 //qDebug() << parent->childItems().count() << "children";
2492 for (int i = 0; i < parent->childItems().count(); ++i) {
2493 QSGItem *item = qobject_cast<QSGItem*>(parent->childItems().at(i));
2496 //qDebug() << "try" << item;
2497 if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
2499 QDeclarativeContext *context = QDeclarativeEngine::contextForObject(item);
2501 if (context->contextProperty("index").toInt() == index) {
2502 return static_cast<T*>(item);
2506 return static_cast<T*>(item);
2509 item = findItem<T>(item, objectName, index);
2511 return static_cast<T*>(item);
2517 template<typename T>
2518 QList<T*> tst_QSGGridView::findItems(QSGItem *parent, const QString &objectName)
2521 const QMetaObject &mo = T::staticMetaObject;
2522 //qDebug() << parent->childItems().count() << "children";
2523 for (int i = 0; i < parent->childItems().count(); ++i) {
2524 QSGItem *item = qobject_cast<QSGItem*>(parent->childItems().at(i));
2527 //qDebug() << "try" << item;
2528 if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
2529 items.append(static_cast<T*>(item));
2530 //qDebug() << " found:" << item;
2532 items += findItems<T>(item, objectName);
2538 void tst_QSGGridView::dumpTree(QSGItem *parent, int depth)
2540 static QString padding(" ");
2541 for (int i = 0; i < parent->childItems().count(); ++i) {
2542 QSGItem *item = qobject_cast<QSGItem*>(parent->childItems().at(i));
2545 QDeclarativeContext *context = QDeclarativeEngine::contextForObject(item);
2546 qDebug() << padding.left(depth*2) << item << (context ? context->contextProperty("index").toInt() : -1);
2547 dumpTree(item, depth+1);
2552 QTEST_MAIN(tst_QSGGridView)
2554 #include "tst_qsggridview.moc"