diff options
Diffstat (limited to 'tests')
4 files changed, 70 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsggridview/data/gridview-initCurrent.qml b/tests/auto/declarative/qsggridview/data/gridview-initCurrent.qml index c012b4c481..e3ec8f2d4a 100644 --- a/tests/auto/declarative/qsggridview/data/gridview-initCurrent.qml +++ b/tests/auto/declarative/qsggridview/data/gridview-initCurrent.qml @@ -1,7 +1,12 @@ import QtQuick 2.0 Rectangle { + id: root + property int current: grid.currentIndex + property bool showHeader: false + property bool showFooter: false + width: 240 height: 320 color: "#ffffff" @@ -37,6 +42,12 @@ Rectangle { } } ] + + Component { + id: headerFooter + Rectangle { height: 30; width: 240; color: "blue" } + } + GridView { id: grid objectName: "grid" @@ -48,5 +59,7 @@ Rectangle { cellHeight: 60 delegate: myDelegate model: testModel + header: root.showHeader ? headerFooter : null + footer: root.showFooter ? headerFooter : null } } diff --git a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp index c478f0dab3..49c3080a1c 100644 --- a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp +++ b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp @@ -880,6 +880,26 @@ void tst_QSGGridView::currentIndex() 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); + 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); + + // header should become visible if it is out of view, and then current index moves to the last row + canvas->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 qApp->setActiveWindow(canvas); #ifdef Q_WS_X11 @@ -889,6 +909,8 @@ void tst_QSGGridView::currentIndex() QTRY_VERIFY(canvas->hasFocus()); qApp->processEvents(); + gridview->setCurrentIndex(0); + QTest::keyClick(canvas, Qt::Key_Down); QCOMPARE(gridview->currentIndex(), 3); diff --git a/tests/auto/declarative/qsglistview/data/listview-initCurrent.qml b/tests/auto/declarative/qsglistview/data/listview-initCurrent.qml index ee1a333de0..c4f1860eda 100644 --- a/tests/auto/declarative/qsglistview/data/listview-initCurrent.qml +++ b/tests/auto/declarative/qsglistview/data/listview-initCurrent.qml @@ -1,7 +1,12 @@ import QtQuick 2.0 Rectangle { + id: root + property int current: list.currentIndex + property bool showHeader: false + property bool showFooter: false + width: 240 height: 320 color: "#ffffff" @@ -36,6 +41,12 @@ Rectangle { } } ] + + Component { + id: headerFooter + Rectangle { height: 30; width: 240; color: "blue" } + } + ListView { id: list objectName: "list" @@ -47,5 +58,7 @@ Rectangle { delegate: myDelegate highlightMoveSpeed: 1000 model: testModel + header: root.showHeader ? headerFooter : null + footer: root.showFooter ? headerFooter : null } } diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp index 59847d37f5..e1e6edd53d 100644 --- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp +++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp @@ -1478,6 +1478,26 @@ void tst_QSGListView::currentIndex() QTRY_COMPARE(listview->contentY(), 0.0); + + // footer should become visible if it is out of view, and then current index is set to count-1 + canvas->rootObject()->setProperty("showFooter", true); + QTRY_VERIFY(listview->footerItem()); + listview->setCurrentIndex(model.count()-2); + QTRY_VERIFY(listview->footerItem()->y() > listview->contentY() + listview->height()); + listview->setCurrentIndex(model.count()-1); + QTRY_COMPARE(listview->contentY() + listview->height(), (20.0 * model.count()) + listview->footerItem()->height()); + canvas->rootObject()->setProperty("showFooter", false); + + // header should become visible if it is out of view, and then current index is set to 0 + canvas->rootObject()->setProperty("showHeader", true); + QTRY_VERIFY(listview->headerItem()); + listview->setCurrentIndex(1); + QTRY_VERIFY(listview->headerItem()->y() + listview->headerItem()->height() < listview->contentY()); + listview->setCurrentIndex(0); + QTRY_COMPARE(listview->contentY(), -listview->headerItem()->height()); + canvas->rootObject()->setProperty("showHeader", false); + + // Test keys canvas->show(); qApp->setActiveWindow(canvas); @@ -1488,6 +1508,8 @@ void tst_QSGListView::currentIndex() QTRY_VERIFY(canvas->hasFocus()); qApp->processEvents(); + listview->setCurrentIndex(0); + QTest::keyClick(canvas, Qt::Key_Down); QCOMPARE(listview->currentIndex(), 1); |