QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquickgridview / tst_qquickgridview.cpp
index 0171872..bb10d53 100644 (file)
@@ -47,6 +47,7 @@
 #include <QtQml/qqmlcontext.h>
 #include <QtQml/qqmlexpression.h>
 #include <QtQml/qqmlincubator.h>
+#include <QtQml/qqmlcontext.h>
 #include <QtQuick/private/qquickitem_p.h>
 #include <QtQuick/private/qquickgridview_p.h>
 #include <QtQuick/private/qquicktext_p.h>
 #include "../shared/viewtestutil.h"
 #include "../shared/visualtestutil.h"
 #include <QtGui/qguiapplication.h>
+#include "qplatformdefs.h"
 
-Q_DECLARE_METATYPE(Qt::LayoutDirection)
 Q_DECLARE_METATYPE(QQuickGridView::Flow)
+Q_DECLARE_METATYPE(Qt::LayoutDirection)
+Q_DECLARE_METATYPE(QQuickItemView::VerticalLayoutDirection)
+Q_DECLARE_METATYPE(Qt::Key)
 
 using namespace QQuickViewTestUtil;
 using namespace QQuickVisualTestUtil;
 
+#define SHARE_VIEWS
+
 class tst_QQuickGridView : public QQmlDataTest
 {
     Q_OBJECT
@@ -71,27 +77,33 @@ public:
     tst_QQuickGridView();
 
 private slots:
+    void init();
+    void cleanupTestCase();
     void items();
     void changed();
-    void inserted();
-    void inserted_more();
-    void inserted_more_data();
+    void inserted_basic();
+    void inserted_defaultLayout(QQuickGridView::Flow flow = QQuickGridView::FlowLeftToRight, Qt::LayoutDirection horizLayout = Qt::LeftToRight, QQuickItemView::VerticalLayoutDirection verticalLayout = QQuickItemView::TopToBottom);
+    void inserted_defaultLayout_data();
     void insertBeforeVisible();
     void insertBeforeVisible_data();
-    void removed();
-    void removed_more();
-    void removed_more_data();
+    void removed_basic();
+    void removed_defaultLayout(QQuickGridView::Flow flow = QQuickGridView::FlowLeftToRight, Qt::LayoutDirection horizLayout = Qt::LeftToRight, QQuickItemView::VerticalLayoutDirection verticalLayout = QQuickItemView::TopToBottom);
+    void removed_defaultLayout_data();
     void addOrRemoveBeforeVisible();
     void addOrRemoveBeforeVisible_data();
     void clear();
-    void moved();
-    void moved_data();
-    void multipleChanges();
-    void multipleChanges_data();
+    void moved_defaultLayout(QQuickGridView::Flow flow = QQuickGridView::FlowLeftToRight, Qt::LayoutDirection horizLayout = Qt::LeftToRight, QQuickItemView::VerticalLayoutDirection verticalLayout = QQuickItemView::TopToBottom);
+    void moved_defaultLayout_data();
+    void multipleChanges_condensed() { multipleChanges(true); }
+    void multipleChanges_condensed_data() { multipleChanges_data(); }
+    void multipleChanges_uncondensed() { multipleChanges(false); }
+    void multipleChanges_uncondensed_data() { multipleChanges_data(); }
     void swapWithFirstItem();
     void changeFlow();
     void currentIndex();
     void noCurrentIndex();
+    void keyNavigation();
+    void keyNavigation_data();
     void defaultValues();
     void properties();
     void propertyChanges();
@@ -108,9 +120,15 @@ private slots:
     void manualHighlight();
     void footer();
     void footer_data();
+    void initialZValues();
     void header();
     void header_data();
+    void extents();
+    void extents_data();
+    void resetModel_headerFooter();
     void resizeViewAndRepaint();
+    void resizeGrid();
+    void resizeGrid_data();
     void changeColumnCount();
     void indexAt_itemAt_data();
     void indexAt_itemAt();
@@ -142,21 +160,179 @@ private slots:
     void displacedTransitions_data();
     void multipleTransitions();
     void multipleTransitions_data();
+    void multipleDisplaced();
+
+    void inserted_leftToRight_RtL_TtB();
+    void inserted_leftToRight_RtL_TtB_data();
+    void inserted_leftToRight_LtR_BtT();
+    void inserted_leftToRight_LtR_BtT_data();
+    void inserted_leftToRight_RtL_BtT();
+    void inserted_leftToRight_RtL_BtT_data();
+    void inserted_topToBottom_LtR_TtB();
+    void inserted_topToBottom_LtR_TtB_data();
+    void inserted_topToBottom_RtL_TtB();
+    void inserted_topToBottom_RtL_TtB_data();
+    void inserted_topToBottom_LtR_BtT();
+    void inserted_topToBottom_LtR_BtT_data();
+    void inserted_topToBottom_RtL_BtT();
+    void inserted_topToBottom_RtL_BtT_data();
+
+    void removed_leftToRight_RtL_TtB();
+    void removed_leftToRight_RtL_TtB_data();
+    void removed_leftToRight_LtR_BtT();
+    void removed_leftToRight_LtR_BtT_data();
+    void removed_leftToRight_RtL_BtT();
+    void removed_leftToRight_RtL_BtT_data();
+    void removed_topToBottom_LtR_TtB();
+    void removed_topToBottom_LtR_TtB_data();
+    void removed_topToBottom_RtL_TtB();
+    void removed_topToBottom_RtL_TtB_data();
+    void removed_topToBottom_LtR_BtT();
+    void removed_topToBottom_LtR_BtT_data();
+    void removed_topToBottom_RtL_BtT();
+    void removed_topToBottom_RtL_BtT_data();
+
+    void moved_leftToRight_RtL_TtB();
+    void moved_leftToRight_RtL_TtB_data();
+    void moved_leftToRight_LtR_BtT();
+    void moved_leftToRight_LtR_BtT_data();
+    void moved_leftToRight_RtL_BtT();
+    void moved_leftToRight_RtL_BtT_data();
+    void moved_topToBottom_LtR_TtB();
+    void moved_topToBottom_LtR_TtB_data();
+    void moved_topToBottom_RtL_TtB();
+    void moved_topToBottom_RtL_TtB_data();
+    void moved_topToBottom_LtR_BtT();
+    void moved_topToBottom_LtR_BtT_data();
+    void moved_topToBottom_RtL_BtT();
+    void moved_topToBottom_RtL_BtT_data();
 
 private:
     QList<int> toIntList(const QVariantList &list);
     void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes);
     void matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes);
     void matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems);
+
+    void multipleChanges(bool condensed);
+    void multipleChanges_data();
+
+    QPointF expectedItemPos(QQuickGridView *grid, int index, qreal rowOffset = 0) {
+        qreal x;
+        qreal y;
+        if (grid->flow() == QQuickGridView::FlowLeftToRight) {
+            int columns = grid->width() / grid->cellWidth();
+            x = (index % columns) * grid->cellWidth();
+            y = (index / columns) * grid->cellHeight();
+            if (grid->effectiveLayoutDirection() == Qt::RightToLeft) {
+                int col = (index % columns) * grid->cellWidth();
+                x = grid->cellWidth() * (columns - 1) - col;
+            }
+
+            qreal offset = grid->cellHeight() * rowOffset;
+            if (grid->verticalLayoutDirection() == QQuickItemView::TopToBottom)
+                y += offset;
+            else
+                y = -grid->cellHeight() - y - offset;
+        } else {
+            int rows = grid->height() / grid->cellHeight();
+            x = (index / rows) * grid->cellWidth();
+            y = (index % rows) * grid->cellHeight();
+            if (grid->effectiveLayoutDirection() == Qt::RightToLeft)
+                x = -x - grid->cellWidth();
+
+            qreal offset = grid->cellWidth() * rowOffset;
+            if (grid->effectiveLayoutDirection() == Qt::RightToLeft)
+                x -= offset;
+            else
+                x += offset;
+            if (grid->verticalLayoutDirection() == QQuickItemView::BottomToTop)
+                y = -grid->cellHeight() - y;
+        }
+        return QPointF(x, y);
+    }
+
+    // Sets contentY (or contentX in TopToBottom flow) according to given row offset
+    // (in LeftToRight flow) or col offset (in TopToBottom).
+    bool setContentPos(QQuickGridView *gridview, qreal rowOrColOffset) {
+        bool contentPosChanged = (rowOrColOffset != 0);
+        qreal contentOffset = gridview->flow() == QQuickGridView::FlowLeftToRight
+                ? rowOrColOffset * gridview->cellHeight()
+                : rowOrColOffset * gridview->cellWidth();
+
+        if (gridview->flow() == QQuickGridView::FlowLeftToRight) {
+            if (gridview->verticalLayoutDirection() == QQuickItemView::BottomToTop)
+                contentOffset = -gridview->height() - contentOffset;
+        } else {
+            if (gridview->effectiveLayoutDirection() == Qt::RightToLeft)
+                contentOffset = -gridview->width() - contentOffset;
+        }
+        if (gridview->flow() == QQuickGridView::FlowLeftToRight)
+            gridview->setContentY(contentOffset);
+        else
+            gridview->setContentX(contentOffset);
+        return contentPosChanged;
+    }
+
+#ifdef SHARE_VIEWS
+    QQuickView *getView() {
+        if (m_view) {
+            if (QString(QTest::currentTestFunction()) != testForView) {
+                delete m_view;
+                m_view = 0;
+            } else {
+                m_view->setSource(QUrl());
+                return m_view;
+            }
+        }
+
+        testForView = QTest::currentTestFunction();
+        m_view = createView();
+        return m_view;
+    }
+    void releaseView(QQuickView *view) {
+        Q_ASSERT(view == m_view);
+        m_view->setSource(QUrl());
+    }
+#else
+    QQuickView *getView() {
+        return createView();
+    }
+    void releaseView(QQuickView *view) {
+        delete view;
+    }
+#endif
+
+    QQuickView *m_view;
+    QString testForView;
 };
 
-tst_QQuickGridView::tst_QQuickGridView()
+tst_QQuickGridView::tst_QQuickGridView() : m_view(0)
 {
 }
 
+void tst_QQuickGridView::init()
+{
+#ifdef SHARE_VIEWS
+    if (m_view && QString(QTest::currentTestFunction()) != testForView) {
+        testForView = QString();
+        delete m_view;
+        m_view = 0;
+    }
+#endif
+}
+
+void tst_QQuickGridView::cleanupTestCase()
+{
+#ifdef SHARE_VIEWS
+    testForView = QString();
+    delete m_view;
+    m_view = 0;
+#endif
+}
+
 void tst_QQuickGridView::items()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     model.addItem("Fred", "12345");
@@ -167,22 +343,20 @@ void tst_QQuickGridView::items()
     model.addItem("Ben", "04321");
     model.addItem("Jim", "0780");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
 
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->setSource(testFileUrl("gridview1.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
 
     QTRY_COMPARE(gridview->count(), model.count());
-    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
+    QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count());
     QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
 
     for (int i = 0; i < model.count(); ++i) {
@@ -201,12 +375,12 @@ void tst_QQuickGridView::items()
     int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
     QTRY_VERIFY(itemCount == 0);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::changed()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     model.addItem("Fred", "12345");
@@ -217,15 +391,13 @@ void tst_QQuickGridView::changed()
     model.addItem("Ben", "04321");
     model.addItem("Jim", "0780");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
 
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->setSource(testFileUrl("gridview1.qml"));
     qApp->processEvents();
 
-    QQuickFlickable *gridview = findItem<QQuickFlickable>(canvas->rootObject(), "grid");
+    QQuickFlickable *gridview = findItem<QQuickFlickable>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -239,28 +411,24 @@ void tst_QQuickGridView::changed()
     QTRY_VERIFY(number != 0);
     QTRY_COMPARE(number->text(), model.number(1));
 
-    delete canvas;
+    delete window;
 }
 
-void tst_QQuickGridView::inserted()
+void tst_QQuickGridView::inserted_basic()
 {
-    QQuickView *canvas = createView();
-    canvas->show();
+    QQuickView *window = createView();
+    window->show();
 
     QaimModel model;
     model.addItem("Fred", "12345");
     model.addItem("John", "2345");
     model.addItem("Bob", "54321");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -268,7 +436,7 @@ void tst_QQuickGridView::inserted()
 
     model.insertItem(1, "Will", "9876");
 
-    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
+    QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count());
     QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
 
     QQuickText *name = findItem<QQuickText>(contentItem, "textName", 1);
@@ -279,7 +447,7 @@ void tst_QQuickGridView::inserted()
     QTRY_COMPARE(number->text(), model.number(1));
 
     // Checks that onAdd is called
-    int added = canvas->rootObject()->property("added").toInt();
+    int added = window->rootObject()->property("added").toInt();
     QTRY_COMPARE(added, 1);
 
     // Confirm items positioned correctly
@@ -319,37 +487,45 @@ void tst_QQuickGridView::inserted()
 
     QTRY_VERIFY(gridview->contentY() == 120);
 
-    delete canvas;
+    delete window;
 }
 
-void tst_QQuickGridView::inserted_more()
+void tst_QQuickGridView::inserted_defaultLayout(QQuickGridView::Flow flow,
+                                       Qt::LayoutDirection horizLayout,
+                                       QQuickItemView::VerticalLayoutDirection verticalLayout)
 {
-    QFETCH(qreal, contentY);
+    QFETCH(qreal, contentYRowOffset);
     QFETCH(int, insertIndex);
     QFETCH(int, insertCount);
-    QFETCH(qreal, itemsOffsetAfterMove);
+    QFETCH(int, insertIndex_ttb);
+    QFETCH(int, insertCount_ttb);
+    QFETCH(qreal, rowOffsetAfterMove);
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+    ctxt->setContextProperty("testRightToLeft", horizLayout == Qt::RightToLeft);
+    ctxt->setContextProperty("testBottomToTop", verticalLayout == QQuickGridView::BottomToTop);
+    window->setSource(testFileUrl("layouts.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
 
-    gridview->setContentY(contentY);
-    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+    if (flow == QQuickGridView::FlowTopToBottom) {
+        insertIndex = insertIndex_ttb;
+        insertCount = insertCount_ttb;
+    }
+    if (setContentPos(gridview, contentYRowOffset))
+        QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     QList<QPair<QString, QString> > newData;
     for (int i=0; i<insertCount; i++)
@@ -360,137 +536,152 @@ void tst_QQuickGridView::inserted_more()
     // check visibleItems.first() is in correct position
     QQuickItem *item0 = findItem<QQuickItem>(contentItem, "wrapper", 0);
     QVERIFY(item0);
-    QCOMPARE(item0->y(), 0.0);
+    QPointF firstPos(0, 0);
+    if (horizLayout == Qt::RightToLeft)
+        firstPos.rx() = flow == QQuickGridView::FlowLeftToRight ? gridview->width() - gridview->cellWidth() : -gridview->cellWidth();
+    if (verticalLayout == QQuickItemView::BottomToTop)
+        firstPos.ry() -= gridview->cellHeight();
+    QCOMPARE(item0->pos(), firstPos);
 
     QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
     int firstVisibleIndex = -1;
     for (int i=0; i<items.count(); i++) {
-        if (items[i]->y() >= contentY) {
-            QQmlExpression e(qmlContext(items[i]), items[i], "index");
-            firstVisibleIndex = e.evaluate().toInt();
+        QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+        if (item && delegateVisible(item)) {
+            firstVisibleIndex = i;
             break;
         }
     }
     QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
 
     // Confirm items positioned correctly and indexes correct
-    int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
-    QQuickText *name;
-    QQuickText *number;
-    for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+    for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
         QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
         QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
-
-        QCOMPARE(item->x(), (i%3)*80.0);
-        QCOMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
-
-        name = findItem<QQuickText>(contentItem, "textName", i);
+        QCOMPARE(item->pos(), expectedItemPos(gridview, i, rowOffsetAfterMove));
+        QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
         QVERIFY(name != 0);
         QCOMPARE(name->text(), model.name(i));
-        number = findItem<QQuickText>(contentItem, "textNumber", i);
-        QVERIFY(number != 0);
-        QCOMPARE(number->text(), model.number(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
-void tst_QQuickGridView::inserted_more_data()
+void tst_QQuickGridView::inserted_defaultLayout_data()
 {
-    QTest::addColumn<qreal>("contentY");
+    QTest::addColumn<qreal>("contentYRowOffset");
     QTest::addColumn<int>("insertIndex");
     QTest::addColumn<int>("insertCount");
-    QTest::addColumn<qreal>("itemsOffsetAfterMove");
+    QTest::addColumn<int>("insertIndex_ttb");
+    QTest::addColumn<int>("insertCount_ttb");
+    QTest::addColumn<qreal>("rowOffsetAfterMove");
 
     QTest::newRow("add 1, before visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 5 << 1
+               << 9 << 1
             << 0.0;   // insert 1 above first visible, grid is rearranged; first visible moves forward within its row
                       // new 1st visible item is at 0
 
     QTest::newRow("add 2, before visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 5 << 2
+               << 9 << 2
             << 0.0;   // insert 2 above first visible, grid is rearranged; first visible moves forward within its row
 
     QTest::newRow("add 3, before visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 5 << 3
-            << -60.0;   // insert 3 (1 row) above first visible in negative pos, first visible does not move
+               << 9 << 5
+            << -1.0;   // insert 3 (1 row) above first visible in negative pos, first visible does not move
 
     QTest::newRow("add 5, before visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 5 << 5
-            << -60.0;   // insert 1 row + 2 items above first visible, 1 row added at negative pos,
+               << 9 << 7
+            << -1.0;   // insert 1 row + 2 items above first visible, 1 row added at negative pos,
                         // grid is rearranged and first visible moves forward within its row
 
     QTest::newRow("add 6, before visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 5 << 6
-            << -60.0 * 2;   // insert 2 rows above first visible in negative pos, first visible does not move
+               << 9 << 10
+            << -1.0 * 2;   // insert 2 rows above first visible in negative pos, first visible does not move
 
 
 
    QTest::newRow("add 1, at start of visible, content at start")
             << 0.0
             << 0 << 1
+               << 0 << 1
             << 0.0;
 
     QTest::newRow("add multiple, at start of visible, content at start")
             << 0.0
             << 0 << 3
+               << 0 << 5
             << 0.0;
 
     QTest::newRow("add 1, at start of visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 6 << 1
+               << 10 << 1
             << 0.0;
 
     QTest::newRow("add multiple, at start of visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 6 << 3
+               << 10 << 5
             << 0.0;
 
 
     QTest::newRow("add 1, at end of visible, content at start")
             << 0.0
             << 17 << 1
+               << 14 << 1
             << 0.0;
 
-    QTest::newRow("add 1, at end of visible, content at start")
+    QTest::newRow("add row, at end of visible, content at start")
             << 0.0
             << 17 << 3
+               << 14 << 5
             << 0.0;
 
     QTest::newRow("add 1, at end of visible, content not at start")
-            << 120.0     // show 6-23
-            << 23 << 1
+            << 2.0     // show 6-23
+            << 17+6 << 1
+               << 14+10 << 1
             << 0.0;
 
     QTest::newRow("add multiple, at end of visible, content not at start")
-            << 120.0     // show 6-23
-            << 23 << 3
+            << 2.0     // show 6-23
+            << 17+6 << 3
+               << 14+10 << 5
             << 0.0;
 
 
     QTest::newRow("add 1, after visible, content at start")
             << 0.0
             << 20 << 1
+               << 18 << 1
             << 0.0;
 
-    QTest::newRow("add 1, after visible, content at start")
+    QTest::newRow("add row, after visible, content at start")
             << 0.0
             << 20 << 3
+               << 18 << 5
             << 0.0;
 
     QTest::newRow("add 1, after visible, content not at start")
-            << 120.0     // show 6-23
-            << 24 << 1
+            << 2.0     // show 6-23
+            << 20+6 << 1
+               << 18+10 << 1
             << 0.0;
 
     QTest::newRow("add multiple, after visible, content not at start")
-            << 120.0     // show 6-23
-            << 24 << 3
+            << 2.0     // show 6-23
+            << 20+6 << 3
+               << 18+10 << 3
             << 0.0;
 }
 
@@ -501,21 +692,19 @@ void tst_QQuickGridView::insertBeforeVisible()
     QFETCH(int, cacheBuffer);
 
     QQuickText *name;
-    QQuickView *canvas = createView();
+    QQuickView *window = getView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("gridview1.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
@@ -559,7 +748,7 @@ void tst_QQuickGridView::insertBeforeVisible()
         QTRY_COMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::insertBeforeVisible_data()
@@ -585,31 +774,27 @@ void tst_QQuickGridView::insertBeforeVisible_data()
     QTest::newRow("insert multiple at 1, 500 buffer") << 1 << 6 << 500;
 }
 
-void tst_QQuickGridView::removed()
+void tst_QQuickGridView::removed_basic()
 {
-    QQuickView *canvas = createView();
-    canvas->show();
+    QQuickView *window = createView();
+    window->show();
 
     QaimModel model;
     for (int i = 0; i < 40; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     model.removeItem(1);
-    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
+    QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count());
 
     QQuickText *name = findItem<QQuickText>(contentItem, "textName", 1);
     QTRY_VERIFY(name != 0);
@@ -620,7 +805,7 @@ void tst_QQuickGridView::removed()
 
 
     // Checks that onRemove is called
-    QString removed = canvas->rootObject()->property("removed").toString();
+    QString removed = window->rootObject()->property("removed").toString();
     QTRY_COMPARE(removed, QString("Item1"));
 
     // Confirm items positioned correctly
@@ -634,7 +819,7 @@ void tst_QQuickGridView::removed()
 
     // Remove first item (which is the current item);
     model.removeItem(0);
-    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
+    QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count());
 
     name = findItem<QQuickText>(contentItem, "textName", 0);
     QTRY_VERIFY(name != 0);
@@ -655,7 +840,7 @@ void tst_QQuickGridView::removed()
 
     // Remove items not visible
     model.removeItem(25);
-    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
+    QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count());
 
     // Confirm items positioned correctly
     itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
@@ -674,7 +859,7 @@ void tst_QQuickGridView::removed()
     QTRY_COMPARE(gridview->contentY(), 120.0);
 
     model.removeItem(1);
-    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
+    QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count());
 
     // Confirm items positioned correctly
     for (int i = 6; i < 18; ++i) {
@@ -687,14 +872,13 @@ void tst_QQuickGridView::removed()
     // Remove currentIndex
     QQuickItem *oldCurrent = gridview->currentItem();
     model.removeItem(9);
-    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
+    QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count());
 
     QTRY_COMPARE(gridview->currentIndex(), 9);
     QTRY_VERIFY(gridview->currentItem() != oldCurrent);
 
     gridview->setContentY(0);
-    // let transitions settle.
-    QTest::qWait(300);
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     // Confirm items positioned correctly
     itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
@@ -728,40 +912,49 @@ void tst_QQuickGridView::removed()
     QTRY_COMPARE(gridview->currentIndex(), 7);
     QTRY_VERIFY(gridview->currentItem() == oldCurrent);
 
-    delete canvas;
+    delete window;
 }
 
-void tst_QQuickGridView::removed_more()
+void tst_QQuickGridView::removed_defaultLayout(QQuickGridView::Flow flow,
+                                               Qt::LayoutDirection horizLayout,
+                                               QQuickItemView::VerticalLayoutDirection verticalLayout)
 {
-    QFETCH(qreal, contentY);
+    QFETCH(qreal, contentYRowOffset);
     QFETCH(int, removeIndex);
     QFETCH(int, removeCount);
-    QFETCH(qreal, itemsOffsetAfterMove);
+    QFETCH(int, removeIndex_ttb);
+    QFETCH(int, removeCount_ttb);
+    QFETCH(qreal, rowOffsetAfterMove);
     QFETCH(QString, firstVisible);
+    QFETCH(QString, firstVisible_ttb);
 
-    QQuickText *name;
-    QQuickText *number;
-    QQuickView *canvas = createView();
+    QQuickView *window = getView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+    ctxt->setContextProperty("testRightToLeft", horizLayout == Qt::RightToLeft);
+    ctxt->setContextProperty("testBottomToTop", verticalLayout == QQuickGridView::BottomToTop);
+    window->setSource(testFileUrl("layouts.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
 
-    gridview->setContentY(contentY);
-    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+    if (flow == QQuickGridView::FlowTopToBottom) {
+        removeIndex = removeIndex_ttb;
+        removeCount = removeCount_ttb;
+        firstVisible = firstVisible_ttb;
+    }
+    if (setContentPos(gridview, contentYRowOffset))
+        QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     model.removeItems(removeIndex, removeCount);
     QTRY_COMPARE(gridview->property("count").toInt(), model.count());
@@ -769,161 +962,183 @@ void tst_QQuickGridView::removed_more()
     QString firstName;
     int firstVisibleIndex = -1;
     QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+    QRectF viewRect(gridview->contentX(), gridview->contentY(), gridview->width(), gridview->height());
     for (int i=0; i<items.count(); i++) {
-        if (items[i]->y() >= contentY) {
-            QQmlExpression e(qmlContext(items[i]), items[i], "index");
-            firstVisibleIndex = e.evaluate().toInt();
-            QQmlExpression en(qmlContext(items[i]), items[i], "name");
-            firstName = en.evaluate().toString();
-            break;
+        QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+        if (item) {
+            QRectF itemRect(item->x(), item->y(), item->width(), item->height());
+            if (delegateVisible(item) && viewRect.intersects(itemRect)) {
+                firstVisibleIndex = i;
+                QQmlExpression en(qmlContext(item), item, "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) {
+    for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++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);
+        QCOMPARE(item->pos(), expectedItemPos(gridview, i, rowOffsetAfterMove));
+        QQuickText *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;
+    releaseView(window);
 }
 
-void tst_QQuickGridView::removed_more_data()
+void tst_QQuickGridView::removed_defaultLayout_data()
 {
-    QTest::addColumn<qreal>("contentY");
+    QTest::addColumn<qreal>("contentYRowOffset");
     QTest::addColumn<int>("removeIndex");
     QTest::addColumn<int>("removeCount");
-    QTest::addColumn<qreal>("itemsOffsetAfterMove");
+    QTest::addColumn<int>("removeIndex_ttb");
+    QTest::addColumn<int>("removeCount_ttb");
+    QTest::addColumn<qreal>("rowOffsetAfterMove");
     QTest::addColumn<QString>("firstVisible");
+    QTest::addColumn<QString>("firstVisible_ttb");
 
     QTest::newRow("remove 1, before visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 2 << 1
-            << 0.0 << "Item7";
+               << 4 << 1
+            << 0.0 << "Item7" << "Item11";
 
     QTest::newRow("remove 1, before visible position")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 3 << 1
-            << 0.0 << "Item7";
+               << 5 << 1
+            << 0.0 << "Item7" << "Item11";
 
-    QTest::newRow("remove multiple, all before visible items")
-            << 120.0
+    QTest::newRow("remove multiple (1 row), all before visible items")
+            << 2.0
             << 1 << 3
-            << 60.0 << "Item6";    // removed top row, slide down by 1 row
+               << 1 << 5
+            << 1.0 << "Item6" << "Item10";    // removed top row, slide down by 1 row
 
     QTest::newRow("remove multiple, all before visible items, remove item 0")
-            << 120.0
+            << 2.0
             << 0 << 4
-            << 60.0 << "Item7";    // removed top row, slide down by 1 row
+               << 0 << 6
+            << 1.0 << "Item7" << "Item11";    // removed top row, slide down by 1 row
 
     QTest::newRow("remove multiple rows, all before visible items")
-            << 240.0     // show 12-29
+            << 4.0     // show 12-29
             << 1 << 7
-            << 120.0 << "Item13";
+               << 1 << 12
+            << 2.0 << "Item13" << "Item17";
 
     QTest::newRow("remove one row before visible, content y not on item border")
-            << 100.0
+            << 1.5
             << 0 << 3
-            << 60.0 << "Item6"; // 1 row removed
+               << 0 << 5
+            << 1.0 << "Item3" << "Item5"; // 1 row removed
 
     QTest::newRow("remove mix of visible/non-visible")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 2 << 3
-            << 60.0 << "Item6"; // 1 row removed
+               << 4 << 3
+            << 1.0 << "Item6" << "Item8"; // 1 row removed
 
 
     // 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
+            << 2.0
             << 3 << 5
-            << 60.0 << "Item8";    // adjust for the 1 row removed before the visible
+                << 5 << 7
+            << 1.0 << "Item8" << "Item12";    // 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
+            << 2.0
             << 0 << 8
-            << 60.0 * 2 << "Item8";    // adjust for the 2 rows removed before the visible
+               << 0 << 12
+            << 1.0 * 2 << "Item8" << "Item12";    // 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";
+               << 0 << 1
+            << 0.0 << "Item1" << "Item1";
 
     QTest::newRow("remove multiple, from start of visible, content at start")
             << 0.0
             << 0 << 3
-            << 0.0 << "Item3";
+               << 0 << 5
+            << 0.0 << "Item3" << "Item5";
 
     QTest::newRow("remove 1, from start of visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 4 << 1
-            << 0.0 << "Item7";
+               << 7 << 1
+            << 0.0 << "Item7" << "Item11";
 
     QTest::newRow("remove multiple, from start of visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 4 << 3
-            << 0.0 << "Item9";
+               << 7 << 5
+            << 0.0 << "Item9" << "Item15";
 
 
     QTest::newRow("remove 1, from middle of visible, content at start")
             << 0.0
             << 10 << 1
-            << 0.0 << "Item0";
+               << 12 << 1
+            << 0.0 << "Item0" << "Item0";
 
     QTest::newRow("remove multiple, from middle of visible, content at start")
             << 0.0
             << 10 << 5
-            << 0.0 << "Item0";
+               << 12 << 5
+            << 0.0 << "Item0" << "Item0";
 
     QTest::newRow("remove 1, from middle of visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 10 << 1
-            << 0.0 << "Item6";
+               << 12 << 1
+            << 0.0 << "Item6" << "Item10";
 
     QTest::newRow("remove multiple, from middle of visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 10 << 5
-            << 0.0 << "Item6";
+               << 12 << 7
+            << 0.0 << "Item6" << "Item10";
 
 
     QTest::newRow("remove 1, after visible, content at start")
             << 0.0
             << 16 << 1
-            << 0.0 << "Item0";
+               << 15 << 1
+            << 0.0 << "Item0" << "Item0";
 
     QTest::newRow("remove multiple, after visible, content at start")
             << 0.0
             << 16 << 5
-            << 0.0 << "Item0";
+               << 15 << 7
+            << 0.0 << "Item0" << "Item0";
 
     QTest::newRow("remove 1, after visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 16+4 << 1
-            << 0.0 << "Item6";
+               << 15+10 << 1
+            << 0.0 << "Item6" << "Item10";
 
     QTest::newRow("remove multiple, after visible, content not at start")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 16+4 << 5
-            << 0.0 << "Item6";
+               << 15+10 << 7
+            << 0.0 << "Item6" << "Item10";
 
     QTest::newRow("remove multiple, mix of items from within and after visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 20 << 5
-            << 0.0 << "Item6";
+               << 22 << 7
+            << 0.0 << "Item6" << "Item10";
 }
 
 void tst_QQuickGridView::addOrRemoveBeforeVisible()
@@ -934,20 +1149,17 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible()
     QFETCH(bool, doAdd);
     QFETCH(qreal, newTopContentY);
 
-    QQuickView *canvas = createView();
-    canvas->show();
+    QQuickView *window = getView();
+    window->show();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
@@ -968,7 +1180,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible()
     QTRY_COMPARE(gridview->currentIndex(), 24);
     QTRY_COMPARE(gridview->contentY(), 220.0);
 
-    QTest::qWait(100);  // wait for refill to complete
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
     QTRY_VERIFY(!findItem<QQuickItem>(contentItem, "wrapper", 0));  // 0 shouldn't be visible
 
     if (doAdd) {
@@ -1000,7 +1212,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible()
         QTRY_VERIFY(item->y() == (i/3)*60 + newTopContentY);
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::addOrRemoveBeforeVisible_data()
@@ -1014,22 +1226,18 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible_data()
 
 void tst_QQuickGridView::clear()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QVERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem != 0);
@@ -1041,6 +1249,7 @@ void tst_QQuickGridView::clear()
     QVERIFY(gridview->currentItem() == 0);
     QVERIFY(gridview->contentY() == 0);
     QVERIFY(gridview->currentIndex() == -1);
+    QCOMPARE(gridview->contentHeight(), 0.0);
 
     // confirm sanity when adding an item to cleared list
     model.addItem("New", "1");
@@ -1048,35 +1257,38 @@ void tst_QQuickGridView::clear()
     QVERIFY(gridview->currentItem() != 0);
     QVERIFY(gridview->currentIndex() == 0);
 
-    delete canvas;
+    delete window;
 }
 
-void tst_QQuickGridView::moved()
+void tst_QQuickGridView::moved_defaultLayout(QQuickGridView::Flow flow,
+                                             Qt::LayoutDirection horizLayout,
+                                             QQuickItemView::VerticalLayoutDirection verticalLayout)
 {
-    QFETCH(qreal, contentY);
+    QFETCH(qreal, contentYRowOffset);
     QFETCH(int, from);
     QFETCH(int, to);
     QFETCH(int, count);
-    QFETCH(qreal, itemsOffsetAfterMove);
+    QFETCH(int, from_ttb);
+    QFETCH(int, to_ttb);
+    QFETCH(int, count_ttb);
+    QFETCH(qreal, rowOffsetAfterMove);
 
-    QQuickText *name;
-    QQuickText *number;
-    QScopedPointer<QQuickView> canvas(createView());
+    QQuickView *window = getView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+    ctxt->setContextProperty("testRightToLeft", horizLayout == Qt::RightToLeft);
+    ctxt->setContextProperty("testBottomToTop", verticalLayout == QQuickGridView::BottomToTop);
+    window->setSource(testFileUrl("layouts.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
@@ -1085,46 +1297,60 @@ void tst_QQuickGridView::moved()
     QQuickItem *currentItem = gridview->currentItem();
     QTRY_VERIFY(currentItem != 0);
 
-    if (contentY != 0) {
-        gridview->setContentY(contentY);
-        QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+    if (flow == QQuickGridView::FlowTopToBottom) {
+        from = from_ttb;
+        to = to_ttb;
+        count = count_ttb;
     }
+    if (setContentPos(gridview, contentYRowOffset))
+        QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     model.moveItems(from, to, count);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     // Confirm items positioned correctly and indexes correct
-    int firstVisibleIndex = qCeil(contentY / 60.0) * 3;
-    int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
-    for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
-        if (i >= firstVisibleIndex + 18)    // index has moved out of view
-            continue;
+    QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+    int firstVisibleIndex = -1;
+    for (int i=0; i<items.count(); 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);
+        if (item && delegateVisible(item)) {
+            firstVisibleIndex = i;
+            break;
+        }
+    }
+    QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
 
-        name = findItem<QQuickText>(contentItem, "textName", i);
+    for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
+        QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+        if (!item &&
+                (  (flow == QQuickGridView::FlowLeftToRight && i >= firstVisibleIndex + (3*6))
+                || (flow == QQuickGridView::FlowTopToBottom && i >= firstVisibleIndex + (5*3)) ) ) {
+            continue;   // index has moved out of view
+        }
+        QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
+        QCOMPARE(item->pos(), expectedItemPos(gridview, i, rowOffsetAfterMove));
+        QQuickText *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));
 
         // current index should have been updated
         if (item == currentItem)
             QTRY_COMPARE(gridview->currentIndex(), i);
     }
+
+    releaseView(window);
 }
 
-void tst_QQuickGridView::moved_data()
+void tst_QQuickGridView::moved_defaultLayout_data()
 {
-    QTest::addColumn<qreal>("contentY");
+    QTest::addColumn<qreal>("contentYRowOffset");
     QTest::addColumn<int>("from");
     QTest::addColumn<int>("to");
     QTest::addColumn<int>("count");
-    QTest::addColumn<qreal>("itemsOffsetAfterMove");
+    QTest::addColumn<int>("from_ttb");
+    QTest::addColumn<int>("to_ttb");
+    QTest::addColumn<int>("count_ttb");
+    QTest::addColumn<qreal>("rowOffsetAfterMove");
 
     // model starts with 30 items, each 80x60, in area 240x320
     // 18 items should be visible at a time
@@ -1136,165 +1362,188 @@ void tst_QQuickGridView::moved_data()
     QTest::newRow("move 1 forwards, within visible items")
             << 0.0
             << 1 << 8 << 1
+               << 2 << 12 << 1
             << 0.0;
 
     QTest::newRow("move 1 forwards, from non-visible -> visible")
-            << 120.0     // show 6-23
-            << 1 << 23 << 1
+            << 2.0     // show 6-23
+            << 1 << 8+6 << 1
+               << 2 << 12+10 << 1
             << 0.0;
 
     QTest::newRow("move 1 forwards, from non-visible -> visible (move first item)")
-            << 120.0     // // show 6-23
+            << 2.0     // // show 6-23
             << 0 << 6 << 1
+               << 0 << 10 << 1
             << 0.0;
 
     QTest::newRow("move 1 forwards, from visible -> non-visible")
             << 0.0
             << 1 << 20 << 1
+               << 1 << 20 << 1
             << 0.0;
 
     QTest::newRow("move 1 forwards, from visible -> non-visible (move first item)")
             << 0.0
             << 0 << 20 << 1
+               << 0 << 20 << 1
             << 0.0;
 
 
     QTest::newRow("move 1 backwards, within visible items")
             << 0.0
             << 10 << 5 << 1
+               << 10 << 5 << 1
             << 0.0;
 
     QTest::newRow("move 1 backwards, within visible items (to first index)")
             << 0.0
             << 10 << 0 << 1
+               << 10 << 0 << 1
             << 0.0;
 
     QTest::newRow("move 1 backwards, from non-visible -> visible")
             << 0.0
             << 28 << 8 << 1
+               << 28 << 8 << 1
             << 0.0;
 
     QTest::newRow("move 1 backwards, from non-visible -> visible (move last item)")
             << 0.0
             << 29 << 14 << 1
+               << 29 << 14 << 1
             << 0.0;
 
     QTest::newRow("move 1 backwards, from visible -> non-visible")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 7 << 1 << 1
+               << 10 << 1 << 1
             << 0.0;     // only 1 item moved back, so items shift accordingly and first row doesn't move
 
     QTest::newRow("move 1 backwards, from visible -> non-visible (move first item)")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 7 << 0 << 1
+               << 10 << 0 << 1
             << 0.0;     // only 1 item moved back, so items shift accordingly and first row doesn't move
 
 
     QTest::newRow("move multiple forwards, within visible items")
             << 0.0
             << 0 << 5 << 3
+               << 0 << 7 << 5
             << 0.0;
 
     QTest::newRow("move multiple backwards, within visible items (move first item)")
             << 0.0
             << 10 << 0 << 3
+               << 12 << 0 << 5
             << 0.0;
 
     QTest::newRow("move multiple forwards, before visible items")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 3 << 4 << 3      // 3, 4, 5 move to after 6
-            << 60.0;      // row of 3,4,5 has moved down
+               << 5 << 6 << 5
+            << 1.0;      // row of 3,4,5 has moved down
 
     QTest::newRow("move multiple forwards, from non-visible -> visible")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 1 << 6 << 3
-            << 60.0; // 1st row (it's above visible area) disappears, 0 drops down 1 row, first visible item (6) stays where it is
+               << 1 << 10 << 5
+            << 1.0; // 1st row (it's above visible area) disappears, 0 drops down 1 row, first visible item (6) stays where it is
 
     QTest::newRow("move multiple forwards, from non-visible -> visible (move first item)")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 0 << 6 << 3
-            << 60.0;    // top row moved and shifted to below 3rd row, all items should shift down by 1 row
+               << 0 << 10 << 5
+            << 1.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
+            << 2.0
             << 3 << 16 << 6
-            << 60.0;    // top two rows removed, third row is now the first visible
+               << 5 << 18 << 10
+            << 1.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
+               << 1 << 8 << 6
             << 0.0;
 
     QTest::newRow("move multiple forwards, to bottom of view, first row -> last")
             << 0.0
             << 0 << 15 << 3
+               << 0 << 10 << 5
             << 0.0;
 
     QTest::newRow("move multiple forwards, to bottom of view, content y not 0")
-            << 120.0
+            << 2.0
             << 5+4 << 13+4 << 5
+               << 11 << 19 << 6
             << 0.0;
 
     QTest::newRow("move multiple forwards, from visible -> non-visible")
             << 0.0
             << 1 << 16 << 3
+               << 1 << 18 << 5
             << 0.0;
 
     QTest::newRow("move multiple forwards, from visible -> non-visible (move first item)")
             << 0.0
             << 0 << 16 << 3
+               << 1 << 18 << 5
             << 0.0;
 
 
     QTest::newRow("move multiple backwards, within visible items")
             << 0.0
             << 4 << 1 << 3
+               << 7 << 1 << 5
             << 0.0;
 
     QTest::newRow("move multiple backwards, from non-visible -> visible")
             << 0.0
             << 20 << 4 << 3
+               << 20 << 4 << 5
             << 0.0;
 
     QTest::newRow("move multiple backwards, from non-visible -> visible (move last item)")
             << 0.0
             << 27 << 10 << 3
+               << 25 << 8 << 5
             << 0.0;
 
     QTest::newRow("move multiple backwards, from visible -> non-visible")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 16 << 1 << 3
-            << -60.0;   // to minimize movement, items are added above visible area, all items move up by 1 row
+               << 17 << 1 << 5
+            << -1.0;   // to minimize movement, items are added above visible area, all items move up by 1 row
 
     QTest::newRow("move multiple backwards, from visible -> non-visible (move first item)")
-            << 120.0     // show 6-23
+            << 2.0     // show 6-23
             << 16 << 0 << 3
-            << -60.0;   // 16,17,18 move to above item 0, all items move up by 1 row
+               << 17 << 0 << 5
+            << -1.0;   // 16,17,18 move to above item 0, all items move up by 1 row
 }
 
-void tst_QQuickGridView::multipleChanges()
+void tst_QQuickGridView::multipleChanges(bool condensed)
 {
     QFETCH(int, startCount);
     QFETCH(QList<ListChange>, changes);
     QFETCH(int, newCount);
     QFETCH(int, newCurrentIndex);
 
-    QQuickView *canvas = createView();
+    QQuickView *window = getView();
 
     QaimModel model;
     for (int i = 0; i < startCount; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
@@ -1310,26 +1559,28 @@ void tst_QQuickGridView::multipleChanges()
             }
             case ListChange::Removed:
                 model.removeItems(changes[i].index, changes[i].count);
-                QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
                 break;
             case ListChange::Moved:
                 model.moveItems(changes[i].index, changes[i].to, changes[i].count);
-                QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
                 break;
             case ListChange::SetCurrent:
                 gridview->setCurrentIndex(changes[i].index);
-                QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
                 break;
             case ListChange::SetContentY:
                 gridview->setContentY(changes[i].pos);
-                QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+                break;
+            case ListChange::Polish:
                 break;
         }
+        if (condensed) {
+            QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+        }
     }
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
-    QTRY_COMPARE(gridview->count(), newCount);
+    QCOMPARE(gridview->count(), newCount);
     QCOMPARE(gridview->count(), model.count());
-    QTRY_COMPARE(gridview->currentIndex(), newCurrentIndex);
+    QCOMPARE(gridview->currentIndex(), newCurrentIndex);
 
     QQuickText *name;
     QQuickText *number;
@@ -1347,7 +1598,7 @@ void tst_QQuickGridView::multipleChanges()
         QTRY_COMPARE(number->text(), model.number(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::multipleChanges_data()
@@ -1498,28 +1749,46 @@ void tst_QQuickGridView::multipleChanges_data()
             << ListChange::remove(0, 5)
             << ListChange::insert(0, 5)
             ) << 5 << -1;
+
+    QTest::newRow("remove, scroll") << 30 << (QList<ListChange>()
+            << ListChange::remove(20, 5)
+            << ListChange::setContentY(20)
+            ) << 25 << 0;
+
+    QTest::newRow("insert, scroll") << 10 << (QList<ListChange>()
+            << ListChange::insert(9, 5)
+            << ListChange::setContentY(20)
+            ) << 15 << 0;
+
+    QTest::newRow("move, scroll") << 20 << (QList<ListChange>()
+            << ListChange::move(15, 8, 3)
+            << ListChange::setContentY(0)
+            ) << 20 << 0;
+
+    QTest::newRow("clear, insert, scroll") << 30 << (QList<ListChange>()
+            << ListChange::setContentY(20)
+            << ListChange::remove(0, 30)
+            << ListChange::insert(0, 2)
+            << ListChange::setContentY(0)
+            ) << 2 << 0;
 }
 
 
 void tst_QQuickGridView::swapWithFirstItem()
 {
     // QTBUG_9697
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     // ensure content position is stable
@@ -1527,7 +1796,7 @@ void tst_QQuickGridView::swapWithFirstItem()
     model.moveItem(10, 0);
     QTRY_VERIFY(gridview->contentY() == 0);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::currentIndex()
@@ -1536,19 +1805,19 @@ void tst_QQuickGridView::currentIndex()
     for (int i = 0; i < 60; i++)
         model.addItem("Item" + QString::number(i), QString::number(i));
 
-    QQuickView *canvas = new QQuickView(0);
-    canvas->setGeometry(0,0,240,320);
-    canvas->show();
+    QQuickView *window = new QQuickView(0);
+    window->setGeometry(0,0,240,320);
+    window->show();
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
 
     QString filename(testFile("gridview-initCurrent.qml"));
-    canvas->setSource(QUrl::fromLocalFile(filename));
+    window->setSource(QUrl::fromLocalFile(filename));
 
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QVERIFY(gridview != 0);
     QTRY_VERIFY(!QQuickItemPrivate::get(gridview)->polishScheduled);
 
@@ -1561,146 +1830,28 @@ void tst_QQuickGridView::currentIndex()
     QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y());
     QCOMPARE(gridview->contentY(), 400.0);
 
-    gridview->moveCurrentIndexRight();
-    QCOMPARE(gridview->currentIndex(), 36);
-    gridview->moveCurrentIndexDown();
-    QCOMPARE(gridview->currentIndex(), 39);
-    gridview->moveCurrentIndexUp();
-    QCOMPARE(gridview->currentIndex(), 36);
-    gridview->moveCurrentIndexLeft();
-    QCOMPARE(gridview->currentIndex(), 35);
-
-    // wait until motion stops
-    QTRY_VERIFY(gridview->verticalVelocity() == 0.0);
-
-    // no wrap
     gridview->setCurrentIndex(0);
     QCOMPARE(gridview->currentIndex(), 0);
     // confirm that the velocity is updated
     QTRY_VERIFY(gridview->verticalVelocity() != 0.0);
 
-    gridview->moveCurrentIndexUp();
-    QCOMPARE(gridview->currentIndex(), 0);
-
-    gridview->moveCurrentIndexLeft();
-    QCOMPARE(gridview->currentIndex(), 0);
-
-    gridview->setCurrentIndex(model.count()-1);
-    QCOMPARE(gridview->currentIndex(), model.count()-1);
-
-    gridview->moveCurrentIndexRight();
-    QCOMPARE(gridview->currentIndex(), model.count()-1);
-
-    gridview->moveCurrentIndexDown();
-    QCOMPARE(gridview->currentIndex(), model.count()-1);
-
-    // with wrap
-    gridview->setWrapEnabled(true);
-
-    gridview->setCurrentIndex(0);
-    QCOMPARE(gridview->currentIndex(), 0);
-
-    gridview->moveCurrentIndexLeft();
-    QCOMPARE(gridview->currentIndex(), model.count()-1);
-
-    qApp->processEvents();
-    QTRY_COMPARE(gridview->contentY(), 880.0);
-
-    gridview->moveCurrentIndexRight();
-    QCOMPARE(gridview->currentIndex(), 0);
-
-    QTRY_COMPARE(gridview->contentY(), 0.0);
-
-
     // footer should become visible if it is out of view, and then current index moves to the first row
-    canvas->rootObject()->setProperty("showFooter", true);
+    window->rootObject()->setProperty("showFooter", true);
     QTRY_VERIFY(gridview->footerItem());
     gridview->setCurrentIndex(model.count()-3);
     QTRY_VERIFY(gridview->footerItem()->y() > gridview->contentY() + gridview->height());
     gridview->setCurrentIndex(model.count()-2);
     QTRY_COMPARE(gridview->contentY() + gridview->height(), (60.0 * model.count()/3) + gridview->footerItem()->height());
-    canvas->rootObject()->setProperty("showFooter", false);
+    window->rootObject()->setProperty("showFooter", false);
 
     // header should become visible if it is out of view, and then current index moves to the last row
-    canvas->rootObject()->setProperty("showHeader", true);
+    window->rootObject()->setProperty("showHeader", true);
     QTRY_VERIFY(gridview->headerItem());
     gridview->setCurrentIndex(3);
     QTRY_VERIFY(gridview->headerItem()->y() + gridview->headerItem()->height() < gridview->contentY());
     gridview->setCurrentIndex(1);
     QTRY_COMPARE(gridview->contentY(), -gridview->headerItem()->height());
-    canvas->rootObject()->setProperty("showHeader", false);
-
-
-    // Test keys
-    canvas->requestActivateWindow();
-    QTest::qWaitForWindowShown(canvas);
-    QTRY_VERIFY(qGuiApp->focusWindow() == canvas);
-
-    gridview->setCurrentIndex(0);
-
-    QTest::keyClick(canvas, Qt::Key_Down);
-    QCOMPARE(gridview->currentIndex(), 3);
-
-    QTest::keyClick(canvas, Qt::Key_Up);
-    QCOMPARE(gridview->currentIndex(), 0);
-
-    // hold down Key_Down
-    for (int i=0; i<(model.count() / 3) - 1; i++) {
-        QTest::simulateEvent(canvas, true, Qt::Key_Down, Qt::NoModifier, "", true);
-        QTRY_COMPARE(gridview->currentIndex(), i*3 + 3);
-    }
-    QTest::keyRelease(canvas, Qt::Key_Down);
-    QTRY_COMPARE(gridview->currentIndex(), 57);
-    QTRY_COMPARE(gridview->contentY(), 880.0);
-
-    // hold down Key_Up
-    for (int i=(model.count() / 3) - 1; i > 0; i--) {
-        QTest::simulateEvent(canvas, true, Qt::Key_Up, Qt::NoModifier, "", true);
-        QTRY_COMPARE(gridview->currentIndex(), i*3 - 3);
-    }
-    QTest::keyRelease(canvas, Qt::Key_Up);
-    QTRY_COMPARE(gridview->currentIndex(), 0);
-    QTRY_COMPARE(gridview->contentY(), 0.0);
-
-
-    gridview->setFlow(QQuickGridView::TopToBottom);
-
-    canvas->requestActivateWindow();
-    QTest::qWaitForWindowShown(canvas);
-    QVERIFY(qGuiApp->focusWindow() == canvas);
-    qApp->processEvents();
-
-    QTest::keyClick(canvas, Qt::Key_Right);
-    QCOMPARE(gridview->currentIndex(), 5);
-
-    QTest::keyClick(canvas, Qt::Key_Left);
-    QCOMPARE(gridview->currentIndex(), 0);
-
-    QTest::keyClick(canvas, Qt::Key_Down);
-    QCOMPARE(gridview->currentIndex(), 1);
-
-    QTest::keyClick(canvas, Qt::Key_Up);
-    QCOMPARE(gridview->currentIndex(), 0);
-
-    // hold down Key_Right
-    for (int i=0; i<(model.count() / 5) - 1; i++) {
-        QTest::simulateEvent(canvas, true, Qt::Key_Right, Qt::NoModifier, "", true);
-        QTRY_COMPARE(gridview->currentIndex(), i*5 + 5);
-    }
-
-    QTest::keyRelease(canvas, Qt::Key_Right);
-    QTRY_COMPARE(gridview->currentIndex(), 55);
-    QTRY_COMPARE(gridview->contentX(), 720.0);
-
-    // hold down Key_Left
-    for (int i=(model.count() / 5) - 1; i > 0; i--) {
-        QTest::simulateEvent(canvas, true, Qt::Key_Left, Qt::NoModifier, "", true);
-        QTRY_COMPARE(gridview->currentIndex(), i*5 - 5);
-    }
-    QTest::keyRelease(canvas, Qt::Key_Left);
-    QTRY_COMPARE(gridview->currentIndex(), 0);
-    QTRY_COMPARE(gridview->contentX(), 0.0);
-
+    window->rootObject()->setProperty("showHeader", false);
 
     // turn off auto highlight
     gridview->setHighlightFollowsCurrentItem(false);
@@ -1716,7 +1867,7 @@ void tst_QQuickGridView::currentIndex()
     // insert item before currentIndex
     gridview->setCurrentIndex(28);
     model.insertItem(0, "Foo", "1111");
-    QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29);
+    QTRY_COMPARE(window->rootObject()->property("current").toInt(), 29);
 
     // check removing highlight by setting currentIndex to -1;
     gridview->setCurrentIndex(-1);
@@ -1725,55 +1876,13 @@ void tst_QQuickGridView::currentIndex()
     QVERIFY(!gridview->highlightItem());
     QVERIFY(!gridview->currentItem());
 
-    gridview->setHighlightFollowsCurrentItem(true);
-
-    gridview->setFlow(QQuickGridView::LeftToRight);
-    gridview->setLayoutDirection(Qt::RightToLeft);
-
-    canvas->requestActivateWindow();
-    QTest::qWaitForWindowShown(canvas);
-    QTRY_VERIFY(qGuiApp->focusWindow() == canvas);
-    qApp->processEvents();
-
-    gridview->setCurrentIndex(35);
-
-    QTest::keyClick(canvas, Qt::Key_Right);
-    QCOMPARE(gridview->currentIndex(), 34);
-
-    QTest::keyClick(canvas, Qt::Key_Down);
-    QCOMPARE(gridview->currentIndex(), 37);
-
-    QTest::keyClick(canvas, Qt::Key_Up);
-    QCOMPARE(gridview->currentIndex(), 34);
-
-    QTest::keyClick(canvas, Qt::Key_Left);
-    QCOMPARE(gridview->currentIndex(), 35);
-
-
-    // turn off auto highlight
-    gridview->setHighlightFollowsCurrentItem(false);
-    QVERIFY(gridview->highlightFollowsCurrentItem() == false);
-    QVERIFY(gridview->highlightItem());
-    hlPosX = gridview->highlightItem()->x();
-    hlPosY = gridview->highlightItem()->y();
-
-    gridview->setCurrentIndex(5);
-    QTRY_COMPARE(gridview->highlightItem()->x(), hlPosX);
-    QTRY_COMPARE(gridview->highlightItem()->y(), hlPosY);
-
-    // insert item before currentIndex
-    gridview->setCurrentIndex(28);
-    model.insertItem(0, "Foo", "1111");
-    QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29);
-
-    // check removing highlight by setting currentIndex to -1;
-    gridview->setCurrentIndex(-1);
-
-    QCOMPARE(gridview->currentIndex(), -1);
-    QVERIFY(!gridview->highlightItem());
-    QVERIFY(!gridview->currentItem());
+    // moving currentItem out of view should make it invisible
+    gridview->setCurrentIndex(0);
+    QTRY_VERIFY(delegateVisible(gridview->currentItem()));
+    gridview->setContentY(200);
+    QTRY_VERIFY(!delegateVisible(gridview->currentItem()));
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::noCurrentIndex()
@@ -1782,18 +1891,18 @@ void tst_QQuickGridView::noCurrentIndex()
     for (int i = 0; i < 60; i++)
         model.addItem("Item" + QString::number(i), QString::number(i));
 
-    QQuickView *canvas = new QQuickView(0);
-    canvas->setGeometry(0,0,240,320);
+    QQuickView *window = new QQuickView(0);
+    window->setGeometry(0,0,240,320);
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
 
     QString filename(testFile("gridview-noCurrent.qml"));
-    canvas->setSource(QUrl::fromLocalFile(filename));
-    canvas->show();
+    window->setSource(QUrl::fromLocalFile(filename));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QVERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem != 0);
@@ -1810,26 +1919,240 @@ void tst_QQuickGridView::noCurrentIndex()
     QVERIFY(gridview->currentItem());
     QVERIFY(gridview->highlightItem());
 
-    delete canvas;
+    delete window;
+}
+
+void tst_QQuickGridView::keyNavigation()
+{
+    QFETCH(QQuickGridView::Flow, flow);
+    QFETCH(Qt::LayoutDirection, layoutDirection);
+    QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+    QFETCH(Qt::Key, forwardsKey);
+    QFETCH(Qt::Key, backwardsKey);
+    QFETCH(QPointF, contentPosAtFirstItem);
+    QFETCH(QPointF, contentPosAtLastItem);
+    QFETCH(int, indexRightOf7);
+    QFETCH(int, indexLeftOf7);
+    QFETCH(int, indexUpFrom7);
+    QFETCH(int, indexDownFrom7);
+
+    QmlListModel model;
+    for (int i = 0; i < 18; i++)
+        model.addItem("Item" + QString::number(i), "");
+
+    QQuickView *window = getView();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
+    window->show();
+    QTest::qWaitForWindowActive(window);
+
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
+    QTRY_VERIFY(gridview != 0);
+    gridview->setFlow(flow);
+    gridview->setLayoutDirection(layoutDirection);
+    gridview->setVerticalLayoutDirection(verticalLayoutDirection);
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+    window->requestActivateWindow();
+    QTest::qWaitForWindowActive(window);
+    QTRY_VERIFY(qGuiApp->focusWindow() == window);
+    QCOMPARE(gridview->currentIndex(), 0);
+
+    QTest::keyClick(window, forwardsKey);
+    QCOMPARE(gridview->currentIndex(), 1);
+
+    QTest::keyClick(window, backwardsKey);
+    QCOMPARE(gridview->currentIndex(), 0);
+
+    gridview->setCurrentIndex(7);
+    gridview->moveCurrentIndexRight();
+    QCOMPARE(gridview->currentIndex(), indexRightOf7);
+    gridview->moveCurrentIndexLeft();
+    QCOMPARE(gridview->currentIndex(), 7);
+    gridview->moveCurrentIndexLeft();
+    QCOMPARE(gridview->currentIndex(), indexLeftOf7);
+    gridview->moveCurrentIndexRight();
+    QCOMPARE(gridview->currentIndex(), 7);
+    gridview->moveCurrentIndexUp();
+    QCOMPARE(gridview->currentIndex(), indexUpFrom7);
+    gridview->moveCurrentIndexDown();
+    QCOMPARE(gridview->currentIndex(), 7);
+    gridview->moveCurrentIndexDown();
+    QCOMPARE(gridview->currentIndex(), indexDownFrom7);
+
+    gridview->setCurrentIndex(7);
+    QTest::keyClick(window, Qt::Key_Right);
+    QCOMPARE(gridview->currentIndex(), indexRightOf7);
+    QTest::keyClick(window, Qt::Key_Left);
+    QCOMPARE(gridview->currentIndex(), 7);
+    QTest::keyClick(window, Qt::Key_Left);
+    QCOMPARE(gridview->currentIndex(), indexLeftOf7);
+    QTest::keyClick(window, Qt::Key_Right);
+    QCOMPARE(gridview->currentIndex(), 7);
+    QTest::keyClick(window, Qt::Key_Up);
+    QCOMPARE(gridview->currentIndex(), indexUpFrom7);
+    QTest::keyClick(window, Qt::Key_Down);
+    QCOMPARE(gridview->currentIndex(), 7);
+    QTest::keyClick(window, Qt::Key_Down);
+    QCOMPARE(gridview->currentIndex(), indexDownFrom7);
+
+    // hold down a key to go forwards
+    gridview->setCurrentIndex(0);
+    for (int i=0; i<model.count()-1; i++) {
+//        QTest::qWait(500);
+        QTest::simulateEvent(window, true, forwardsKey, Qt::NoModifier, "", true);
+        QTRY_COMPARE(gridview->currentIndex(), i+1);
+    }
+    QTest::keyRelease(window, forwardsKey);
+    QTRY_COMPARE(gridview->currentIndex(), model.count()-1);
+    QTRY_COMPARE(gridview->contentX(), contentPosAtLastItem.x());
+    QTRY_COMPARE(gridview->contentY(), contentPosAtLastItem.y());
+
+    // hold down a key to go backwards
+    for (int i=model.count()-1; i > 0; i--) {
+        QTest::simulateEvent(window, true, backwardsKey, Qt::NoModifier, "", true);
+        QTRY_COMPARE(gridview->currentIndex(), i-1);
+    }
+    QTest::keyRelease(window, backwardsKey);
+    QTRY_COMPARE(gridview->currentIndex(), 0);
+    QTRY_COMPARE(gridview->contentX(), contentPosAtFirstItem.x());
+    QTRY_COMPARE(gridview->contentY(), contentPosAtFirstItem.y());
+
+    // no wrap
+    QVERIFY(!gridview->isWrapEnabled());
+    QTest::keyClick(window, forwardsKey);
+    QCOMPARE(gridview->currentIndex(), 1);
+    QTest::keyClick(window, backwardsKey);
+    QCOMPARE(gridview->currentIndex(), 0);
+
+    QTest::keyClick(window, backwardsKey);
+    QCOMPARE(gridview->currentIndex(), 0);
+
+    // with wrap
+    gridview->setWrapEnabled(true);
+    QVERIFY(gridview->isWrapEnabled());
+
+    QTest::keyClick(window, backwardsKey);
+    QCOMPARE(gridview->currentIndex(), model.count()-1);
+    QTRY_COMPARE(gridview->contentX(), contentPosAtLastItem.x());
+    QTRY_COMPARE(gridview->contentY(), contentPosAtLastItem.y());
+
+    QTest::keyClick(window, forwardsKey);
+    QCOMPARE(gridview->currentIndex(), 0);
+    QTRY_COMPARE(gridview->contentX(), contentPosAtFirstItem.x());
+    QTRY_COMPARE(gridview->contentY(), contentPosAtFirstItem.y());
+
+    // Test key press still accepted when position wraps to same index.
+    window->rootObject()->setProperty("lastKey", 0);
+    model.removeItems(1, model.count() - 1);
+
+    QTest::keyClick(window, backwardsKey);
+    QCOMPARE(window->rootObject()->property("lastKey").toInt(), 0);
+
+    QTest::keyClick(window, forwardsKey);
+    QCOMPARE(window->rootObject()->property("lastKey").toInt(), 0);
+
+    // Test key press not accepted at limits when wrap is disabled.
+    gridview->setWrapEnabled(false);
+
+    QTest::keyClick(window, backwardsKey);
+    QCOMPARE(window->rootObject()->property("lastKey").toInt(), int(backwardsKey));
+
+    QTest::keyClick(window, forwardsKey);
+    QCOMPARE(window->rootObject()->property("lastKey").toInt(), int(forwardsKey));
+
+    releaseView(window);
+}
+
+void tst_QQuickGridView::keyNavigation_data()
+{
+    QTest::addColumn<QQuickGridView::Flow>("flow");
+    QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+    QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+    QTest::addColumn<Qt::Key>("forwardsKey");
+    QTest::addColumn<Qt::Key>("backwardsKey");
+    QTest::addColumn<QPointF>("contentPosAtFirstItem");
+    QTest::addColumn<QPointF>("contentPosAtLastItem");
+    QTest::addColumn<int>("indexRightOf7");
+    QTest::addColumn<int>("indexLeftOf7");
+    QTest::addColumn<int>("indexUpFrom7");
+    QTest::addColumn<int>("indexDownFrom7");
+
+    QTest::newRow("LeftToRight, LtR, TtB")
+            << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
+            << Qt::Key_Right << Qt::Key_Left
+            << QPointF(0, 0)
+            << QPointF(0, 40)
+            << 8 << 6 << 4 << 10;
+
+    QTest::newRow("LeftToRight, RtL, TtB")
+            << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
+            << Qt::Key_Left << Qt::Key_Right
+            << QPointF(0, 0)
+            << QPointF(0, 40)
+            << 6 << 8 << 4 << 10;
+
+    QTest::newRow("LeftToRight, LtR, BtT")
+            << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+            << Qt::Key_Right << Qt::Key_Left
+            << QPointF(0, -320)
+            << QPointF(0, -360)
+            << 8 << 6 << 10 << 4;
+
+    QTest::newRow("LeftToRight, RtL, BtT")
+            << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+            << Qt::Key_Left << Qt::Key_Right
+            << QPointF(0, -320)
+            << QPointF(0, -360)
+            << 6 << 8 << 10 << 4;
+
+    QTest::newRow("TopToBottom, LtR, TtB")
+            << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
+            << Qt::Key_Down << Qt::Key_Up
+            << QPointF(0, 0)
+            << QPointF(80, 0)
+            << 12 << 2 << 6 << 8;
+
+    QTest::newRow("TopToBottom, RtL, TtB")
+            << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
+            << Qt::Key_Down << Qt::Key_Up
+            << QPointF(-240, 0)
+            << QPointF(-320, 0)
+            << 2 << 12 << 6 << 8;
+
+    QTest::newRow("TopToBottom, LtR, BtT")
+            << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+            << Qt::Key_Up << Qt::Key_Down
+            << QPointF(0, -320)
+            << QPointF(80, -320)
+            << 12 << 2 << 8 << 6;
+
+    QTest::newRow("TopToBottom, RtL, BtT")
+            << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+            << Qt::Key_Up << Qt::Key_Down
+            << QPointF(-240, -320)
+            << QPointF(-320, -320)
+            << 2 << 12 << 8 << 6;
 }
 
 void tst_QQuickGridView::changeFlow()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), QString::number(i));
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("testRightToLeft", QVariant(false));
     ctxt->setContextProperty("testTopToBottom", QVariant(false));
+    ctxt->setContextProperty("testBottomToTop", QVariant(false));
 
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->setSource(testFileUrl("layouts.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -1907,7 +2230,7 @@ void tst_QQuickGridView::changeFlow()
         QTRY_COMPARE(number->text(), model.number(i));
     }
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::defaultValues()
@@ -1927,7 +2250,11 @@ void tst_QQuickGridView::defaultValues()
     QTRY_COMPARE(obj->highlightFollowsCurrentItem(), true);
     QTRY_VERIFY(obj->flow() == 0);
     QTRY_COMPARE(obj->isWrapEnabled(), false);
-    QTRY_COMPARE(obj->cacheBuffer(), 0);
+#ifdef QML_VIEW_DEFAULTCACHEBUFFER
+    QTRY_COMPARE(obj->cacheBuffer(), QML_VIEW_DEFAULTCACHEBUFFER);
+#else
+    QTRY_COMPARE(obj->cacheBuffer(), 320);
+#endif
     QTRY_COMPARE(obj->cellWidth(), qreal(100)); //### Should 100 be the default?
     QTRY_COMPARE(obj->cellHeight(), qreal(100));
     delete obj;
@@ -1958,11 +2285,11 @@ void tst_QQuickGridView::properties()
 
 void tst_QQuickGridView::propertyChanges()
 {
-    QQuickView *canvas = createView();
-    QTRY_VERIFY(canvas);
-    canvas->setSource(testFileUrl("propertychangestest.qml"));
+    QQuickView *window = createView();
+    QTRY_VERIFY(window);
+    window->setSource(testFileUrl("propertychangestest.qml"));
 
-    QQuickGridView *gridView = canvas->rootObject()->findChild<QQuickGridView*>("gridView");
+    QQuickGridView *gridView = window->rootObject()->findChild<QQuickGridView*>("gridView");
     QTRY_VERIFY(gridView);
 
     QSignalSpy keyNavigationWrapsSpy(gridView, SIGNAL(keyNavigationWrapsChanged()));
@@ -1972,15 +2299,15 @@ void tst_QQuickGridView::propertyChanges()
 
     QTRY_COMPARE(gridView->isWrapEnabled(), true);
     QTRY_COMPARE(gridView->cacheBuffer(), 10);
-    QTRY_COMPARE(gridView->flow(), QQuickGridView::LeftToRight);
+    QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowLeftToRight);
 
     gridView->setWrapEnabled(false);
     gridView->setCacheBuffer(3);
-    gridView->setFlow(QQuickGridView::TopToBottom);
+    gridView->setFlow(QQuickGridView::FlowTopToBottom);
 
     QTRY_COMPARE(gridView->isWrapEnabled(), false);
     QTRY_COMPARE(gridView->cacheBuffer(), 3);
-    QTRY_COMPARE(gridView->flow(), QQuickGridView::TopToBottom);
+    QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowTopToBottom);
 
     QTRY_COMPARE(keyNavigationWrapsSpy.count(),1);
     QTRY_COMPARE(cacheBufferSpy.count(),1);
@@ -1988,14 +2315,14 @@ void tst_QQuickGridView::propertyChanges()
 
     gridView->setWrapEnabled(false);
     gridView->setCacheBuffer(3);
-    gridView->setFlow(QQuickGridView::TopToBottom);
+    gridView->setFlow(QQuickGridView::FlowTopToBottom);
 
     QTRY_COMPARE(keyNavigationWrapsSpy.count(),1);
     QTRY_COMPARE(cacheBufferSpy.count(),1);
     QTRY_COMPARE(flowSpy.count(),1);
 
-    gridView->setFlow(QQuickGridView::LeftToRight);
-    QTRY_COMPARE(gridView->flow(), QQuickGridView::LeftToRight);
+    gridView->setFlow(QQuickGridView::FlowLeftToRight);
+    QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowLeftToRight);
 
     gridView->setWrapEnabled(true);
     gridView->setCacheBuffer(5);
@@ -2019,35 +2346,37 @@ void tst_QQuickGridView::propertyChanges()
     QTRY_COMPARE(layoutSpy.count(),1);
     QTRY_COMPARE(flowSpy.count(),2);
 
-    gridView->setFlow(QQuickGridView::TopToBottom);
-    QTRY_COMPARE(gridView->flow(), QQuickGridView::TopToBottom);
+    gridView->setFlow(QQuickGridView::FlowTopToBottom);
+    QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowTopToBottom);
     QTRY_COMPARE(flowSpy.count(),3);
 
-    gridView->setFlow(QQuickGridView::TopToBottom);
+    gridView->setFlow(QQuickGridView::FlowTopToBottom);
     QTRY_COMPARE(flowSpy.count(),3);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::componentChanges()
 {
-    QQuickView *canvas = createView();
-    QTRY_VERIFY(canvas);
-    canvas->setSource(testFileUrl("propertychangestest.qml"));
+    QQuickView *window = createView();
+    QTRY_VERIFY(window);
+    window->setSource(testFileUrl("propertychangestest.qml"));
 
-    QQuickGridView *gridView = canvas->rootObject()->findChild<QQuickGridView*>("gridView");
+    QQuickGridView *gridView = window->rootObject()->findChild<QQuickGridView*>("gridView");
     QTRY_VERIFY(gridView);
 
-    QQmlComponent component(canvas->engine());
-    component.setData("import QtQuick 1.0; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile(""));
+    QQmlComponent component(window->engine());
+    component.setData("import QtQuick 2.0; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile(""));
 
-    QQmlComponent delegateComponent(canvas->engine());
-    delegateComponent.setData("import QtQuick 1.0; Text { text: '<b>Name:</b> ' + name }", QUrl::fromLocalFile(""));
+    QQmlComponent delegateComponent(window->engine());
+    delegateComponent.setData("import QtQuick 2.0; Text { text: '<b>Name:</b> ' + name }", QUrl::fromLocalFile(""));
 
     QSignalSpy highlightSpy(gridView, SIGNAL(highlightChanged()));
     QSignalSpy delegateSpy(gridView, SIGNAL(delegateChanged()));
     QSignalSpy headerSpy(gridView, SIGNAL(headerChanged()));
     QSignalSpy footerSpy(gridView, SIGNAL(footerChanged()));
+    QSignalSpy headerItemSpy(gridView, SIGNAL(headerItemChanged()));
+    QSignalSpy footerItemSpy(gridView, SIGNAL(footerItemChanged()));
 
     gridView->setHighlight(&component);
     gridView->setDelegate(&delegateComponent);
@@ -2059,10 +2388,15 @@ void tst_QQuickGridView::componentChanges()
     QTRY_COMPARE(gridView->header(), &component);
     QTRY_COMPARE(gridView->footer(), &component);
 
+    QVERIFY(gridView->headerItem());
+    QVERIFY(gridView->footerItem());
+
     QTRY_COMPARE(highlightSpy.count(),1);
     QTRY_COMPARE(delegateSpy.count(),1);
     QTRY_COMPARE(headerSpy.count(),1);
     QTRY_COMPARE(footerSpy.count(),1);
+    QTRY_COMPARE(headerItemSpy.count(),1);
+    QTRY_COMPARE(footerItemSpy.count(),1);
 
     gridView->setHighlight(&component);
     gridView->setDelegate(&delegateComponent);
@@ -2073,20 +2407,22 @@ void tst_QQuickGridView::componentChanges()
     QTRY_COMPARE(delegateSpy.count(),1);
     QTRY_COMPARE(headerSpy.count(),1);
     QTRY_COMPARE(footerSpy.count(),1);
+    QTRY_COMPARE(headerItemSpy.count(),1);
+    QTRY_COMPARE(footerItemSpy.count(),1);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::modelChanges()
 {
-    QQuickView *canvas = createView();
-    QTRY_VERIFY(canvas);
-    canvas->setSource(testFileUrl("propertychangestest.qml"));
+    QQuickView *window = createView();
+    QTRY_VERIFY(window);
+    window->setSource(testFileUrl("propertychangestest.qml"));
 
-    QQuickGridView *gridView = canvas->rootObject()->findChild<QQuickGridView*>("gridView");
+    QQuickGridView *gridView = window->rootObject()->findChild<QQuickGridView*>("gridView");
     QTRY_VERIFY(gridView);
 
-    QQuickListModel *alternateModel = canvas->rootObject()->findChild<QQuickListModel*>("alternateModel");
+    QQuickListModel *alternateModel = window->rootObject()->findChild<QQuickListModel*>("alternateModel");
     QTRY_VERIFY(alternateModel);
     QVariant modelVariant = QVariant::fromValue<QObject *>(alternateModel);
     QSignalSpy modelSpy(gridView, SIGNAL(modelChanged()));
@@ -2100,27 +2436,28 @@ void tst_QQuickGridView::modelChanges()
 
     gridView->setModel(QVariant());
     QTRY_COMPARE(modelSpy.count(),2);
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::positionViewAtIndex()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 40; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("testRightToLeft", QVariant(false));
     ctxt->setContextProperty("testTopToBottom", QVariant(false));
+    ctxt->setContextProperty("testBottomToTop", QVariant(false));
 
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("layouts.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
@@ -2281,7 +2618,7 @@ void tst_QQuickGridView::positionViewAtIndex()
     QTRY_COMPARE(gridview->contentX(), 0.);
 
     gridview->setContentX(80);
-    canvas->rootObject()->setProperty("showHeader", true);
+    window->rootObject()->setProperty("showHeader", true);
     gridview->positionViewAtBeginning();
     QTRY_COMPARE(gridview->contentX(), -30.);
 
@@ -2290,7 +2627,7 @@ void tst_QQuickGridView::positionViewAtIndex()
     QTRY_COMPARE(gridview->contentX(), 400.);   // 8*80 - 240   (8 columns)
 
     gridview->setContentX(80);
-    canvas->rootObject()->setProperty("showFooter", true);
+    window->rootObject()->setProperty("showFooter", true);
     gridview->positionViewAtEnd();
     QTRY_COMPARE(gridview->contentX(), 430.);
 
@@ -2302,26 +2639,22 @@ void tst_QQuickGridView::positionViewAtIndex()
     QVERIFY(gridview->highlightItem());
     QCOMPARE(gridview->highlightItem()->x(), 80.);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::snapping()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 40; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     gridview->setHeight(220);
@@ -2342,20 +2675,20 @@ void tst_QQuickGridView::snapping()
     gridview->positionViewAtIndex(15, QQuickGridView::End);
     QCOMPARE(gridview->contentY(), 120.);
 
-    delete canvas;
+    delete window;
 
 }
 
 void tst_QQuickGridView::mirroring()
 {
-    QQuickView *canvasA = createView();
-    canvasA->setSource(testFileUrl("mirroring.qml"));
-    QQuickGridView *gridviewA = findItem<QQuickGridView>(canvasA->rootObject(), "view");
+    QQuickView *windowA = createView();
+    windowA->setSource(testFileUrl("mirroring.qml"));
+    QQuickGridView *gridviewA = findItem<QQuickGridView>(windowA->rootObject(), "view");
     QTRY_VERIFY(gridviewA != 0);
 
-    QQuickView *canvasB = createView();
-    canvasB->setSource(testFileUrl("mirroring.qml"));
-    QQuickGridView *gridviewB = findItem<QQuickGridView>(canvasB->rootObject(), "view");
+    QQuickView *windowB = createView();
+    windowB->setSource(testFileUrl("mirroring.qml"));
+    QQuickGridView *gridviewB = findItem<QQuickGridView>(windowB->rootObject(), "view");
     QTRY_VERIFY(gridviewA != 0);
     qApp->processEvents();
 
@@ -2403,27 +2736,28 @@ void tst_QQuickGridView::mirroring()
     foreach (const QString objectName, objectNames)
         QCOMPARE(findItem<QQuickItem>(gridviewA, objectName)->x(), findItem<QQuickItem>(gridviewB, objectName)->x());
 
-    delete canvasA;
-    delete canvasB;
+    delete windowA;
+    delete windowB;
 }
 
 void tst_QQuickGridView::positionViewAtIndex_rightToLeft()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 40; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("testTopToBottom", QVariant(true));
     ctxt->setContextProperty("testRightToLeft", QVariant(true));
+    ctxt->setContextProperty("testBottomToTop", QVariant(false));
 
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->setSource(testFileUrl("layouts.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -2536,25 +2870,25 @@ void tst_QQuickGridView::positionViewAtIndex_rightToLeft()
     gridview->positionViewAtIndex(20, QQuickGridView::Contain);
     QTRY_COMPARE(gridview->contentX(), -560.);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::resetModel()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QStringList strings;
     strings << "one" << "two" << "three";
     QStringListModel model(strings);
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
 
-    canvas->setSource(testFileUrl("displaygrid.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("displaygrid.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
@@ -2580,28 +2914,28 @@ void tst_QQuickGridView::resetModel()
         QTRY_COMPARE(display->text(), strings.at(i));
     }
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::enforceRange()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("testRightToLeft", QVariant(false));
     ctxt->setContextProperty("testTopToBottom", QVariant(false));
 
-    canvas->setSource(testFileUrl("gridview-enforcerange.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("gridview-enforcerange.qml"));
+    window->show();
     qApp->processEvents();
-    QVERIFY(canvas->rootObject() != 0);
+    QVERIFY(window->rootObject() != 0);
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QTRY_COMPARE(gridview->preferredHighlightBegin(), 100.0);
@@ -2638,27 +2972,27 @@ void tst_QQuickGridView::enforceRange()
     ctxt->setContextProperty("testModel", &model2);
     QCOMPARE(gridview->count(), 5);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::enforceRange_rightToLeft()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("testRightToLeft", QVariant(true));
     ctxt->setContextProperty("testTopToBottom", QVariant(true));
 
-    canvas->setSource(testFileUrl("gridview-enforcerange.qml"));
+    window->setSource(testFileUrl("gridview-enforcerange.qml"));
     qApp->processEvents();
-    QVERIFY(canvas->rootObject() != 0);
+    QVERIFY(window->rootObject() != 0);
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QCOMPARE(gridview->preferredHighlightBegin(), 100.0);
@@ -2696,34 +3030,34 @@ void tst_QQuickGridView::enforceRange_rightToLeft()
     ctxt->setContextProperty("testModel", &model2);
     QCOMPARE(gridview->count(), 5);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::QTBUG_8456()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
-    canvas->setSource(testFileUrl("setindex.qml"));
+    window->setSource(testFileUrl("setindex.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QTRY_COMPARE(gridview->currentIndex(), 0);
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::manualHighlight()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QString filename(testFile("manual-highlight.qml"));
-    canvas->setSource(QUrl::fromLocalFile(filename));
+    window->setSource(QUrl::fromLocalFile(filename));
 
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -2748,8 +3082,8 @@ void tst_QQuickGridView::manualHighlight()
     QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y());
     QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x());
 
-    gridview->setFlow(QQuickGridView::TopToBottom);
-    QTRY_COMPARE(gridview->flow(), QQuickGridView::TopToBottom);
+    gridview->setFlow(QQuickGridView::FlowTopToBottom);
+    QTRY_COMPARE(gridview->flow(), QQuickGridView::FlowTopToBottom);
 
     gridview->setCurrentIndex(0);
     QTRY_COMPARE(gridview->currentIndex(), 0);
@@ -2757,7 +3091,7 @@ void tst_QQuickGridView::manualHighlight()
     QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y());
     QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x());
 
-    delete canvas;
+    delete window;
 }
 
 
@@ -2765,37 +3099,37 @@ void tst_QQuickGridView::footer()
 {
     QFETCH(QQuickGridView::Flow, flow);
     QFETCH(Qt::LayoutDirection, layoutDirection);
+    QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
     QFETCH(QPointF, initialFooterPos);
     QFETCH(QPointF, changedFooterPos);
     QFETCH(QPointF, initialContentPos);
-    QFETCH(QPointF, changedContentPos);
     QFETCH(QPointF, firstDelegatePos);
     QFETCH(QPointF, resizeContentPos);
 
-    QQuickView *canvas = createView();
-    canvas->show();
+    QQuickView *window = getView();
+    window->show();
 
     QaimModel model;
     for (int i = 0; i < 7; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
-
-    canvas->setSource(testFileUrl("footer.qml"));
+    window->setSource(testFileUrl("footer.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     gridview->setFlow(flow);
     gridview->setLayoutDirection(layoutDirection);
+    gridview->setVerticalLayoutDirection(verticalLayoutDirection);
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
 
     QQuickText *footer = findItem<QQuickText>(contentItem, "footer");
     QVERIFY(footer);
-
     QVERIFY(footer == gridview->footerItem());
 
     QCOMPARE(footer->pos(), initialFooterPos);
@@ -2803,14 +3137,22 @@ void tst_QQuickGridView::footer()
     QCOMPARE(footer->height(), 30.);
     QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
 
+    if (flow == QQuickGridView::FlowLeftToRight)
+        QCOMPARE(gridview->contentHeight(), (model.count()+2) / 3 * 60. + footer->height());
+    else
+        QCOMPARE(gridview->contentWidth(), (model.count()+3) / 5 * 80. + footer->width());
+
     QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", 0);
     QVERIFY(item);
     QCOMPARE(item->pos(), firstDelegatePos);
 
-    if (flow == QQuickGridView::LeftToRight) {
+    if (flow == QQuickGridView::FlowLeftToRight) {
         // shrink by one row
         model.removeItem(2);
-        QTRY_COMPARE(footer->y(), initialFooterPos.y() - gridview->cellHeight());
+        if (verticalLayoutDirection == QQuickItemView::TopToBottom)
+            QTRY_COMPARE(footer->y(), initialFooterPos.y() - gridview->cellHeight());
+        else
+            QTRY_COMPARE(footer->y(), initialFooterPos.y() + gridview->cellHeight());
     } else {
         // shrink by one column
         model.removeItem(2);
@@ -2823,24 +3165,30 @@ void tst_QQuickGridView::footer()
 
     // remove all items
     model.clear();
+    if (flow == QQuickGridView::FlowLeftToRight)
+        QTRY_COMPARE(gridview->contentHeight(), footer->height());
+    else
+        QTRY_COMPARE(gridview->contentWidth(), footer->width());
 
     QPointF posWhenNoItems(0, 0);
     if (layoutDirection == Qt::RightToLeft)
-        posWhenNoItems.setX(flow == QQuickGridView::LeftToRight ? gridview->width() - footer->width() : -footer->width());
+        posWhenNoItems.setX(flow == QQuickGridView::FlowLeftToRight ? gridview->width() - footer->width() : -footer->width());
+    if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+        posWhenNoItems.setY(-footer->height());
     QTRY_COMPARE(footer->pos(), posWhenNoItems);
 
-    // if header is present, it's at a negative pos, so the footer should not move
-    canvas->rootObject()->setProperty("showHeader", true);
+    // if header is toggled, it shouldn't affect the footer position
+    window->rootObject()->setProperty("showHeader", true);
     QVERIFY(findItem<QQuickItem>(contentItem, "header") != 0);
     QTRY_COMPARE(footer->pos(), posWhenNoItems);
-    canvas->rootObject()->setProperty("showHeader", false);
+    window->rootObject()->setProperty("showHeader", false);
 
     // add 30 items
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
     QSignalSpy footerItemSpy(gridview, SIGNAL(footerItemChanged()));
-    QMetaObject::invokeMethod(canvas->rootObject(), "changeFooter");
+    QMetaObject::invokeMethod(window->rootObject(), "changeFooter");
 
     QCOMPARE(footerItemSpy.count(), 1);
 
@@ -2848,13 +3196,14 @@ void tst_QQuickGridView::footer()
     QVERIFY(!footer);
     footer = findItem<QQuickText>(contentItem, "footer2");
     QVERIFY(footer);
-
     QVERIFY(footer == gridview->footerItem());
 
     QCOMPARE(footer->pos(), changedFooterPos);
     QCOMPARE(footer->width(), 50.);
     QCOMPARE(footer->height(), 20.);
-    QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), changedContentPos);
+
+    // changing the footer shouldn't change the content pos
+    QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
 
     item = findItem<QQuickItem>(contentItem, "wrapper", 0);
     QVERIFY(item);
@@ -2865,17 +3214,17 @@ void tst_QQuickGridView::footer()
     footer->setWidth(40);
     QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), resizeContentPos);
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::footer_data()
 {
     QTest::addColumn<QQuickGridView::Flow>("flow");
     QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+    QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
     QTest::addColumn<QPointF>("initialFooterPos");
     QTest::addColumn<QPointF>("changedFooterPos");
     QTest::addColumn<QPointF>("initialContentPos");
-    QTest::addColumn<QPointF>("changedContentPos");
     QTest::addColumn<QPointF>("firstDelegatePos");
     QTest::addColumn<QPointF>("resizeContentPos");
 
@@ -2886,46 +3235,104 @@ void tst_QQuickGridView::footer_data()
     // view height = 320
 
     // footer below items, bottom left
-    QTest::newRow("flow left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight
+    QTest::newRow("LeftToRight, LtR, TtB")
+        << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
         << QPointF(0, 3 * 60)  // 180 = height of 3 rows (cell height is 60)
         << QPointF(0, 10 * 60)  // 30 items = 10 rows
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(0, 0)
-        << QPointF(0, 10 * 60 - 320 + 10);
+        << QPointF(0, (10 * 60) - 320 + 10);
 
     // footer below items, bottom right
-    QTest::newRow("flow left to right, layout right to left") << QQuickGridView::LeftToRight << Qt::RightToLeft
+    QTest::newRow("LeftToRight, RtL, TtB")
+        << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
         << QPointF(240 - 100, 3 * 60)
         << QPointF((240 - 100) + 50, 10 * 60)     // 50 = width diff between old and new footers
         << QPointF(0, 0)
-        << QPointF(0, 0)
         << QPointF(240 - 80, 0)
-        << QPointF(0, 10 * 60 - 320 + 10);
-
-    // footer to right of items
-    QTest::newRow("flow top to bottom, layout left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight
+        << QPointF(0, (10 * 60) - 320 + 10);
+
+    // footer above items, top left
+    QTest::newRow("LeftToRight, LtR, BtT")
+        << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+        << QPointF(0, -(3 * 60) - 30)
+        << QPointF(0, -(10 * 60) - 20)
+        << QPointF(0, -320)
+        << QPointF(0, -60)
+        << QPointF(0, -(10 * 60) - 10);
+
+    // footer above items, top right
+    QTest::newRow("LeftToRight, RtL, BtT")
+        << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+        << QPointF(240 - 100, -(3 * 60) - 30)
+        << QPointF((240 - 100) + 50, -(10 * 60) - 20)
+        << QPointF(0, -320)
+        << QPointF(240 - 80, -60)
+        << QPointF(0, -(10 * 60) - 10);
+
+
+    // footer to right of items, bottom right
+    QTest::newRow("TopToBottom, LtR, TtB")
+        << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
         << QPointF(2 * 80, 0)      // 2 columns, cell width 80
         << QPointF(6 * 80, 0)      // 30 items = 6 columns
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(0, 0)
-        << QPointF(6 * 80 - 240 + 40, 0);
+        << QPointF((6 * 80) - 240 + 40, 0);
 
-    // footer to left of items
-    QTest::newRow("flow top to bottom, layout right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft
+    // footer to left of items, bottom right
+    QTest::newRow("TopToBottom, RtL, TtB")
+        << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
         << QPointF(-(2 * 80) - 100, 0)
         << QPointF(-(6 * 80) - 50, 0)     // 50 = new footer width
         << QPointF(-240, 0)
-        << QPointF(-240, 0)    // unchanged, footer change doesn't change content pos
         << QPointF(-80, 0)
         << QPointF(-(6 * 80) - 40, 0);
+
+    // footer to right of items, top right
+    QTest::newRow("TopToBottom, LtR, BtT")
+        << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+        << QPointF(2 * 80, -30)
+        << QPointF(6 * 80, -20)
+        << QPointF(0, -320)
+        << QPointF(0, -60)
+        << QPointF((6 * 80) - 240 + 40, -320);
+
+    // footer to left of items, top left
+    QTest::newRow("TopToBottom, RtL, BtT")
+        << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+        << QPointF(-(2 * 80) - 100, -30)
+        << QPointF(-(6 * 80) - 50, -20)
+        << QPointF(-240, -320)
+        << QPointF(-80, -60)
+        << QPointF(-(6 * 80) - 40, -320);
+}
+
+void tst_QQuickGridView::initialZValues()
+{
+    QQuickView *window = createView();
+    window->setSource(testFileUrl("initialZValues.qml"));
+    qApp->processEvents();
+
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
+    QTRY_VERIFY(gridview != 0);
+    QQuickItem *contentItem = gridview->contentItem();
+    QTRY_VERIFY(contentItem != 0);
+
+    QVERIFY(gridview->headerItem());
+    QTRY_COMPARE(gridview->headerItem()->z(), gridview->property("initialZ").toReal());
+
+    QVERIFY(gridview->footerItem());
+    QTRY_COMPARE(gridview->footerItem()->z(), gridview->property("initialZ").toReal());
+
+    delete window;
 }
 
 void tst_QQuickGridView::header()
 {
     QFETCH(QQuickGridView::Flow, flow);
     QFETCH(Qt::LayoutDirection, layoutDirection);
+    QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
     QFETCH(QPointF, initialHeaderPos);
     QFETCH(QPointF, changedHeaderPos);
     QFETCH(QPointF, initialContentPos);
@@ -2937,18 +3344,19 @@ void tst_QQuickGridView::header()
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQuickView *canvas = createView();
-    canvas->rootContext()->setContextProperty("testModel", &model);
-    canvas->rootContext()->setContextProperty("initialViewWidth", 240);
-    canvas->rootContext()->setContextProperty("initialViewHeight", 320);
-    canvas->setSource(testFileUrl("header.qml"));
-    canvas->show();
+    QQuickView *window = getView();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->rootContext()->setContextProperty("initialViewWidth", 240);
+    window->rootContext()->setContextProperty("initialViewHeight", 320);
+    window->setSource(testFileUrl("header.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     gridview->setFlow(flow);
     gridview->setLayoutDirection(layoutDirection);
+    gridview->setVerticalLayoutDirection(verticalLayoutDirection);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -2956,7 +3364,6 @@ void tst_QQuickGridView::header()
 
     QQuickText *header = findItem<QQuickText>(contentItem, "header");
     QVERIFY(header);
-
     QVERIFY(header == gridview->headerItem());
 
     QCOMPARE(header->pos(), initialHeaderPos);
@@ -2964,6 +3371,11 @@ void tst_QQuickGridView::header()
     QCOMPARE(header->height(), 30.);
     QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
 
+    if (flow == QQuickGridView::FlowLeftToRight)
+        QCOMPARE(gridview->contentHeight(), (model.count()+2) / 3 * 60. + header->height());
+    else
+        QCOMPARE(gridview->contentWidth(), (model.count()+3) / 5 * 80. + header->width());
+
     QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", 0);
     QVERIFY(item);
     QCOMPARE(item->pos(), firstDelegatePos);
@@ -2971,12 +3383,16 @@ void tst_QQuickGridView::header()
     model.clear();
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
     QCOMPARE(header->pos(), initialHeaderPos); // header should stay where it is
+    if (flow == QQuickGridView::FlowLeftToRight)
+        QCOMPARE(gridview->contentHeight(), header->height());
+    else
+        QCOMPARE(gridview->contentWidth(), header->width());
 
     for (int i = 0; i < 30; i++)
         model.addItem("Item" + QString::number(i), "");
 
     QSignalSpy headerItemSpy(gridview, SIGNAL(headerItemChanged()));
-    QMetaObject::invokeMethod(canvas->rootObject(), "changeHeader");
+    QMetaObject::invokeMethod(window->rootObject(), "changeHeader");
 
     QCOMPARE(headerItemSpy.count(), 1);
 
@@ -3000,23 +3416,24 @@ void tst_QQuickGridView::header()
     header->setWidth(40);
     QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), resizeContentPos);
 
-    delete canvas;
+    releaseView(window);
 
 
     // QTBUG-21207 header should become visible if view resizes from initial empty size
 
-    canvas = createView();
-    canvas->rootContext()->setContextProperty("testModel", &model);
-    canvas->rootContext()->setContextProperty("initialViewWidth", 240);
-    canvas->rootContext()->setContextProperty("initialViewHeight", 320);
-    canvas->setSource(testFileUrl("header.qml"));
-    canvas->show();
+    window = getView();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->rootContext()->setContextProperty("initialViewWidth", 240);
+    window->rootContext()->setContextProperty("initialViewHeight", 320);
+    window->setSource(testFileUrl("header.qml"));
+    window->show();
     qApp->processEvents();
 
-    gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     gridview->setFlow(flow);
     gridview->setLayoutDirection(layoutDirection);
+    gridview->setVerticalLayoutDirection(verticalLayoutDirection);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
     gridview->setWidth(240);
@@ -3024,13 +3441,14 @@ void tst_QQuickGridView::header()
     QTRY_COMPARE(gridview->headerItem()->pos(), initialHeaderPos);
     QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::header_data()
 {
     QTest::addColumn<QQuickGridView::Flow>("flow");
     QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+    QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
     QTest::addColumn<QPointF>("initialHeaderPos");
     QTest::addColumn<QPointF>("changedHeaderPos");
     QTest::addColumn<QPointF>("initialContentPos");
@@ -3044,7 +3462,8 @@ void tst_QQuickGridView::header_data()
     // view width = 240
 
     // header above items, top left
-    QTest::newRow("flow left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight
+    QTest::newRow("LeftToRight, LtR, TtB")
+        << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
         << QPointF(0, -30)
         << QPointF(0, -20)
         << QPointF(0, -30)
@@ -3053,7 +3472,8 @@ void tst_QQuickGridView::header_data()
         << QPointF(0, -10);
 
     // header above items, top right
-    QTest::newRow("flow left to right, layout right to left") << QQuickGridView::LeftToRight << Qt::RightToLeft
+    QTest::newRow("LeftToRight, RtL, TtB")
+        << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
         << QPointF(240 - 100, -30)
         << QPointF((240 - 100) + 50, -20)     // 50 = width diff between old and new headers
         << QPointF(0, -30)
@@ -3061,8 +3481,30 @@ void tst_QQuickGridView::header_data()
         << QPointF(160, 0)
         << QPointF(0, -10);
 
-    // header to left of items
-    QTest::newRow("flow top to bottom, layout left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight
+    // header below items, bottom left
+    QTest::newRow("LeftToRight, LtR, BtT")
+        << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+        << QPointF(0, 0)
+        << QPointF(0, 0)
+        << QPointF(0, -320 + 30)
+        << QPointF(0, -320 + 20)
+        << QPointF(0, -60)
+        << QPointF(0, -320 + 10);
+
+    // header above items, top right
+    QTest::newRow("LeftToRight, RtL, BtT")
+        << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+        << QPointF(240 - 100, 0)
+        << QPointF((240 - 100) + 50, 0)
+        << QPointF(0, -320 + 30)
+        << QPointF(0, -320 + 20)
+        << QPointF(160, -60)
+        << QPointF(0, -320 + 10);
+
+
+    // header to left of items, bottom left
+    QTest::newRow("TopToBottom, LtR, TtB")
+        << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
         << QPointF(-100, 0)
         << QPointF(-50, 0)
         << QPointF(-100, 0)
@@ -3070,35 +3512,228 @@ void tst_QQuickGridView::header_data()
         << QPointF(0, 0)
         << QPointF(-40, 0);
 
-    // header to right of items
-    QTest::newRow("flow top to bottom, layout right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft
+    // header to right of items, bottom right
+    QTest::newRow("TopToBottom, RtL, TtB")
+        << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
         << QPointF(0, 0)
         << QPointF(0, 0)
         << QPointF(-(240 - 100), 0)
         << QPointF(-(240 - 50), 0)
         << QPointF(-80, 0)
         << QPointF(-(240 - 40), 0);
+
+    // header to left of items, top left
+    QTest::newRow("TopToBottom, LtR, BtT")
+        << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+        << QPointF(-100, -30)
+        << QPointF(-50, -20)
+        << QPointF(-100, -320)
+        << QPointF(-50, -320)
+        << QPointF(0, -60)
+        << QPointF(-40, -320);
+
+    // header to right of items, top right
+    QTest::newRow("TopToBottom, RtL, BtT")
+        << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+        << QPointF(0, -30)
+        << QPointF(0, -20)
+        << QPointF(-(240 - 100), -320)
+        << QPointF(-(240 - 50), -320)
+        << QPointF(-80, -60)
+        << QPointF(-(240 - 40), -320);
+}
+
+class GVAccessor : public QQuickGridView
+{
+public:
+    qreal minY() const { return minYExtent(); }
+    qreal maxY() const { return maxYExtent(); }
+    qreal minX() const { return minXExtent(); }
+    qreal maxX() const { return maxXExtent(); }
+};
+
+void tst_QQuickGridView::extents()
+{
+    QFETCH(QQuickGridView::Flow, flow);
+    QFETCH(Qt::LayoutDirection, layoutDirection);
+    QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+    QFETCH(QPointF, headerPos);
+    QFETCH(QPointF, footerPos);
+    QFETCH(QPointF, minPos);
+    QFETCH(QPointF, maxPos);
+    QFETCH(QPointF, origin_empty);
+    QFETCH(QPointF, origin_nonEmpty);
+
+    QQuickView *window = getView();
+
+    QmlListModel model;
+    QQmlContext *ctxt = window->rootContext();
+    ctxt->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("headerfooter.qml"));
+    window->show();
+    qApp->processEvents();
+
+    QQuickGridView *gridview = qobject_cast<QQuickGridView*>(window->rootObject());
+    QTRY_VERIFY(gridview != 0);
+    gridview->setFlow(flow);
+    gridview->setLayoutDirection(layoutDirection);
+    gridview->setVerticalLayoutDirection(verticalLayoutDirection);
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+    QQuickItem *contentItem = gridview->contentItem();
+    QTRY_VERIFY(contentItem != 0);
+
+    QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
+    QVERIFY(header);
+    QCOMPARE(header->pos(), headerPos);
+
+    QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
+    QVERIFY(footer);
+    QCOMPARE(footer->pos(), footerPos);
+
+    QCOMPARE(static_cast<GVAccessor*>(gridview)->minX(), minPos.x());
+    QCOMPARE(static_cast<GVAccessor*>(gridview)->minY(), minPos.y());
+    QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), maxPos.x());
+    QCOMPARE(static_cast<GVAccessor*>(gridview)->maxY(), maxPos.y());
+
+    QCOMPARE(gridview->originX(), origin_empty.x());
+    QCOMPARE(gridview->originY(), origin_empty.y());
+    for (int i=0; i<30; i++)
+        model.addItem("Item" + QString::number(i), "");
+    QTRY_COMPARE(gridview->count(), model.count());
+    QCOMPARE(gridview->originX(), origin_nonEmpty.x());
+    QCOMPARE(gridview->originY(), origin_nonEmpty.y());
+
+    releaseView(window);
+}
+
+void tst_QQuickGridView::extents_data()
+{
+    QTest::addColumn<QQuickGridView::Flow>("flow");
+    QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+    QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+    QTest::addColumn<QPointF>("headerPos");
+    QTest::addColumn<QPointF>("footerPos");
+    QTest::addColumn<QPointF>("minPos");
+    QTest::addColumn<QPointF>("maxPos");
+    QTest::addColumn<QPointF>("origin_empty");
+    QTest::addColumn<QPointF>("origin_nonEmpty");
+
+    // header is 240x20 (or 20x320 in TopToBottom)
+    // footer is 240x30 (or 30x320 in TopToBottom)
+    // grid has 10 rows in LeftToRight mode and 6 columns in TopToBottom
+
+    QTest::newRow("LeftToRight, LtR, TtB")
+            << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
+            << QPointF(0, -20) << QPointF(0, 0)
+            << QPointF(0, 20) << QPointF(240, 20)
+            << QPointF(0, -20) << QPointF(0, -20);
+
+    QTest::newRow("LeftToRight, RtL, TtB")
+            << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
+            << QPointF(0, -20) << QPointF(0, 0)
+            << QPointF(0, 20) << QPointF(240, 20)
+            << QPointF(0, -20) << QPointF(0, -20);
+
+    QTest::newRow("LeftToRight, LtR, BtT")
+            << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+            << QPointF(0, 0) << QPointF(0, -30)
+            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20)  // content flow is reversed
+            << QPointF(0, -30) << QPointF(0, (-60.0 * 10) - 30);
+
+    QTest::newRow("LeftToRight, RtL, BtT")
+            << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+            << QPointF(0, 0) << QPointF(0, -30)
+            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20)  // content flow is reversed
+            << QPointF(0, -30) << QPointF(0, (-60.0 * 10) - 30);
+
+
+    QTest::newRow("TopToBottom, LtR, TtB")
+            << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
+            << QPointF(-20, 0) << QPointF(0, 0)
+            << QPointF(20, 0) << QPointF(20, 320)
+            << QPointF(-20, 0) << QPointF(-20, 0);
+
+    QTest::newRow("TopToBottom, RtL, TtB")
+            << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
+            << QPointF(0, 0) << QPointF(-30, 0)
+            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320)  // content flow is reversed
+            << QPointF(-30, 0) << QPointF((-80.0 * 6) - 30, 0);
+
+    QTest::newRow("TopToBottom, LtR, BtT")
+            << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+            << QPointF(-20, -320) << QPointF(0, -320)
+            << QPointF(20, 0) << QPointF(20, 320)
+            << QPointF(-20, 0) << QPointF(-20, 0);
+
+    QTest::newRow("TopToBottom, RtL, BtT")
+            << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+            << QPointF(0, -320) << QPointF(-30, -320)
+            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320)  // content flow is reversed
+            << QPointF(-30, 0) << QPointF((-80.0 * 6) - 30, 0);
+}
+
+void tst_QQuickGridView::resetModel_headerFooter()
+{
+    // Resetting a model shouldn't crash in views with header/footer
+
+    QQuickView *window = createView();
+
+    QaimModel model;
+    for (int i = 0; i < 6; i++)
+        model.addItem("Item" + QString::number(i), "");
+    QQmlContext *ctxt = window->rootContext();
+    ctxt->setContextProperty("testModel", &model);
+
+    window->setSource(testFileUrl("headerfooter.qml"));
+    qApp->processEvents();
+
+    QQuickGridView *gridview = qobject_cast<QQuickGridView*>(window->rootObject());
+    QTRY_VERIFY(gridview != 0);
+
+    QQuickItem *contentItem = gridview->contentItem();
+    QTRY_VERIFY(contentItem != 0);
+
+    QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
+    QVERIFY(header);
+    QCOMPARE(header->y(), -header->height());
+
+    QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
+    QVERIFY(footer);
+    QCOMPARE(footer->y(), 60.*2);
+
+    model.reset();
+
+    header = findItem<QQuickItem>(contentItem, "header");
+    QVERIFY(header);
+    QCOMPARE(header->y(), -header->height());
+
+    footer = findItem<QQuickItem>(contentItem, "footer");
+    QVERIFY(footer);
+    QCOMPARE(footer->y(), 60.*2);
+
+    delete window;
 }
 
 void tst_QQuickGridView::resizeViewAndRepaint()
 {
-    QQuickView *canvas = createView();
-    canvas->show();
+    QQuickView *window = createView();
+    window->show();
 
     QaimModel model;
     for (int i = 0; i < 40; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("initialWidth", 240);
     ctxt->setContextProperty("initialHeight", 100);
 
-    canvas->setSource(testFileUrl("resizeview.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("resizeview.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
@@ -3131,42 +3766,183 @@ void tst_QQuickGridView::resizeViewAndRepaint()
         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
+        QCOMPARE(delegateVisible(item), i < 9); // inside view visible, outside not visible
+    }
+
+    // ensure items outside view become invisible
+    gridview->setHeight(60);
+    QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 12);
+
+    itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count();
+    for (int i = 0; i < model.count() && i < itemCount; ++i) {
+        QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+        if (!item) qWarning() << "Item" << i << "not found";
+        QTRY_VERIFY(item);
+        QTRY_COMPARE(item->x(), qreal((i%3)*80));
+        QTRY_COMPARE(item->y(), qreal((i/3)*60));
+        QCOMPARE(delegateVisible(item), i < 6); // inside view visible, outside not visible
+    }
+
+    delete window;
+}
+
+void tst_QQuickGridView::resizeGrid()
+{
+    QFETCH(QQuickGridView::Flow, flow);
+    QFETCH(Qt::LayoutDirection, layoutDirection);
+    QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+    QFETCH(QPointF, initialContentPos);
+    QFETCH(QPointF, firstItemPos);
+
+    QaimModel model;
+    for (int i = 0; i < 30; i++)
+        model.addItem("Item" + QString::number(i), "");
+
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
+    ctxt->setContextProperty("testModel", &model);
+    ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+    ctxt->setContextProperty("testRightToLeft", layoutDirection == Qt::RightToLeft);
+    ctxt->setContextProperty("testBottomToTop", verticalLayoutDirection == QQuickGridView::BottomToTop);
+    window->setSource(testFileUrl("resizegrid.qml"));
+    window->show();
+    qApp->processEvents();
+
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
+    QTRY_VERIFY(gridview != 0);
+    QQuickItem *contentItem = gridview->contentItem();
+    QTRY_VERIFY(contentItem != 0);
+
+    // set the width to slightly larger than 3 items across, to test
+    // items are aligned correctly in right-to-left
+    window->rootObject()->setWidth(260);
+    window->rootObject()->setHeight(320);
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+    QCOMPARE(gridview->contentX(), initialContentPos.x());
+    QCOMPARE(gridview->contentY(), initialContentPos.y());
+
+    QQuickItem *item0 = findItem<QQuickItem>(contentItem, "wrapper", 0);
+    QVERIFY(item0);
+    QCOMPARE(item0->pos(), firstItemPos);
+
+    // Confirm items positioned correctly and indexes correct
+    QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+    QVERIFY(items.count() >= 18 && items.count() <= 21);
+    for (int i = 0; i < model.count() && i < items.count(); ++i) {
+        QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+        QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
+        QCOMPARE(item->pos(), expectedItemPos(gridview, i, 0));
+        QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
+        QVERIFY(name != 0);
+        QCOMPARE(name->text(), model.name(i));
     }
 
-    // ensure items outside view become invisible
-    gridview->setHeight(60);
-    QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 12);
+    // change from 3x5 grid to 4x7
+    window->rootObject()->setWidth(window->rootObject()->width() + 80);
+    window->rootObject()->setHeight(window->rootObject()->height() + 60*2);
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
-    itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count();
-    for (int i = 0; i < model.count() && i < itemCount; ++i) {
+    // other than in LeftToRight+RightToLeft layout, the first item should not move
+    // if view is resized
+    QCOMPARE(findItem<QQuickItem>(contentItem, "wrapper", 0), item0);
+    if (flow == QQuickGridView::FlowLeftToRight && layoutDirection == Qt::RightToLeft)
+        firstItemPos.rx() += 80;
+    QCOMPARE(item0->pos(), firstItemPos);
+
+    QPointF newContentPos = initialContentPos;
+    if (flow == QQuickGridView::FlowTopToBottom && layoutDirection == Qt::RightToLeft)
+        newContentPos.rx() -= 80.0;
+    if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+        newContentPos.ry() -= 60.0 * 2;
+    QCOMPARE(gridview->contentX(), newContentPos.x());
+    QCOMPARE(gridview->contentY(), newContentPos.y());
+
+    // Confirm items positioned correctly and indexes correct
+    items = findItems<QQuickItem>(contentItem, "wrapper");
+    QVERIFY(items.count() >= 28);
+    for (int i = 0; i < model.count() && i < items.count(); ++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
+        QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
+        QCOMPARE(item->pos(), expectedItemPos(gridview, i, 0));
+        QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
+        QVERIFY(name != 0);
+        QCOMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
+}
+
+void tst_QQuickGridView::resizeGrid_data()
+{
+    QTest::addColumn<QQuickGridView::Flow>("flow");
+    QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+    QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+    QTest::addColumn<QPointF>("initialContentPos");
+    QTest::addColumn<QPointF>("firstItemPos");
+
+    // Initial view width is 260, so in LeftToRight + right-to-left mode the
+    // content x should be -20
+
+    QTest::newRow("LeftToRight, LtR, TtB")
+            << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
+            << QPointF(0, 0)
+            << QPointF(0, 0);
+
+    QTest::newRow("LeftToRight, RtL, TtB")
+            << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
+            << QPointF(-20.0, 0)
+            << QPointF(80.0 * 2, 0);
+
+    QTest::newRow("LeftToRight, LtR, BtT")
+            << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+            << QPointF(0, -320)
+            << QPointF(0, -60.0);
+
+    QTest::newRow("LeftToRight, RtL, BtT")
+            << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+            << QPointF(-20.0, -320)
+            << QPointF(80.0 * 2, -60.0);
+
+
+    QTest::newRow("TopToBottom, LtR, TtB")
+            << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
+            << QPointF(0, 0)
+            << QPointF(0, 0);
+
+    QTest::newRow("TopToBottom, RtL, TtB")
+            << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
+            << QPointF(-260, 0)
+            << QPointF(-80.0, 0);
+
+    QTest::newRow("TopToBottom, LtR, BtT")
+            << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+            << QPointF(0, -320)
+            << QPointF(0, -60.0);
+
+    QTest::newRow("TopToBottom, RtL, BtT")
+            << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+            << QPointF(-260, -320)
+            << QPointF(-80.0, -60.0);
 }
 
+
 void tst_QQuickGridView::changeColumnCount()
 {
     QmlListModel model;
     for (int i = 0; i < 40; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = createView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("initialWidth", 100);
     ctxt->setContextProperty("initialHeight", 320);
-    canvas->setSource(testFileUrl("resizeview.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("resizeview.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QTRY_VERIFY(contentItem != 0);
@@ -3206,7 +3982,7 @@ void tst_QQuickGridView::changeColumnCount()
         QCOMPARE(item->y(), qreal(i*60));
     }
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::indexAt_itemAt_data()
@@ -3228,7 +4004,7 @@ void tst_QQuickGridView::indexAt_itemAt()
     QFETCH(qreal, y);
     QFETCH(int, index);
 
-    QQuickView *canvas = createView();
+    QQuickView *window = getView();
 
     QaimModel model;
     model.addItem("Fred", "12345");
@@ -3239,15 +4015,11 @@ void tst_QQuickGridView::indexAt_itemAt()
     model.addItem("Ben", "04321");
     model.addItem("Jim", "0780");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -3263,7 +4035,7 @@ void tst_QQuickGridView::indexAt_itemAt()
     QCOMPARE(gridview->indexAt(x, y), index);
     QVERIFY(gridview->itemAt(x, y) == item);
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::onAdd()
@@ -3274,22 +4046,22 @@ void tst_QQuickGridView::onAdd()
     const int delegateWidth = 50;
     const int delegateHeight = 100;
     QaimModel model;
-    QQuickView *canvas = createView();
-    canvas->setGeometry(0,0,5 * delegateWidth, 5 * delegateHeight); // just ensure all items fit
+    QQuickView *window = getView();
+    window->setGeometry(0,0,5 * delegateWidth, 5 * delegateHeight); // just ensure all items fit
 
     // these initial items should not trigger GridView.onAdd
     for (int i=0; i<initialItemCount; i++)
         model.addItem("dummy value", "dummy value");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("delegateWidth", delegateWidth);
     ctxt->setContextProperty("delegateHeight", delegateHeight);
-    canvas->setSource(testFileUrl("attachedSignals.qml"));
+    window->setSource(testFileUrl("attachedSignals.qml"));
 
-    QObject *object = canvas->rootObject();
-    object->setProperty("width", canvas->width());
-    object->setProperty("height", canvas->height());
+    QObject *object = window->rootObject();
+    object->setProperty("width", window->width());
+    object->setProperty("height", window->height());
     qApp->processEvents();
 
     QList<QPair<QString, QString> > items;
@@ -3297,7 +4069,7 @@ void tst_QQuickGridView::onAdd()
         items << qMakePair(QString("value %1").arg(i), QString::number(i));
     model.addItems(items);
 
-    QTRY_COMPARE(model.count(), qobject_cast<QQuickGridView*>(canvas->rootObject())->count());
+    QTRY_COMPARE(model.count(), qobject_cast<QQuickGridView*>(window->rootObject())->count());
     qApp->processEvents();
 
     QVariantList result = object->property("addedDelegates").toList();
@@ -3305,7 +4077,7 @@ void tst_QQuickGridView::onAdd()
     for (int i=0; i<items.count(); i++)
         QCOMPARE(result[i].toString(), items[i].first);
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::onAdd_data()
@@ -3338,19 +4110,19 @@ void tst_QQuickGridView::onRemove()
     for (int i=0; i<initialItemCount; i++)
         model.addItem(QString("value %1").arg(i), "dummy value");
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("delegateWidth", delegateWidth);
     ctxt->setContextProperty("delegateHeight", delegateHeight);
-    canvas->setSource(testFileUrl("attachedSignals.qml"));
-    QObject *object = canvas->rootObject();
+    window->setSource(testFileUrl("attachedSignals.qml"));
+    QObject *object = window->rootObject();
 
     model.removeItems(indexToRemove, removeCount);
-    QTRY_COMPARE(model.count(), qobject_cast<QQuickGridView*>(canvas->rootObject())->count());
+    QTRY_COMPARE(model.count(), qobject_cast<QQuickGridView*>(window->rootObject())->count());
     QCOMPARE(object->property("removedDelegateCount"), QVariant(removeCount));
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::onRemove_data()
@@ -3378,13 +4150,13 @@ void tst_QQuickGridView::onRemove_data()
 
 void tst_QQuickGridView::columnCount()
 {
-    QQuickView canvas;
-    canvas.setSource(testFileUrl("gridview4.qml"));
-    canvas.show();
-    canvas.requestActivateWindow();
-    QTest::qWaitForWindowShown(&canvas);
+    QQuickView window;
+    window.setSource(testFileUrl("gridview4.qml"));
+    window.show();
+    window.requestActivateWindow();
+    QTest::qWaitForWindowShown(&window);
 
-    QQuickGridView *view = qobject_cast<QQuickGridView*>(canvas.rootObject());
+    QQuickGridView *view = qobject_cast<QQuickGridView*>(window.rootObject());
 
     QCOMPARE(view->cellWidth(), qreal(405)/qreal(9));
     QCOMPARE(view->cellHeight(), qreal(100));
@@ -3398,28 +4170,28 @@ void tst_QQuickGridView::columnCount()
 void tst_QQuickGridView::margins()
 {
     {
-        QQuickView *canvas = createView();
+        QQuickView *window = createView();
 
         QaimModel model;
         for (int i = 0; i < 40; i++)
             model.addItem("Item" + QString::number(i), "");
 
-        QQmlContext *ctxt = canvas->rootContext();
+        QQmlContext *ctxt = window->rootContext();
         ctxt->setContextProperty("testModel", &model);
         ctxt->setContextProperty("testRightToLeft", QVariant(false));
 
-        canvas->setSource(testFileUrl("margins.qml"));
-        canvas->show();
+        window->setSource(testFileUrl("margins.qml"));
+        window->show();
         qApp->processEvents();
 
-        QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+        QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
         QTRY_VERIFY(gridview != 0);
         QQuickItem *contentItem = gridview->contentItem();
         QTRY_VERIFY(contentItem != 0);
         QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
         QCOMPARE(gridview->contentX(), -30.);
-        QCOMPARE(gridview->xOrigin(), 0.);
+        QCOMPARE(gridview->originX(), 0.);
 
         // check end bound
         gridview->positionViewAtEnd();
@@ -3429,23 +4201,23 @@ void tst_QQuickGridView::margins()
         QTRY_COMPARE(gridview->contentX(), pos + 50);
 
         // remove item before visible and check that left margin is maintained
-        // and xOrigin is updated
+        // and originX is updated
         gridview->setContentX(200);
         model.removeItems(0, 4);
         QTest::qWait(100);
         gridview->setContentX(-50);
         gridview->returnToBounds();
-        QCOMPARE(gridview->xOrigin(), 100.);
+        QCOMPARE(gridview->originX(), 100.);
         QTRY_COMPARE(gridview->contentX(), 70.);
 
         // reduce left margin
         gridview->setLeftMargin(20);
-        QCOMPARE(gridview->xOrigin(), 100.);
+        QCOMPARE(gridview->originX(), 100.);
         QTRY_COMPARE(gridview->contentX(), 80.);
 
         // check end bound
         gridview->positionViewAtEnd();
-        QCOMPARE(gridview->xOrigin(), 0.); // positionViewAtEnd() resets origin
+        QCOMPARE(gridview->originX(), 0.); // positionViewAtEnd() resets origin
         pos = gridview->contentX();
         gridview->setContentX(pos + 80);
         gridview->returnToBounds();
@@ -3454,90 +4226,91 @@ void tst_QQuickGridView::margins()
         // reduce right margin
         pos = gridview->contentX();
         gridview->setRightMargin(40);
-        QCOMPARE(gridview->xOrigin(), 0.);
+        QCOMPARE(gridview->originX(), 0.);
         QTRY_COMPARE(gridview->contentX(), pos-10);
 
-        delete canvas;
+        delete window;
     }
     {
         //RTL
-        QQuickView *canvas = createView();
-        canvas->show();
+        QQuickView *window = createView();
+        window->show();
 
         QaimModel model;
         for (int i = 0; i < 40; i++)
             model.addItem("Item" + QString::number(i), "");
 
-        QQmlContext *ctxt = canvas->rootContext();
+        QQmlContext *ctxt = window->rootContext();
         ctxt->setContextProperty("testModel", &model);
         ctxt->setContextProperty("testRightToLeft", QVariant(true));
 
-        canvas->setSource(testFileUrl("margins.qml"));
+        window->setSource(testFileUrl("margins.qml"));
         qApp->processEvents();
 
-        QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+        QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
         QTRY_VERIFY(gridview != 0);
 
         QQuickItem *contentItem = gridview->contentItem();
         QTRY_VERIFY(contentItem != 0);
 
-        QCOMPARE(gridview->contentX(), -240+30.);
-        QCOMPARE(gridview->xOrigin(), 0.);
+        QTRY_COMPARE(gridview->contentX(), -240+50.);
+        QTRY_COMPARE(gridview->originX(), -100. * 10);
 
         // check end bound
         gridview->positionViewAtEnd();
         qreal pos = gridview->contentX();
         gridview->setContentX(pos - 80);
         gridview->returnToBounds();
-        QTRY_COMPARE(gridview->contentX(), pos - 50);
+        QTRY_COMPARE(gridview->contentX(), pos - 30);
 
         // remove item before visible and check that left margin is maintained
-        // and xOrigin is updated
+        // and originX is updated
         gridview->setContentX(-400);
+        QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
         model.removeItems(0, 4);
-        QTest::qWait(100);
+        QTRY_COMPARE(model.count(), gridview->count());
         gridview->setContentX(-240+50);
         gridview->returnToBounds();
-        QCOMPARE(gridview->xOrigin(), -100.);
-        QTRY_COMPARE(gridview->contentX(), -240-70.);
+        QCOMPARE(gridview->originX(), -1000.);
+        QTRY_COMPARE(gridview->contentX(), -240-50.);
 
-        // reduce left margin (i.e. right side due to RTL)
+        // reduce right margin
         pos = gridview->contentX();
-        gridview->setLeftMargin(20);
-        QCOMPARE(gridview->xOrigin(), -100.);
-        QTRY_COMPARE(gridview->contentX(), -240-80.);
+        gridview->setRightMargin(40);
+        QCOMPARE(gridview->originX(), -1000.);
+        QTRY_COMPARE(gridview->contentX(), -240-100 + 40.);
 
         // check end bound
         gridview->positionViewAtEnd();
-        QCOMPARE(gridview->xOrigin(), 0.); // positionViewAtEnd() resets origin
+        QCOMPARE(gridview->originX(), -900.); // positionViewAtEnd() resets origin
         pos = gridview->contentX();
         gridview->setContentX(pos - 80);
         gridview->returnToBounds();
-        QTRY_COMPARE(gridview->contentX(), pos - 50);
+        QTRY_COMPARE(gridview->contentX(), pos - 30);
 
-        // reduce right margin (i.e. left side due to RTL)
+        // reduce left margin
         pos = gridview->contentX();
-        gridview->setRightMargin(40);
-        QCOMPARE(gridview->xOrigin(), 0.);
+        gridview->setLeftMargin(20);
+        QCOMPARE(gridview->originX(), -900.);
         QTRY_COMPARE(gridview->contentX(), pos+10);
 
-        delete canvas;
+        delete window;
     }
 }
 
 void tst_QQuickGridView::creationContext()
 {
-    QQuickView canvas;
-    canvas.setGeometry(0,0,240,320);
-    canvas.setSource(testFileUrl("creationContext.qml"));
+    QQuickView window;
+    window.setGeometry(0,0,240,320);
+    window.setSource(testFileUrl("creationContext.qml"));
     qApp->processEvents();
 
-    QQuickItem *rootItem = qobject_cast<QQuickItem *>(canvas.rootObject());
+    QQuickItem *rootItem = qobject_cast<QQuickItem *>(window.rootObject());
     QVERIFY(rootItem);
     QVERIFY(rootItem->property("count").toInt() > 0);
 
     QQuickItem *item;
-    QVERIFY(item = rootItem->findChild<QQuickItem *>("listItem"));
+    QVERIFY(item = findItem<QQuickItem>(rootItem, "listItem"));
     QCOMPARE(item->property("text").toString(), QString("Hello!"));
     QVERIFY(item = rootItem->findChild<QQuickItem *>("header"));
     QCOMPARE(item->property("text").toString(), QString("Hello!"));
@@ -3556,23 +4329,23 @@ void tst_QQuickGridView::snapToRow_data()
     QTest::addColumn<qreal>("endExtent");
     QTest::addColumn<qreal>("startExtent");
 
-    QTest::newRow("vertical, left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
-        << QPoint(20, 200) << QPoint(20, 20) << 60.0 << 1200.0 << 0.0;
+    QTest::newRow("vertical, left to right") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+        << QPoint(20, 200) << QPoint(20, 20) << 60.0 << 800.0 << 0.0;
 
-    QTest::newRow("horizontal, left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
-        << QPoint(200, 20) << QPoint(20, 20) << 60.0 << 1200.0 << 0.0;
+    QTest::newRow("horizontal, left to right") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+        << QPoint(200, 20) << QPoint(20, 20) << 60.0 << 800.0 << 0.0;
 
-    QTest::newRow("horizontal, right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
-        << QPoint(20, 20) << QPoint(200, 20) << -60.0 << -1200.0 - 240.0 << -240.0;
+    QTest::newRow("horizontal, right to left") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
+        << QPoint(20, 20) << QPoint(200, 20) << -60.0 << -800.0 - 240.0 << -240.0;
 
-    QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
-        << QPoint(20, 200) << QPoint(20, 20) << 60.0 << 1340.0 << -20.0;
+    QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+        << QPoint(20, 200) << QPoint(20, 20) << 60.0 << 940.0 << -20.0;
 
-    QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
-        << QPoint(200, 20) << QPoint(20, 20) << 60.0 << 1340.0 << -20.0;
+    QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+        << QPoint(200, 20) << QPoint(20, 20) << 60.0 << 940.0 << -20.0;
 
-    QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
-        << QPoint(20, 20) << QPoint(200, 20) << -60.0 << -1200.0 - 240.0 - 140.0 << -220.0;
+    QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
+        << QPoint(20, 20) << QPoint(200, 20) << -60.0 << -800.0 - 240.0 - 140.0 << -220.0;
 }
 
 void tst_QQuickGridView::snapToRow()
@@ -3586,13 +4359,13 @@ void tst_QQuickGridView::snapToRow()
     QFETCH(qreal, endExtent);
     QFETCH(qreal, startExtent);
 
-    QQuickView *canvas = createView();
+    QQuickView *window = getView();
 
-    canvas->setSource(testFileUrl("snapToRow.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("snapToRow.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     gridview->setFlow(flow);
@@ -3604,40 +4377,40 @@ void tst_QQuickGridView::snapToRow()
     QTRY_VERIFY(contentItem != 0);
 
     // confirm that a flick hits an item boundary
-    flick(canvas, flickStart, flickEnd, 180);
+    flick(window, flickStart, flickEnd, 180);
     QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
-    if (flow == QQuickGridView::LeftToRight)
+    if (flow == QQuickGridView::FlowLeftToRight)
         QCOMPARE(qreal(fmod(gridview->contentY(),80.0)), snapAlignment);
     else
         QCOMPARE(qreal(fmod(gridview->contentX(),80.0)), snapAlignment);
 
     // flick to end
     do {
-        flick(canvas, flickStart, flickEnd, 180);
+        flick(window, flickStart, flickEnd, 180);
         QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
-    } while (flow == QQuickGridView::LeftToRight
+    } while (flow == QQuickGridView::FlowLeftToRight
            ? !gridview->isAtYEnd()
            : layoutDirection == Qt::LeftToRight ? !gridview->isAtXEnd() : !gridview->isAtXBeginning());
 
-    if (flow == QQuickGridView::LeftToRight)
+    if (flow == QQuickGridView::FlowLeftToRight)
         QCOMPARE(gridview->contentY(), endExtent);
     else
         QCOMPARE(gridview->contentX(), endExtent);
 
     // flick to start
     do {
-        flick(canvas, flickEnd, flickStart, 180);
+        flick(window, flickEnd, flickStart, 180);
         QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
-    } while (flow == QQuickGridView::LeftToRight
+    } while (flow == QQuickGridView::FlowLeftToRight
            ? !gridview->isAtYBeginning()
            : layoutDirection == Qt::LeftToRight ? !gridview->isAtXBeginning() : !gridview->isAtXEnd());
 
-    if (flow == QQuickGridView::LeftToRight)
+    if (flow == QQuickGridView::FlowLeftToRight)
         QCOMPARE(gridview->contentY(), startExtent);
     else
         QCOMPARE(gridview->contentX(), startExtent);
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::snapOneRow_data()
@@ -3651,23 +4424,23 @@ void tst_QQuickGridView::snapOneRow_data()
     QTest::addColumn<qreal>("endExtent");
     QTest::addColumn<qreal>("startExtent");
 
-    QTest::newRow("vertical, left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
-        << QPoint(20, 200) << QPoint(20, 20) << 100.0 << 360.0 << 0.0;
+    QTest::newRow("vertical, left to right") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+        << QPoint(20, 200) << QPoint(20, 20) << 100.0 << 240.0 << 0.0;
 
-    QTest::newRow("horizontal, left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
-        << QPoint(200, 20) << QPoint(20, 20) << 100.0 << 360.0 << 0.0;
+    QTest::newRow("horizontal, left to right") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+        << QPoint(200, 20) << QPoint(20, 20) << 100.0 << 240.0 << 0.0;
 
-    QTest::newRow("horizontal, right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
-        << QPoint(20, 20) << QPoint(200, 20) << -340.0 << -360.0 - 240.0 << -240.0;
+    QTest::newRow("horizontal, right to left") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
+        << QPoint(20, 20) << QPoint(200, 20) << -340.0 << -240.0 - 240.0 << -240.0;
 
-    QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
-        << QPoint(20, 200) << QPoint(20, 20) << 100.0 << 460.0 << -20.0;
+    QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+        << QPoint(20, 200) << QPoint(20, 20) << 100.0 << 340.0 << -20.0;
 
-    QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
-        << QPoint(200, 20) << QPoint(20, 20) << 100.0 << 460.0 << -20.0;
+    QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+        << QPoint(200, 20) << QPoint(20, 20) << 100.0 << 340.0 << -20.0;
 
-    QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
-        << QPoint(20, 20) << QPoint(200, 20) << -340.0 << -360.0 - 240.0 - 100.0 << -220.0;
+    QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
+        << QPoint(20, 20) << QPoint(200, 20) << -340.0 << -240.0 - 240.0 - 100.0 << -220.0;
 }
 
 void tst_QQuickGridView::snapOneRow()
@@ -3681,13 +4454,13 @@ void tst_QQuickGridView::snapOneRow()
     QFETCH(qreal, endExtent);
     QFETCH(qreal, startExtent);
 
-    QQuickView *canvas = createView();
+    QQuickView *window = getView();
 
-    canvas->setSource(testFileUrl("snapOneRow.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("snapOneRow.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
 
     gridview->setFlow(flow);
@@ -3701,9 +4474,9 @@ void tst_QQuickGridView::snapOneRow()
     QSignalSpy currentIndexSpy(gridview, SIGNAL(currentIndexChanged()));
 
     // confirm that a flick hits next row boundary
-    flick(canvas, flickStart, flickEnd, 180);
+    flick(window, flickStart, flickEnd, 180);
     QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
-    if (flow == QQuickGridView::LeftToRight)
+    if (flow == QQuickGridView::FlowLeftToRight)
         QCOMPARE(gridview->contentY(), snapAlignment);
     else
         QCOMPARE(gridview->contentX(), snapAlignment);
@@ -3715,60 +4488,60 @@ void tst_QQuickGridView::snapOneRow()
 
     // flick to end
     do {
-        flick(canvas, flickStart, flickEnd, 180);
+        flick(window, flickStart, flickEnd, 180);
         QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
-    } while (flow == QQuickGridView::LeftToRight
+    } while (flow == QQuickGridView::FlowLeftToRight
            ? !gridview->isAtYEnd()
            : layoutDirection == Qt::LeftToRight ? !gridview->isAtXEnd() : !gridview->isAtXBeginning());
 
     if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) {
-        QCOMPARE(gridview->currentIndex(), 8);
-        QCOMPARE(currentIndexSpy.count(), 4);
+        QCOMPARE(gridview->currentIndex(), 6);
+        QCOMPARE(currentIndexSpy.count(), 3);
     }
 
-    if (flow == QQuickGridView::LeftToRight)
+    if (flow == QQuickGridView::FlowLeftToRight)
         QCOMPARE(gridview->contentY(), endExtent);
     else
         QCOMPARE(gridview->contentX(), endExtent);
 
     // flick to start
     do {
-        flick(canvas, flickEnd, flickStart, 180);
+        flick(window, flickEnd, flickStart, 180);
         QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
-    } while (flow == QQuickGridView::LeftToRight
+    } while (flow == QQuickGridView::FlowLeftToRight
            ? !gridview->isAtYBeginning()
            : layoutDirection == Qt::LeftToRight ? !gridview->isAtXBeginning() : !gridview->isAtXEnd());
 
-    if (flow == QQuickGridView::LeftToRight)
+    if (flow == QQuickGridView::FlowLeftToRight)
         QCOMPARE(gridview->contentY(), startExtent);
     else
         QCOMPARE(gridview->contentX(), startExtent);
 
     if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) {
         QCOMPARE(gridview->currentIndex(), 0);
-        QCOMPARE(currentIndexSpy.count(), 8);
+        QCOMPARE(currentIndexSpy.count(), 6);
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 
 void tst_QQuickGridView::unaligned()
 {
-    QQuickView *canvas = createView();
-    canvas->show();
+    QQuickView *window = createView();
+    window->show();
 
     QaimModel model;
     for (int i = 0; i < 10; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
 
-    canvas->setSource(testFileUrl("unaligned.qml"));
+    window->setSource(testFileUrl("unaligned.qml"));
     qApp->processEvents();
 
-    QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
+    QQuickGridView *gridview = qobject_cast<QQuickGridView*>(window->rootObject());
     QVERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -3810,7 +4583,7 @@ void tst_QQuickGridView::unaligned()
         QCOMPARE(item->y(), qreal(i/9)*gridview->cellHeight());
     }
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::populateTransitions()
@@ -3830,56 +4603,56 @@ void tst_QQuickGridView::populateTransitions()
             model.addItem("item" + QString::number(i), "");
     }
 
-    QQuickView *canvas = createView();
-    canvas->rootContext()->setContextProperty("testModel", &model);
-    canvas->rootContext()->setContextProperty("usePopulateTransition", usePopulateTransition);
-    canvas->rootContext()->setContextProperty("dynamicallyPopulate", dynamicallyPopulate);
-    canvas->rootContext()->setContextProperty("transitionFrom", transitionFrom);
-    canvas->rootContext()->setContextProperty("transitionVia", transitionVia);
-    canvas->rootContext()->setContextProperty("model_transitionFrom", &model_transitionFrom);
-    canvas->rootContext()->setContextProperty("model_transitionVia", &model_transitionVia);
-    canvas->setSource(testFileUrl("populateTransitions.qml"));
-    canvas->show();
-
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickView *window = getView();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->rootContext()->setContextProperty("usePopulateTransition", usePopulateTransition);
+    window->rootContext()->setContextProperty("dynamicallyPopulate", dynamicallyPopulate);
+    window->rootContext()->setContextProperty("transitionFrom", transitionFrom);
+    window->rootContext()->setContextProperty("transitionVia", transitionVia);
+    window->rootContext()->setContextProperty("model_transitionFrom", &model_transitionFrom);
+    window->rootContext()->setContextProperty("model_transitionVia", &model_transitionVia);
+    window->setSource(testFileUrl("populateTransitions.qml"));
+    window->show();
+
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QVERIFY(gridview);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem);
 
-    if (staticallyPopulate || dynamicallyPopulate) {
-        // check the populate transition is run
-        if (usePopulateTransition) {
-            QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), 19);
-        } else {
-            QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
-            QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), 0);
-        }
+    // check the populate transition is run
+    if (staticallyPopulate && usePopulateTransition) {
+        QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), 18);
         QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 0);
+    } else if (dynamicallyPopulate) {
+        QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), 0);
+        QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 18);
     } else {
         QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+        QCOMPARE(gridview->property("countPopulateTransitions").toInt(), 0);
+        QCOMPARE(gridview->property("countAddTransitions").toInt(), 0);
     }
 
     int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
-    if (usePopulateTransition)
-        QCOMPARE(itemCount, gridview->property("countPopulateTransitions").toInt());
     for (int i=0; i < model.count() && i < itemCount; ++i) {
         QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
         QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
-        QCOMPARE(item->x(), (i%3)*80.0);
-        QCOMPARE(item->y(), (i/3)*60.0);
+        QTRY_COMPARE(item->x(), (i%3)*80.0);
+        QTRY_COMPARE(item->y(), (i/3)*60.0);
         QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
         QVERIFY(name != 0);
         QTRY_COMPARE(name->text(), model.name(i));
     }
 
+    gridview->setProperty("countPopulateTransitions", 0);
+    gridview->setProperty("countAddTransitions", 0);
+
     // add an item and check this is done with add transition, not populate
     model.insertItem(0, "another item", "");
     QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 1);
-    QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(),
-                 (usePopulateTransition && (staticallyPopulate || dynamicallyPopulate)) ? 19 : 0);
+    QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), 0);
 
     // clear the model
-    canvas->rootContext()->setContextProperty("testModel", QVariant());
+    window->rootContext()->setContextProperty("testModel", QVariant());
     QTRY_COMPARE(gridview->count(), 0);
     QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 0);
     gridview->setProperty("countPopulateTransitions", 0);
@@ -3889,20 +4662,18 @@ void tst_QQuickGridView::populateTransitions()
     model.clear();
     for (int i = 0; i < 30; i++)
         model.addItem("item" + QString::number(i), "");
-    canvas->rootContext()->setContextProperty("testModel", &model);
+    window->rootContext()->setContextProperty("testModel", &model);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
-    QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 19 : 0);
+    QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 18 : 0);
     QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 0);
 
     itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
-    if (usePopulateTransition)
-        QCOMPARE(itemCount, gridview->property("countPopulateTransitions").toInt());
     for (int i=0; i < model.count() && i < itemCount; ++i) {
         QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
         QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
-        QCOMPARE(item->x(), (i%3)*80.0);
-        QCOMPARE(item->y(), (i/3)*60.0);
+        QTRY_COMPARE(item->x(), (i%3)*80.0);
+        QTRY_COMPARE(item->y(), (i/3)*60.0);
         QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
         QVERIFY(name != 0);
         QTRY_COMPARE(name->text(), model.name(i));
@@ -3912,23 +4683,21 @@ void tst_QQuickGridView::populateTransitions()
     gridview->setProperty("countPopulateTransitions", 0);
     gridview->setProperty("countAddTransitions", 0);
     model.reset();
-    QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 19 : 0);
+    QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 18 : 0);
     QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 0);
 
     itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
-    if (usePopulateTransition)
-        QCOMPARE(itemCount, gridview->property("countPopulateTransitions").toInt());
     for (int i=0; i < model.count() && i < itemCount; ++i) {
         QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
         QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
-        QCOMPARE(item->x(), (i%3)*80.0);
-        QCOMPARE(item->y(), (i/3)*60.0);
+        QTRY_COMPARE(item->x(), (i%3)*80.0);
+        QTRY_COMPARE(item->y(), (i/3)*60.0);
         QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
         QVERIFY(name != 0);
         QTRY_COMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::populateTransitions_data()
@@ -3951,7 +4720,7 @@ void tst_QQuickGridView::addTransitions()
 {
     QFETCH(int, initialItemCount);
     QFETCH(bool, shouldAnimateTargets);
-    QFETCH(qreal, contentY);
+    QFETCH(qreal, contentYRowOffset);
     QFETCH(int, insertionIndex);
     QFETCH(int, insertionCount);
     QFETCH(ListRange, expectedDisplacedIndexes);
@@ -3968,24 +4737,24 @@ void tst_QQuickGridView::addTransitions()
     QaimModel model_targetItems_transitionFrom;
     QaimModel model_displacedItems_transitionVia;
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("model_targetItems_transitionFrom", &model_targetItems_transitionFrom);
     ctxt->setContextProperty("model_displacedItems_transitionVia", &model_displacedItems_transitionVia);
     ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom);
     ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia);
-    canvas->setSource(testFileUrl("addTransitions.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("addTransitions.qml"));
+    window->show();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem != 0);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
-    if (contentY != 0) {
-        gridview->setContentY(contentY);
+    if (contentYRowOffset != 0) {
+        gridview->setContentY(contentYRowOffset * 60.0);
         QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
     }
 
@@ -4000,7 +4769,7 @@ void tst_QQuickGridView::addTransitions()
             newData << qMakePair(QString("New item %1").arg(i), QString(""));
 
             // last visible item is the first item of the row beneath the view
-            if (i >= (contentY / 60)*3 && i < qCeil((contentY + gridview->height()) / 60.0)*3) {
+            if (i >= (gridview->contentY() / 60)*3 && i < qCeil((gridview->contentY() + gridview->height()) / 60.0)*3) {
                 expectedTargetData << newData.last();
                 targetIndexes << i;
             }
@@ -4044,7 +4813,7 @@ void tst_QQuickGridView::addTransitions()
     QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
     int firstVisibleIndex = -1;
     for (int i=0; i<items.count(); i++) {
-        if (items[i]->y() >= contentY) {
+        if (items[i]->y() >= gridview->contentY()) {
             QQmlExpression e(qmlContext(items[i]), items[i], "index");
             firstVisibleIndex = e.evaluate().toInt();
             break;
@@ -4053,8 +4822,7 @@ void tst_QQuickGridView::addTransitions()
     QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
 
     // verify all items moved to the correct final positions
-    int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
-    for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+    for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
         QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
         QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
         QCOMPARE(item->x(), (i%3)*80.0);
@@ -4064,13 +4832,13 @@ void tst_QQuickGridView::addTransitions()
         QCOMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::addTransitions_data()
 {
     QTest::addColumn<int>("initialItemCount");
-    QTest::addColumn<qreal>("contentY");
+    QTest::addColumn<qreal>("contentYRowOffset");
     QTest::addColumn<bool>("shouldAnimateTargets");
     QTest::addColumn<int>("insertionIndex");
     QTest::addColumn<int>("insertionCount");
@@ -4078,19 +4846,19 @@ void tst_QQuickGridView::addTransitions_data()
 
     // if inserting a full row before visible index, items don't appear or animate in, even if there are > 1 new items
     QTest::newRow("insert 1, just before start")
-            << 30 << 20.0 << false
+            << 30 << 1.0 << false
             << 0 << 1 << ListRange();
     QTest::newRow("insert 1, way before start")
-            << 30 << 20.0 << false
+            << 30 << 1.0 << false
             << 0 << 1 << ListRange();
     QTest::newRow("insert multiple, just before start")
-            << 30 << 100.0 << false
+            << 30 << 1.0 << false
             << 0 << 3 << ListRange();
     QTest::newRow("insert multiple (< 1 row), just before start")
-            << 30 << 100.0 << false
+            << 30 << 1.0 << false
             << 0 << 2 << ListRange();
     QTest::newRow("insert multiple, way before start")
-            << 30 << 100.0 << false
+            << 30 << 3.0 << false
             << 0 << 3 << ListRange();
 
     QTest::newRow("insert 1 at start")
@@ -4103,13 +4871,13 @@ void tst_QQuickGridView::addTransitions_data()
             << 30 << 0.0 << true
             << 0 << 5 << ListRange(0, 17);
     QTest::newRow("insert 1 at start, content y not 0")
-            << 30 << 60.0 << true  // first visible is index 3
+            << 30 << 1.0 << true  // first visible is index 3
             << 3 << 1 << ListRange(0 + 3, 17 + 3);
     QTest::newRow("insert multiple at start, content y not 0")
-            << 30 << 60.0 << true    // first visible is index 3
+            << 30 << 1.0 << true    // first visible is index 3
             << 3 << 3 << ListRange(0 + 3, 17 + 3);
     QTest::newRow("insert multiple (> 1 row) at start, content y not 0")
-            << 30 << 60.0 << true    // first visible is index 3
+            << 30 << 1.0 << true    // first visible is index 3
             << 3 << 5 << ListRange(0 + 3, 17 + 3);
 
     QTest::newRow("insert 1 at start, to empty grid")
@@ -4136,10 +4904,10 @@ void tst_QQuickGridView::addTransitions_data()
             << 30 << 0.0 << true
             << 17 << 3 << ListRange(17, 17);
     QTest::newRow("insert 1 at bottom, content y not 0")
-            << 30 << 20.0 * 3 << true
+            << 30 << 1.0 << true
             << 17 + 3 << 1 << ListRange(17 + 3, 17 + 3);
     QTest::newRow("insert multiple at bottom, content y not 0")
-            << 30 << 20.0 * 3 << true
+            << 30 << 1.0 << true
             << 17 + 3 << 3 << ListRange(17 + 3, 17 + 3);
 
 
@@ -4156,8 +4924,8 @@ void tst_QQuickGridView::addTransitions_data()
 void tst_QQuickGridView::moveTransitions()
 {
     QFETCH(int, initialItemCount);
-    QFETCH(qreal, contentY);
-    QFETCH(qreal, itemsOffsetAfterMove);
+    QFETCH(qreal, contentYRowOffset);
+    QFETCH(qreal, rowOffsetAfterMove);
     QFETCH(int, moveFrom);
     QFETCH(int, moveTo);
     QFETCH(int, moveCount);
@@ -4173,24 +4941,24 @@ void tst_QQuickGridView::moveTransitions()
     QaimModel model_targetItems_transitionVia;
     QaimModel model_displacedItems_transitionVia;
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("model_targetItems_transitionVia", &model_targetItems_transitionVia);
     ctxt->setContextProperty("model_displacedItems_transitionVia", &model_displacedItems_transitionVia);
     ctxt->setContextProperty("targetItems_transitionVia", targetItems_transitionVia);
     ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia);
-    canvas->setSource(testFileUrl("moveTransitions.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("moveTransitions.qml"));
+    window->show();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem != 0);
     QQuickText *name;
 
-    if (contentY != 0) {
-        gridview->setContentY(contentY);
+    if (contentYRowOffset != 0) {
+        gridview->setContentY(contentYRowOffset * 60.0);
         QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
     }
 
@@ -4202,8 +4970,8 @@ void tst_QQuickGridView::moveTransitions()
     QList<int> targetIndexes;
     for (int i=moveFrom; i<moveFrom+moveCount; i++) {
         int toIndex = moveTo + (i - moveFrom);
-        int firstVisibleIndex = (contentY / 60) * 3;
-        int lastVisibleIndex = (qCeil((contentY + gridview->height()) / 60.0)*3) - 1;
+        int firstVisibleIndex = (gridview->contentY() / 60) * 3;
+        int lastVisibleIndex = (qCeil((gridview->contentY() + gridview->height()) / 60.0)*3) - 1;
         if ((i >= firstVisibleIndex && i <= lastVisibleIndex)
                 || (toIndex >= firstVisibleIndex && toIndex <= lastVisibleIndex)) {
             expectedTargetData << qMakePair(model.name(i), model.number(i));
@@ -4241,7 +5009,7 @@ void tst_QQuickGridView::moveTransitions()
     QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
     int firstVisibleIndex = -1;
     for (int i=0; i<items.count(); i++) {
-        if (items[i]->y() >= contentY) {
+        if (items[i]->y() >= gridview->contentY()) {
             QQmlExpression e(qmlContext(items[i]), items[i], "index");
             firstVisibleIndex = e.evaluate().toInt();
             break;
@@ -4250,111 +5018,149 @@ void tst_QQuickGridView::moveTransitions()
     QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
 
     // verify all items moved to the correct final positions
-    int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
-    for (int i=firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+    qreal pixelOffset = 60 * rowOffsetAfterMove;
+    for (int i=firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
         QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
         QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
         QCOMPARE(item->x(), (i%3)*80.0);
-        QCOMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
+        QCOMPARE(item->y(), (i/3)*60.0 + pixelOffset);
         name = findItem<QQuickText>(contentItem, "textName", i);
         QVERIFY(name != 0);
         QTRY_COMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::moveTransitions_data()
 {
     QTest::addColumn<int>("initialItemCount");
-    QTest::addColumn<qreal>("contentY");
-    QTest::addColumn<qreal>("itemsOffsetAfterMove");
+    QTest::addColumn<qreal>("contentYRowOffset");
+    QTest::addColumn<qreal>("rowOffsetAfterMove");
     QTest::addColumn<int>("moveFrom");
     QTest::addColumn<int>("moveTo");
     QTest::addColumn<int>("moveCount");
     QTest::addColumn<ListRange>("expectedDisplacedIndexes");
 
-    QTest::newRow("move from above view, outside visible items, move 1") << 30 << 120.0 << 0.0
+    QTest::newRow("move from above view, outside visible items, move 1")
+            << 30 << 2.0 << 0.0
             << 1 << 10 << 1 << ListRange(6, 10);
-    QTest::newRow("move from above view, outside visible items, move 1 (first item)") << 30 << 120.0 << 0.0
+    QTest::newRow("move from above view, outside visible items, move 1 (first item)")
+            << 30 << 2.0 << 0.0
             << 0 << 10 << 1 << ListRange(6, 10);
-    QTest::newRow("move from above view, outside visible items, move multiple") << 30 << 120.0 << 60.0
+    QTest::newRow("move from above view, outside visible items, move multiple")
+            << 30 << 2.0 << 1.0
             << 1 << 10 << 3 << ListRange(13, 23);
-    QTest::newRow("move from above view, mix of visible/non-visible") << 30 << 120.0 << 60.0
+    QTest::newRow("move from above view, mix of visible/non-visible")
+            << 30 << 2.0 << 1.0
             << 1 << 10 << 6 << (ListRange(7, 15) + ListRange(16, 23));
-    QTest::newRow("move from above view, mix of visible/non-visible (move first)") << 30 << 120.0 << 120.0
+    QTest::newRow("move from above view, mix of visible/non-visible (move first)")
+            << 30 << 2.0 << 2.0
             << 0 << 10 << 6 << ListRange(16, 23);
 
-    QTest::newRow("move within view, move 1 down") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move 1 down")
+            << 30 << 0.0 << 0.0
             << 1 << 10 << 1 << ListRange(2, 10);
-    QTest::newRow("move within view, move 1 down, move first item") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move 1 down, move first item")
+            << 30 << 0.0 << 0.0
             << 0 << 10 << 1 << ListRange(1, 10);
-    QTest::newRow("move within view, move 1 down, move first item, contentY not 0") << 30 << 120.0 << 0.0
+    QTest::newRow("move within view, move 1 down, move first item, contentY not 0")
+            << 30 << 2.0 << 0.0
             << 0+6 << 10+6 << 1 << ListRange(1+6, 10+6);
-    QTest::newRow("move within view, move 1 down, to last item") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move 1 down, to last item")
+            << 30 << 0.0 << 0.0
             << 10 << 17 << 1 << ListRange(11, 17);
-    QTest::newRow("move within view, move first->last") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move first->last")
+            << 30 << 0.0 << 0.0
             << 0 << 17 << 1 << ListRange(1, 17);
 
-    QTest::newRow("move within view, move multiple down") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple down")
+            << 30 << 0.0 << 0.0
             << 1 << 10 << 3 << ListRange(4, 12);
-    QTest::newRow("move within view, move multiple down, move first item") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple down, move first item")
+            << 30 << 0.0 << 0.0
             << 0 << 10 << 3 << ListRange(3, 12);
-    QTest::newRow("move within view, move multiple down, move first item, contentY not 0") << 30 << 60.0 << 0.0
+    QTest::newRow("move within view, move multiple down, move first item, contentY not 0")
+            << 30 << 1.0 << 0.0
             << 0+3 << 10+3 << 3 << ListRange(3+3, 12+3);
-    QTest::newRow("move within view, move multiple down, displace last item") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple down, displace last item")
+            << 30 << 0.0 << 0.0
             << 5 << 15 << 3 << ListRange(8, 17);
-    QTest::newRow("move within view, move multiple down, move first->last") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple down, move first->last")
+            << 30 << 0.0 << 0.0
             << 0 << 15 << 3 << ListRange(3, 17);
 
-    QTest::newRow("move within view, move 1 up") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move 1 up")
+            << 30 << 0.0 << 0.0
             << 10 << 1 << 1 << ListRange(1, 9);
-    QTest::newRow("move within view, move 1 up, move to first index") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move 1 up, move to first index")
+            << 30 << 0.0 << 0.0
             << 10 << 0 << 1 << ListRange(0, 9);
-    QTest::newRow("move within view, move 1 up, move to first index, contentY not 0") << 30 << 120.0 << 0.0
+    QTest::newRow("move within view, move 1 up, move to first index, contentY not 0")
+            << 30 << 2.0 << 0.0
             << 10+6 << 0+6 << 1 << ListRange(0+6, 9+6);
-    QTest::newRow("move within view, move 1 up, move to first index, contentY not on item border") << 30 << 80.0 << 0.0
+    QTest::newRow("move within view, move 1 up, move to first index, contentY not on item border")
+            << 30 << 1.5 << 0.0
             << 10+3 << 0+3 << 1 << ListRange(0+3, 9+3);
-    QTest::newRow("move within view, move 1 up, move last item") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move 1 up, move last item")
+            << 30 << 0.0 << 0.0
             << 17 << 10 << 1 << ListRange(10, 16);
-    QTest::newRow("move within view, move 1 up, move last->first") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move 1 up, move last->first")
+            << 30 << 0.0 << 0.0
             << 17 << 0 << 1 << ListRange(0, 16);
 
-    QTest::newRow("move within view, move multiple up") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple up")
+            << 30 << 0.0 << 0.0
             << 10 << 1 << 3 << ListRange(1, 9);
-    QTest::newRow("move within view, move multiple (> 1 row) up") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple (> 1 row) up")
+            << 30 << 0.0 << 0.0
             << 10 << 1 << 5 << ListRange(1, 9);
-    QTest::newRow("move within view, move multiple up, move to first index") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple up, move to first index")
+            << 30 << 0.0 << 0.0
             << 10 << 0 << 3 << ListRange(0, 9);
-    QTest::newRow("move within view, move multiple up, move to first index, contentY not 0") << 30 << 60.0 << 0.0
+    QTest::newRow("move within view, move multiple up, move to first index, contentY not 0")
+            << 30 << 1.0 << 0.0
             << 10+3 << 0+3 << 3 << ListRange(0+3, 9+3);
-    QTest::newRow("move within view, move multiple up (> 1 row), move to first index, contentY not on border") << 30 << 80.0 << 0.0
+    QTest::newRow("move within view, move multiple up (> 1 row), move to first index, contentY not on border")
+            << 30 << 1.5 << 0.0
             << 10+3 << 0+3 << 5 << ListRange(0+3, 9+3);
-    QTest::newRow("move within view, move multiple up, move last item") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple up, move last item")
+            << 30 << 0.0 << 0.0
             << 15 << 5 << 3 << ListRange(5, 14);
-    QTest::newRow("move within view, move multiple up, move last->first") << 30 << 0.0 << 0.0
+    QTest::newRow("move within view, move multiple up, move last->first")
+            << 30 << 0.0 << 0.0
             << 15 << 0 << 3 << ListRange(0, 14);
 
-    QTest::newRow("move from below view, move 1 up") << 30 << 0.0 << 0.0
+    QTest::newRow("move from below view, move 1 up")
+            << 30 << 0.0 << 0.0
             << 20 << 5 << 1 << ListRange(5, 17);
-    QTest::newRow("move from below view, move 1 up, move to top") << 30 << 0.0 << 0.0
+    QTest::newRow("move from below view, move 1 up, move to top")
+            << 30 << 0.0 << 0.0
             << 20 << 0 << 1 << ListRange(0, 17);
-    QTest::newRow("move from below view, move 1 up, move to top, contentY not 0") << 30 << 60.0 << 0.0
+    QTest::newRow("move from below view, move 1 up, move to top, contentY not 0")
+            << 30 << 1.0 << 0.0
             << 25 << 3 << 1 << ListRange(0+3, 17+3);
-    QTest::newRow("move from below view, move multiple (> 1 row) up") << 30 << 0.0 << 0.0
+    QTest::newRow("move from below view, move multiple (> 1 row) up")
+            << 30 << 0.0 << 0.0
             << 20 << 5 << 5 << ListRange(5, 17);
-    QTest::newRow("move from below view, move multiple up, move to top") << 30 << 0.0 << 0.0
+    QTest::newRow("move from below view, move multiple up, move to top")
+            << 30 << 0.0 << 0.0
             << 20 << 0 << 3 << ListRange(0, 17);
-    QTest::newRow("move from below view, move multiple up, move to top, contentY not 0") << 30 << 60.0 << 0.0
+    QTest::newRow("move from below view, move multiple up, move to top, contentY not 0")
+            << 30 << 1.0 << 0.0
             << 25 << 3 << 3 << ListRange(0+3, 17+3);
 
-    QTest::newRow("move from below view, move 1 up, move to bottom") << 30 << 0.0 << 0.0
+    QTest::newRow("move from below view, move 1 up, move to bottom")
+            << 30 << 0.0 << 0.0
             << 20 << 17 << 1 << ListRange(17, 17);
-    QTest::newRow("move from below view, move 1 up, move to bottom, contentY not 0") << 30 << 60.0 << 0.0
+    QTest::newRow("move from below view, move 1 up, move to bottom, contentY not 0")
+            << 30 << 1.0 << 0.0
             << 25 << 17+3 << 1 << ListRange(17+3, 17+3);
-    QTest::newRow("move from below view, move multiple up, move to to bottom") << 30 << 0.0 << 0.0
+    QTest::newRow("move from below view, move multiple up, move to to bottom")
+            << 30 << 0.0 << 0.0
             << 20 << 17 << 3 << ListRange(17, 17);
-    QTest::newRow("move from below view, move multiple up, move to bottom, contentY not 0") << 30 << 60.0 << 0.0
+    QTest::newRow("move from below view, move multiple up, move to bottom, contentY not 0")
+            << 30 << 1.0 << 0.0
             << 25 << 17+3 << 3 << ListRange(17+3, 17+3);
 }
 
@@ -4362,7 +5168,7 @@ void tst_QQuickGridView::removeTransitions()
 {
     QFETCH(int, initialItemCount);
     QFETCH(bool, shouldAnimateTargets);
-    QFETCH(qreal, contentY);
+    QFETCH(qreal, contentYRowOffset);
     QFETCH(int, removalIndex);
     QFETCH(int, removalCount);
     QFETCH(ListRange, expectedDisplacedIndexes);
@@ -4379,24 +5185,24 @@ void tst_QQuickGridView::removeTransitions()
     QaimModel model_targetItems_transitionTo;
     QaimModel model_displacedItems_transitionVia;
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("model_targetItems_transitionTo", &model_targetItems_transitionTo);
     ctxt->setContextProperty("model_displacedItems_transitionVia", &model_displacedItems_transitionVia);
     ctxt->setContextProperty("targetItems_transitionTo", targetItems_transitionTo);
     ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia);
-    canvas->setSource(testFileUrl("removeTransitions.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("removeTransitions.qml"));
+    window->show();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem != 0);
     QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
 
-    if (contentY != 0) {
-        gridview->setContentY(contentY);
+    if (contentYRowOffset != 0) {
+        gridview->setContentY(contentYRowOffset * 60.0);
         QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
     }
 
@@ -4407,8 +5213,8 @@ void tst_QQuickGridView::removeTransitions()
     QList<int> targetIndexes;
     if (shouldAnimateTargets) {
         for (int i=removalIndex; i<removalIndex+removalCount; i++) {
-            int firstVisibleIndex = (contentY / 60.0)*3;
-            int lastVisibleIndex = (qCeil((contentY + gridview->height()) / 60.0)*3) - 1;
+            int firstVisibleIndex = (gridview->contentY() / 60.0)*3;
+            int lastVisibleIndex = (qCeil((gridview->contentY() + gridview->height()) / 60.0)*3) - 1;
             if (i >= firstVisibleIndex && i <= lastVisibleIndex) {
                 expectedTargetData << qMakePair(model.name(i), model.number(i));
                 targetIndexes << i;
@@ -4458,7 +5264,7 @@ void tst_QQuickGridView::removeTransitions()
     for (int i=0; i<items.count(); i++) {
         QQmlExpression e(qmlContext(items[i]), items[i], "index");
         int index = e.evaluate().toInt();
-        if (firstVisibleIndex < 0 && items[i]->y() >= contentY)
+        if (firstVisibleIndex < 0 && items[i]->y() >= gridview->contentY())
             firstVisibleIndex = index;
         else if (index < 0)
             itemCount--;    // exclude deleted items
@@ -4470,19 +5276,19 @@ void tst_QQuickGridView::removeTransitions()
         QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
         QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
         QCOMPARE(item->x(), (i%3)*80.0);
-        QCOMPARE(item->y(), contentY + ((i-firstVisibleIndex)/3) * 60.0);
+        QCOMPARE(item->y(), gridview->contentY() + ((i-firstVisibleIndex)/3) * 60.0);
         QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
         QVERIFY(name != 0);
         QTRY_COMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::removeTransitions_data()
 {
     QTest::addColumn<int>("initialItemCount");
-    QTest::addColumn<qreal>("contentY");
+    QTest::addColumn<qreal>("contentYRowOffset");
     QTest::addColumn<bool>("shouldAnimateTargets");
     QTest::addColumn<int>("removalIndex");
     QTest::addColumn<int>("removalCount");
@@ -4494,19 +5300,19 @@ void tst_QQuickGridView::removeTransitions_data()
     // For a GridView, removing any number of items other than a full row before the start
     // should displace all items in the view
     QTest::newRow("remove 1 before start")
-            << 30 << 120.0 << false
+            << 30 << 2.0 << false
             << 2 << 1 << ListRange(6, 24);    // 6-24 are displaced
     QTest::newRow("remove 1 row, before start")
-            << 30 << 120.0 << false
+            << 30 << 2.0 << false
             << 3 << 3 << ListRange();
     QTest::newRow("remove between 1-2 rows, before start")
-            << 30 << 120.0 << false
+            << 30 << 2.0 << false
             << 0 << 5 << ListRange(6, 25);
     QTest::newRow("remove 2 rows, before start")
-            << 30 << 120.0 << false
+            << 30 << 2.0 << false
             << 0 << 6 << ListRange();
     QTest::newRow("remove mix of before and after start")
-            << 30 << 60.0 << true
+            << 30 << 1.0 << true
             << 2 << 3 << ListRange(5, 23);  // 5-23 are displaced into view
 
 
@@ -4517,10 +5323,10 @@ void tst_QQuickGridView::removeTransitions_data()
             << 30 << 0.0 << true
             << 0 << 3 << ListRange(3, 20);  // 3-18 are displaced into view
     QTest::newRow("remove 1 from start, content y not 0")
-            << 30 << 60.0 << true
+            << 30 << 1.0 << true
             << 3 << 1 << ListRange(1 + 3, 18 + 3);
     QTest::newRow("remove multiple from start, content y not 0")
-            << 30 << 60.0 << true
+            << 30 << 1.0 << true
             << 3 << 3 << ListRange(3 + 3, 20 + 3);
 
 
@@ -4542,10 +5348,10 @@ void tst_QQuickGridView::removeTransitions_data()
             << 30 << 0.0 << true
             << 15 << 5 << ListRange(20, 22);
     QTest::newRow("remove 1 from bottom, content y not 0")
-            << 30 << 60.0 << true
+            << 30 << 1.0 << true
             << 17 + 3 << 1 << ListRange(18 + 3, 18 + 3);
     QTest::newRow("remove multiple (1 row) from bottom, content y not 0")
-            << 30 << 60.0 << true
+            << 30 << 1.0 << true
             << 15 + 3 << 3 << ListRange(18 + 3, 20 + 3);
 
 
@@ -4583,8 +5389,8 @@ void tst_QQuickGridView::displacedTransitions()
     QPointF moveDisplaced_transitionVia(50, -100);
     QPointF removeDisplaced_transitionVia(150, 100);
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("model_displaced_transitionVia", &model_displaced_transitionVia);
     ctxt->setContextProperty("model_addDisplaced_transitionVia", &model_addDisplaced_transitionVia);
@@ -4602,11 +5408,11 @@ void tst_QQuickGridView::displacedTransitions()
     ctxt->setContextProperty("moveDisplacedEnabled", moveDisplacedEnabled);
     ctxt->setContextProperty("useRemoveDisplaced", useRemoveDisplaced);
     ctxt->setContextProperty("removeDisplacedEnabled", removeDisplacedEnabled);
-    canvas->setSource(testFileUrl("displacedTransitions.qml"));
-    canvas->show();
+    window->setSource(testFileUrl("displacedTransitions.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem != 0);
@@ -4635,6 +5441,7 @@ void tst_QQuickGridView::displacedTransitions()
             break;
         case ListChange::SetCurrent:
         case ListChange::SetContentY:
+        case ListChange::Polish:
             break;
     }
 
@@ -4693,7 +5500,7 @@ void tst_QQuickGridView::displacedTransitions()
         QTRY_COMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::displacedTransitions_data()
@@ -4789,6 +5596,9 @@ void tst_QQuickGridView::multipleTransitions()
     QFETCH(int, initialCount);
     QFETCH(qreal, contentY);
     QFETCH(QList<ListChange>, changes);
+    QFETCH(bool, enableAddTransitions);
+    QFETCH(bool, enableMoveTransitions);
+    QFETCH(bool, enableRemoveTransitions);
     QFETCH(bool, rippleAddDisplaced);
 
     // add transitions on the left, moves on the right
@@ -4803,8 +5613,8 @@ void tst_QQuickGridView::multipleTransitions()
     for (int i = 0; i < initialCount; i++)
         model.addItem("Original item" + QString::number(i), "");
 
-    QQuickView *canvas = createView();
-    QQmlContext *ctxt = canvas->rootContext();
+    QQuickView *window = getView();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("addTargets_transitionFrom", addTargets_transitionFrom);
     ctxt->setContextProperty("addDisplaced_transitionFrom", addDisplaced_transitionFrom);
@@ -4812,12 +5622,15 @@ void tst_QQuickGridView::multipleTransitions()
     ctxt->setContextProperty("moveDisplaced_transitionFrom", moveDisplaced_transitionFrom);
     ctxt->setContextProperty("removeTargets_transitionTo", removeTargets_transitionTo);
     ctxt->setContextProperty("removeDisplaced_transitionFrom", removeDisplaced_transitionFrom);
+    ctxt->setContextProperty("enableAddTransitions", enableAddTransitions);
+    ctxt->setContextProperty("enableMoveTransitions", enableMoveTransitions);
+    ctxt->setContextProperty("enableRemoveTransitions", enableRemoveTransitions);
     ctxt->setContextProperty("rippleAddDisplaced", rippleAddDisplaced);
-    canvas->setSource(testFileUrl("multipleTransitions.qml"));
-    canvas->show();
-    QTest::qWaitForWindowShown(canvas);
+    window->setSource(testFileUrl("multipleTransitions.qml"));
+    window->show();
+    QTest::qWaitForWindowShown(window);
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QTRY_VERIFY(gridview != 0);
     QQuickItem *contentItem = gridview->contentItem();
     QVERIFY(contentItem != 0);
@@ -4828,7 +5641,7 @@ void tst_QQuickGridView::multipleTransitions()
         QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
     }
 
-    int timeBetweenActions = canvas->rootObject()->property("timeBetweenActions").toInt();
+    int timeBetweenActions = window->rootObject()->property("timeBetweenActions").toInt();
 
     for (int i=0; i<changes.count(); i++) {
         switch (changes[i].type) {
@@ -4875,6 +5688,8 @@ void tst_QQuickGridView::multipleTransitions()
                 gridview->setContentY(changes[i].pos);
                 QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
                 break;
+            case ListChange::Polish:
+                break;
         }
     }
     QCOMPARE(gridview->count(), model.count());
@@ -4895,14 +5710,14 @@ void tst_QQuickGridView::multipleTransitions()
     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)));
-        QCOMPARE(item->x(), (i%3)*80.0);
-        QCOMPARE(item->y(), (i/3)*60.0);
+        QTRY_COMPARE(item->x(), (i%3)*80.0);
+        QTRY_COMPARE(item->y(), (i/3)*60.0);
         QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
         QVERIFY(name != 0);
         QTRY_COMPARE(name->text(), model.name(i));
     }
 
-    delete canvas;
+    releaseView(window);
 }
 
 void tst_QQuickGridView::multipleTransitions_data()
@@ -4910,6 +5725,9 @@ void tst_QQuickGridView::multipleTransitions_data()
     QTest::addColumn<int>("initialCount");
     QTest::addColumn<qreal>("contentY");
     QTest::addColumn<QList<ListChange> >("changes");
+    QTest::addColumn<bool>("enableAddTransitions");
+    QTest::addColumn<bool>("enableMoveTransitions");
+    QTest::addColumn<bool>("enableRemoveTransitions");
     QTest::addColumn<bool>("rippleAddDisplaced");
 
     // the added item and displaced items should move to final dest correctly
@@ -4917,14 +5735,14 @@ void tst_QQuickGridView::multipleTransitions_data()
              << ListChange::insert(0, 1)
              << ListChange::move(0, 3, 1)
              )
-             << false;
+             << true << true << true << false;
 
     // items affected by the add should change from move to add transition
     QTest::newRow("move, then insert item before the moved item") << 20 << 0.0 << (QList<ListChange>()
             << ListChange::move(1, 10, 3)
             << ListChange::insert(0, 1)
             )
-            << false;
+            << true << true << true << false;
 
     // items should be placed correctly if you trigger a transition then refill for that index
     QTest::newRow("add at 0, flick down, flick back to top and add at 0 again") << 20 << 0.0 << (QList<ListChange>()
@@ -4933,33 +5751,96 @@ void tst_QQuickGridView::multipleTransitions_data()
             << ListChange::setContentY(0.0)
             << ListChange::insert(0, 1)
             )
-            << false;
+            << true << true << true << false;
 
     QTest::newRow("insert then remove same index, with ripple effect on add displaced") << 20 << 0.0 << (QList<ListChange>()
             << ListChange::insert(1, 1)
             << ListChange::remove(1, 1)
             )
-            << true;
+            << true << true << true << true;
+
+    // if item is removed while undergoing a displaced transition, all other items should end up at their correct positions,
+    // even if a remove-displace transition is not present to re-animate them
+    QTest::newRow("insert then remove, with remove disabled") << 20 << 0.0 << (QList<ListChange>()
+            << ListChange::insert(0, 1)
+            << ListChange::remove(2, 1)
+            )
+            << true << true << false << false;
+
+    // if last item is not flush with the edge of the view, it should still be refilled in correctly after a
+    // remove has changed the position of where it will move to
+    QTest::newRow("insert twice then remove, with remove disabled") << 20 << 0.0 << (QList<ListChange>()
+            << ListChange::setContentY(-10.0)
+            << ListChange::insert(0, 1)
+            << ListChange::insert(0, 1)
+            << ListChange::remove(2, 1)
+            )
+            << true << true << false << false;
+}
+
+void tst_QQuickGridView::multipleDisplaced()
+{
+    // multiple move() operations should only restart displace transitions for items that
+    // moved from previously set positions, and not those that have moved from their current
+    // item positions (which may e.g. still be changing from easing bounces in the last transition)
+
+    QmlListModel model;
+    for (int i = 0; i < 30; i++)
+        model.addItem("Original item" + QString::number(i), "");
+
+    QQuickView *window = createView();
+    QQmlContext *ctxt = window->rootContext();
+    ctxt->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("multipleDisplaced.qml"));
+    window->show();
+    QTest::qWaitForWindowShown(window);
+
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
+    QTRY_VERIFY(gridview != 0);
+    QQuickItem *contentItem = gridview->contentItem();
+    QVERIFY(contentItem != 0);
+    QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+    model.moveItems(12, 8, 1);
+    QTest::qWait(window->rootObject()->property("duration").toInt() / 2);
+    model.moveItems(8, 3, 1);
+    QTRY_VERIFY(gridview->property("displaceTransitionsDone").toBool());
+
+    QVariantMap transitionsStarted = gridview->property("displaceTransitionsStarted").toMap();
+    foreach (const QString &name, transitionsStarted.keys()) {
+        QVERIFY2(transitionsStarted[name] == 1,
+                 QTest::toString(QString("%1 was displaced %2 times").arg(name).arg(transitionsStarted[name].toInt())));
+    }
+
+    // verify all items moved to the correct final positions
+    QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+    for (int i=0; i < model.count() && i < items.count(); ++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);
+        QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
+        QVERIFY(name != 0);
+        QTRY_COMPARE(name->text(), model.name(i));
+    }
+
+    delete window;
 }
 
 void tst_QQuickGridView::cacheBuffer()
 {
-    QQuickView *canvas = createView();
+    QQuickView *window = createView();
 
     QaimModel model;
     for (int i = 0; i < 90; i++)
         model.addItem("Item" + QString::number(i), "");
 
-    QQmlContext *ctxt = canvas->rootContext();
-    ctxt->setContextProperty("testModel", &model);
-    ctxt->setContextProperty("testRightToLeft", QVariant(false));
-    ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
-    canvas->setSource(testFileUrl("gridview1.qml"));
-    canvas->show();
+    window->rootContext()->setContextProperty("testModel", &model);
+    window->setSource(testFileUrl("gridview1.qml"));
+    window->show();
     qApp->processEvents();
 
-    QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+    QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid");
     QVERIFY(gridview != 0);
 
     QQuickItem *contentItem = gridview->contentItem();
@@ -4976,9 +5857,9 @@ void tst_QQuickGridView::cacheBuffer()
     }
 
     QQmlIncubationController controller;
-    canvas->engine()->setIncubationController(&controller);
+    window->engine()->setIncubationController(&controller);
 
-    canvas->rootObject()->setProperty("cacheBuffer", 200);
+    window->rootObject()->setProperty("cacheBuffer", 200);
     QTRY_VERIFY(gridview->cacheBuffer() == 200);
 
     // items will be created one at a time
@@ -5036,19 +5917,19 @@ void tst_QQuickGridView::cacheBuffer()
         controller.incubateWhile(&b);
     }
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::asynchronous()
 {
-    QQuickView *canvas = createView();
-    canvas->show();
+    QQuickView *window = createView();
+    window->show();
     QQmlIncubationController controller;
-    canvas->engine()->setIncubationController(&controller);
+    window->engine()->setIncubationController(&controller);
 
-    canvas->setSource(testFile("asyncloader.qml"));
+    window->setSource(testFileUrl("asyncloader.qml"));
 
-    QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject());
+    QQuickItem *rootObject = qobject_cast<QQuickItem*>(window->rootObject());
     QVERIFY(rootObject);
 
     QQuickGridView *gridview = 0;
@@ -5083,7 +5964,7 @@ void tst_QQuickGridView::asynchronous()
         QVERIFY(item->y() == (i/3)*100);
     }
 
-    delete canvas;
+    delete window;
 }
 
 void tst_QQuickGridView::unrequestedVisibility()
@@ -5092,23 +5973,23 @@ void tst_QQuickGridView::unrequestedVisibility()
     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);
+    QQuickView *window = new QQuickView(0);
+    window->setGeometry(0,0,240,320);
 
-    QQmlContext *ctxt = canvas->rootContext();
+    QQmlContext *ctxt = window->rootContext();
     ctxt->setContextProperty("testModel", &model);
     ctxt->setContextProperty("testWrap", QVariant(false));
 
-    canvas->setSource(testFileUrl("unrequestedItems.qml"));
+    window->setSource(testFileUrl("unrequestedItems.qml"));
 
-    canvas->show();
+    window->show();
 
     qApp->processEvents();
 
-    QQuickGridView *leftview = findItem<QQuickGridView>(canvas->rootObject(), "leftGrid");
+    QQuickGridView *leftview = findItem<QQuickGridView>(window->rootObject(), "leftGrid");
     QTRY_VERIFY(leftview != 0);
 
-    QQuickGridView *rightview = findItem<QQuickGridView>(canvas->rootObject(), "rightGrid");
+    QQuickGridView *rightview = findItem<QQuickGridView>(window->rootObject(), "rightGrid");
     QTRY_VERIFY(rightview != 0);
 
     QQuickItem *leftContent = leftview->contentItem();
@@ -5125,23 +6006,23 @@ void tst_QQuickGridView::unrequestedVisibility()
     QQuickItem *item;
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 11));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 11));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 9));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 10));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 3));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 4));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
 
     rightview->setCurrentIndex(0);
 
@@ -5149,9 +6030,9 @@ void tst_QQuickGridView::unrequestedVisibility()
     QTRY_COMPARE(rightview->contentY(), 0.0);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
-    QTRY_COMPARE(item->isVisible(), true);
+    QTRY_COMPARE(delegateVisible(item), true);
 
     QVERIFY(!findItem<QQuickItem>(leftContent, "wrapper", 11));
     QVERIFY(!findItem<QQuickItem>(rightContent, "wrapper", 11));
@@ -5162,102 +6043,316 @@ void tst_QQuickGridView::unrequestedVisibility()
     QTRY_COMPARE(rightview->contentY(), 0.0);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
-    QTRY_COMPARE(item->isVisible(), false);
+    QTRY_COMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 11));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 11));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 5));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     // move a non-visible item into view
     model.moveItems(10, 9, 1);
     QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
 
     QTRY_VERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 1));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 11));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 11));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 5));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     // move a visible item out of view
     model.moveItems(5, 3, 1);
     QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 5));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     // move a non-visible item into view
     model.moveItems(3, 5, 1);
     QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 5));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     // move a visible item out of view
     model.moveItems(9, 10, 1);
     QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 5));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
 
     // move a non-visible item into view
     model.moveItems(10, 9, 1);
     QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false);
 
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
     QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 5));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 9));
-    QCOMPARE(item->isVisible(), true);
+    QCOMPARE(delegateVisible(item), true);
     QVERIFY(item = findItem<QQuickItem>(rightContent, "wrapper", 10));
-    QCOMPARE(item->isVisible(), false);
+    QCOMPARE(delegateVisible(item), false);
+
+    delete window;
+}
 
-    delete canvas;
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_TtB()
+{
+    inserted_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_TtB_data()
+{
+    inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_TtB()
+{
+    inserted_defaultLayout(QQuickGridView::FlowTopToBottom);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_TtB_data()
+{
+    inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_TtB()
+{
+    inserted_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_TtB_data()
+{
+    inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_leftToRight_LtR_BtT()
+{
+    inserted_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_leftToRight_LtR_BtT_data()
+{
+    inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_BtT()
+{
+    inserted_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_BtT_data()
+{
+    inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_BtT()
+{
+    inserted_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_BtT_data()
+{
+    inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_BtT()
+{
+    inserted_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_BtT_data()
+{
+    inserted_defaultLayout_data();
+}
+
+
+void tst_QQuickGridView::removed_leftToRight_RtL_TtB()
+{
+    removed_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::removed_leftToRight_RtL_TtB_data()
+{
+    removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_TtB()
+{
+    removed_defaultLayout(QQuickGridView::FlowTopToBottom);
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_TtB_data()
+{
+    removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_TtB()
+{
+    removed_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_TtB_data()
+{
+    removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_leftToRight_LtR_BtT()
+{
+    removed_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_leftToRight_LtR_BtT_data()
+{
+    removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_leftToRight_RtL_BtT()
+{
+    removed_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_leftToRight_RtL_BtT_data()
+{
+    removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_BtT()
+{
+    removed_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_BtT_data()
+{
+    removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_BtT()
+{
+    removed_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_BtT_data()
+{
+    removed_defaultLayout_data();
+}
+
+
+void tst_QQuickGridView::moved_leftToRight_RtL_TtB()
+{
+    moved_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::moved_leftToRight_RtL_TtB_data()
+{
+    moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_TtB()
+{
+    moved_defaultLayout(QQuickGridView::FlowTopToBottom);
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_TtB_data()
+{
+    moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_TtB()
+{
+    moved_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_TtB_data()
+{
+    moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_leftToRight_LtR_BtT()
+{
+    moved_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::moved_leftToRight_LtR_BtT_data()
+{
+    moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_leftToRight_RtL_BtT()
+{
+    moved_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft, QQuickItemView::BottomToTop);
 }
 
+void tst_QQuickGridView::moved_leftToRight_RtL_BtT_data()
+{
+    moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_BtT()
+{
+    moved_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_BtT_data()
+{
+    moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_BtT()
+{
+    moved_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_BtT_data()
+{
+    moved_defaultLayout_data();
+}
+
+
 QList<int> tst_QQuickGridView::toIntList(const QVariantList &list)
 {
     QList<int> ret;