aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-03-03 15:53:27 +0100
committerJ-P Nurmi <jpnurmi@digia.com>2014-08-08 00:25:49 +0200
commitce5dff18b9a61707617080be7be0cd688996ad6f (patch)
treeec8db965c99393e2540e776bff986e0abc99a029 /tests
parent08457385be89603d7c5ce84dce9ee36e0c6a0263 (diff)
ListView: add support for "pull back" header & footer
[ChangeLog][QtQuick][ListView] Introduced headerPositioning and footerPositioning properties to control whether header and footer are positioned inline, as overlays, or so that they slide away and can be pulled back regardless of the content position. Change-Id: Ifef1faf1ce6acf2b55cd1b6408e22ec2de841409 Reviewed-by: Alan Alpert <aalpert@blackberry.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicklistview/data/stickyPositioning-both.qml77
-rw-r--r--tests/auto/quick/qquicklistview/data/stickyPositioning-footer.qml70
-rw-r--r--tests/auto/quick/qquicklistview/data/stickyPositioning-header.qml70
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp409
-rw-r--r--tests/testapplications/listview/sticky.qml250
5 files changed, 876 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview/data/stickyPositioning-both.qml b/tests/auto/quick/qquicklistview/data/stickyPositioning-both.qml
new file mode 100644
index 0000000000..4bbe7a0053
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/stickyPositioning-both.qml
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+Rectangle {
+ width: 240
+ height: 320
+ ListView {
+ id: list
+ objectName: "list"
+ width: 100
+ height: 100
+ cacheBuffer: 0
+ anchors.centerIn: parent
+ model: testModel
+ orientation: testOrientation
+ layoutDirection: testLayoutDirection
+ verticalLayoutDirection: testVerticalLayoutDirection
+ delegate: Rectangle {
+ width: 10
+ height: 10
+ border.width: 1
+ border.color: "gray"
+ }
+ headerPositioning: ListView.PullBackHeader
+ header: Rectangle {
+ width: 10
+ height: 10
+ color: "red"
+ objectName: "header"
+ }
+ footerPositioning: ListView.PullBackFooter
+ footer: Rectangle {
+ width: 10
+ height: 10
+ color: "blue"
+ objectName: "footer"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/data/stickyPositioning-footer.qml b/tests/auto/quick/qquicklistview/data/stickyPositioning-footer.qml
new file mode 100644
index 0000000000..57773df37e
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/stickyPositioning-footer.qml
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+Rectangle {
+ width: 240
+ height: 320
+ ListView {
+ id: list
+ objectName: "list"
+ width: 100
+ height: 100
+ cacheBuffer: 0
+ anchors.centerIn: parent
+ model: testModel
+ orientation: testOrientation
+ layoutDirection: testLayoutDirection
+ verticalLayoutDirection: testVerticalLayoutDirection
+ delegate: Rectangle {
+ width: 10
+ height: 10
+ border.width: 1
+ border.color: "gray"
+ }
+ footerPositioning: ListView.PullBackFooter
+ footer: Rectangle {
+ width: 10
+ height: 10
+ color: "blue"
+ objectName: "footer"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/data/stickyPositioning-header.qml b/tests/auto/quick/qquicklistview/data/stickyPositioning-header.qml
new file mode 100644
index 0000000000..1ca9813baa
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/stickyPositioning-header.qml
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+Rectangle {
+ width: 240
+ height: 320
+ ListView {
+ id: list
+ objectName: "list"
+ width: 100
+ height: 100
+ cacheBuffer: 0
+ anchors.centerIn: parent
+ model: testModel
+ orientation: testOrientation
+ layoutDirection: testLayoutDirection
+ verticalLayoutDirection: testVerticalLayoutDirection
+ delegate: Rectangle {
+ width: 10
+ height: 10
+ border.width: 1
+ border.color: "gray"
+ }
+ headerPositioning: ListView.PullBackHeader
+ header: Rectangle {
+ width: 10
+ height: 10
+ color: "red"
+ objectName: "header"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index c8ab62cbbc..39610e57f7 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -228,6 +228,9 @@ private slots:
void QTBUG_36481();
void QTBUG_35920();
+ void stickyPositioning();
+ void stickyPositioning_data();
+
void roundingErrors();
void roundingErrors_data();
@@ -7309,6 +7312,412 @@ void tst_QQuickListView::QTBUG_35920()
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(10,100));
}
+Q_DECLARE_METATYPE(Qt::Orientation)
+
+void tst_QQuickListView::stickyPositioning()
+{
+ QFETCH(QString, fileName);
+
+ QFETCH(Qt::Orientation, orientation);
+ QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+
+ QFETCH(int, positionIndex);
+ QFETCH(QQuickItemView::PositionMode, positionMode);
+ QFETCH(QList<QPointF>, movement);
+
+ QFETCH(QPointF, headerPos);
+ QFETCH(QPointF, footerPos);
+
+ QQuickView *window = createView();
+
+ QaimModel model;
+ for (int i = 0; i < 20; i++)
+ model.addItem(QString::number(i), QString::number(i/10));
+
+ QQmlContext *ctxt = window->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testOrientation", orientation);
+ ctxt->setContextProperty("testLayoutDirection", layoutDirection);
+ ctxt->setContextProperty("testVerticalLayoutDirection", verticalLayoutDirection);
+
+ window->setSource(testFileUrl(fileName));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list");
+ QVERIFY(listview);
+
+ QQuickItem *contentItem = listview->contentItem();
+ QVERIFY(contentItem);
+
+ listview->positionViewAtIndex(positionIndex, positionMode);
+
+ foreach (const QPointF &offset, movement) {
+ listview->setContentX(listview->contentX() + offset.x());
+ listview->setContentY(listview->contentY() + offset.y());
+ }
+
+ if (listview->header()) {
+ QQuickItem *headerItem = listview->headerItem();
+ QVERIFY(headerItem);
+ QPointF actualPos = listview->mapFromItem(contentItem, headerItem->position());
+ QCOMPARE(actualPos, headerPos);
+ }
+
+ if (listview->footer()) {
+ QQuickItem *footerItem = listview->footerItem();
+ QVERIFY(footerItem);
+ QPointF actualPos = listview->mapFromItem(contentItem, footerItem->position());
+ QCOMPARE(actualPos, footerPos);
+ }
+
+ delete window;
+}
+
+void tst_QQuickListView::stickyPositioning_data()
+{
+ qRegisterMetaType<Qt::Orientation>();
+ qRegisterMetaType<Qt::LayoutDirection>();
+ qRegisterMetaType<QQuickItemView::VerticalLayoutDirection>();
+ qRegisterMetaType<QQuickItemView::PositionMode>();
+
+ QTest::addColumn<QString>("fileName");
+
+ QTest::addColumn<Qt::Orientation>("orientation");
+ QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+
+ QTest::addColumn<int>("positionIndex");
+ QTest::addColumn<QQuickItemView::PositionMode>("positionMode");
+ QTest::addColumn<QList<QPointF> >("movement");
+
+ QTest::addColumn<QPointF>("headerPos");
+ QTest::addColumn<QPointF>("footerPos");
+
+ // header at the top
+ QTest::newRow("top header") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 0 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(0,-10) << QPointF();
+
+ QTest::newRow("top header: 1/2 up") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-5))
+ << QPointF(0,-5) << QPointF();
+
+ QTest::newRow("top header: up") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-15))
+ << QPointF(0,0) << QPointF();
+
+ QTest::newRow("top header: 1/2 down") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-15) << QPointF(0,5))
+ << QPointF(0,-5) << QPointF();
+
+ QTest::newRow("top header: down") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-15) << QPointF(0,10))
+ << QPointF(0,-10) << QPointF();
+
+
+ // footer at the top
+ QTest::newRow("top footer") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 19 << QQuickItemView::End << QList<QPointF>()
+ << QPointF() << QPointF(0,-10);
+
+ QTest::newRow("top footer: 1/2 up") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 18 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,-5))
+ << QPointF() << QPointF(0,-5);
+
+ QTest::newRow("top footer: up") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 17 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,-15))
+ << QPointF() << QPointF(0,0);
+
+ QTest::newRow("top footer: 1/2 down") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 16 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,-15) << QPointF(0,5))
+ << QPointF() << QPointF(0,-5);
+
+ QTest::newRow("top footer: down") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 15 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,-15) << QPointF(0,10))
+ << QPointF() << QPointF(0,-10);
+
+
+ // header at the bottom
+ QTest::newRow("bottom header") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 0 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(0,100) << QPointF();
+
+ QTest::newRow("bottom header: 1/2 down") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,5))
+ << QPointF(0,95) << QPointF();
+
+ QTest::newRow("bottom header: down") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,15))
+ << QPointF(0,90) << QPointF();
+
+ QTest::newRow("bottom header: 1/2 up") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,15) << QPointF(0,-5))
+ << QPointF(0,95) << QPointF();
+
+ QTest::newRow("bottom header: up") << "stickyPositioning-header.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::BottomToTop
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,15) << QPointF(0,-10))
+ << QPointF(0,100) << QPointF();
+
+
+ // footer at the bottom
+ QTest::newRow("bottom footer") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 19 << QQuickItemView::End << QList<QPointF>()
+ << QPointF() << QPointF(0,100);
+
+ QTest::newRow("bottom footer: 1/2 down") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 18 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,5))
+ << QPointF() << QPointF(0,95);
+
+ QTest::newRow("bottom footer: down") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 17 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,15))
+ << QPointF() << QPointF(0,90);
+
+ QTest::newRow("bottom footer: 1/2 up") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 16 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,15) << QPointF(0,-5))
+ << QPointF() << QPointF(0,95);
+
+ QTest::newRow("bottom footer: up") << "stickyPositioning-footer.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 15 << QQuickItemView::End << (QList<QPointF>() << QPointF(0,15) << QPointF(0,-10))
+ << QPointF() << QPointF(0,100);
+
+
+ // header at the top (& footer at the bottom)
+ QTest::newRow("top header & bottom footer") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 0 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(0,-10) << QPointF(0,90);
+
+ QTest::newRow("top header & bottom footer: 1/2 up") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-5))
+ << QPointF(0,-5) << QPointF(0,95);
+
+ QTest::newRow("top header & bottom footer: up") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-15))
+ << QPointF(0,0) << QPointF(0,100);
+
+ QTest::newRow("top header & bottom footer: 1/2 down") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-15) << QPointF(0,5))
+ << QPointF(0,-5) << QPointF(0,95);
+
+ QTest::newRow("top header & bottom footer: down") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,-15) << QPointF(0,10))
+ << QPointF(0,-10) << QPointF(0,90);
+
+
+ // footer at the bottom (& header at the top)
+ QTest::newRow("bottom footer & top header") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(0,-10) << QPointF(0,90);
+
+ QTest::newRow("bottom footer & top header: 1/2 down") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,5))
+ << QPointF(0,-10) << QPointF(0,90);
+
+ QTest::newRow("bottom footer & top header: down") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,15))
+ << QPointF(0,-10) << QPointF(0,90);
+
+ QTest::newRow("bottom footer & top header: 1/2 up") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,15) << QPointF(0,-5))
+ << QPointF(0,-5) << QPointF(0,95);
+
+ QTest::newRow("bottom footer & top header: up") << "stickyPositioning-both.qml"
+ << Qt::Vertical << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(0,15) << QPointF(0,-10))
+ << QPointF(0,0) << QPointF(0,100);
+
+ // header on the left
+ QTest::newRow("left header") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 0 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(-10,0) << QPointF();
+
+ QTest::newRow("left header: 1/2 left") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-5,0))
+ << QPointF(-5,0) << QPointF();
+
+ QTest::newRow("left header: left") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-15,0))
+ << QPointF(0,0) << QPointF();
+
+ QTest::newRow("left header: 1/2 right") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-15,0) << QPointF(5,0))
+ << QPointF(-5,0) << QPointF();
+
+ QTest::newRow("left header: right") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-15,0) << QPointF(10,0))
+ << QPointF(-10,0) << QPointF();
+
+
+ // footer on the left
+ QTest::newRow("left footer") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 19 << QQuickItemView::End << QList<QPointF>()
+ << QPointF() << QPointF(-10,0);
+
+ QTest::newRow("left footer: 1/2 left") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 18 << QQuickItemView::End << (QList<QPointF>() << QPointF(-5,0))
+ << QPointF() << QPointF(-5,0);
+
+ QTest::newRow("left footer: left") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 17 << QQuickItemView::End << (QList<QPointF>() << QPointF(-15,0))
+ << QPointF() << QPointF(0,0);
+
+ QTest::newRow("left footer: 1/2 right") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 16 << QQuickItemView::End << (QList<QPointF>() << QPointF(-15,0) << QPointF(5,0))
+ << QPointF() << QPointF(-5,0);
+
+ QTest::newRow("left footer: right") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 15 << QQuickItemView::End << (QList<QPointF>() << QPointF(-15,0) << QPointF(10,0))
+ << QPointF() << QPointF(-10,0);
+
+
+ // header on the right
+ QTest::newRow("right header") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 0 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(100,0) << QPointF();
+
+ QTest::newRow("right header: 1/2 right") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(5,0))
+ << QPointF(95,0) << QPointF();
+
+ QTest::newRow("right header: right") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(15,0))
+ << QPointF(90,0) << QPointF();
+
+ QTest::newRow("right header: 1/2 left") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(15,0) << QPointF(-5,0))
+ << QPointF(95,0) << QPointF();
+
+ QTest::newRow("right header: left") << "stickyPositioning-header.qml"
+ << Qt::Horizontal << Qt::RightToLeft << QQuickListView::TopToBottom
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(15,0) << QPointF(-10,0))
+ << QPointF(100,0) << QPointF();
+
+
+ // footer on the right
+ QTest::newRow("right footer") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 19 << QQuickItemView::End << QList<QPointF>()
+ << QPointF() << QPointF(100,0);
+
+ QTest::newRow("right footer: 1/2 right") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 18 << QQuickItemView::End << (QList<QPointF>() << QPointF(5,0))
+ << QPointF() << QPointF(95,0);
+
+ QTest::newRow("right footer: right") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 17 << QQuickItemView::End << (QList<QPointF>() << QPointF(15,0))
+ << QPointF() << QPointF(90,0);
+
+ QTest::newRow("right footer: 1/2 left") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 16 << QQuickItemView::End << (QList<QPointF>() << QPointF(15,0) << QPointF(-5,0))
+ << QPointF() << QPointF(95,0);
+
+ QTest::newRow("right footer: left") << "stickyPositioning-footer.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 15 << QQuickItemView::End << (QList<QPointF>() << QPointF(15,0) << QPointF(-10,0))
+ << QPointF() << QPointF(100,0);
+
+
+ // header on the left (& footer on the right)
+ QTest::newRow("left header & right footer") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 0 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(-10,0) << QPointF(90,0);
+
+ QTest::newRow("left header & right footer: 1/2 left") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-5,0))
+ << QPointF(-5,0) << QPointF(95,0);
+
+ QTest::newRow("left header & right footer: left") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-15,0))
+ << QPointF(0,0) << QPointF(100,0);
+
+ QTest::newRow("left header & right footer: 1/2 right") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-15,0) << QPointF(5,0))
+ << QPointF(-5,0) << QPointF(95,0);
+
+ QTest::newRow("left header & right footer: right") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(-15,0) << QPointF(10,0))
+ << QPointF(-10,0) << QPointF(90,0);
+
+
+ // footer on the right (& header on the left)
+ QTest::newRow("right footer & left header") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << QList<QPointF>()
+ << QPointF(-10,0) << QPointF(90,0);
+
+ QTest::newRow("right footer & left header: 1/2 right") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 1 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(5,0))
+ << QPointF(-10,0) << QPointF(90,0);
+
+ QTest::newRow("right footer & left header: right") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 2 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(15,0))
+ << QPointF(-10,0) << QPointF(90,0);
+
+ QTest::newRow("right footer & left header: 1/2 left") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 3 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(15,0) << QPointF(-5,0))
+ << QPointF(-5,0) << QPointF(95,0);
+
+ QTest::newRow("right footer & left header: left") << "stickyPositioning-both.qml"
+ << Qt::Horizontal << Qt::LeftToRight << QQuickListView::TopToBottom
+ << 4 << QQuickItemView::Beginning << (QList<QPointF>() << QPointF(15,0) << QPointF(-10,0))
+ << QPointF(0,0) << QPointF(100,0);
+}
+
void tst_QQuickListView::roundingErrors()
{
QFETCH(bool, pixelAligned);
diff --git a/tests/testapplications/listview/sticky.qml b/tests/testapplications/listview/sticky.qml
new file mode 100644
index 0000000000..6dcdf6b57e
--- /dev/null
+++ b/tests/testapplications/listview/sticky.qml
@@ -0,0 +1,250 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.4
+import QtQuick.Window 2.1
+import QtQuick.Layouts 1.1
+import QtQuick.Controls 1.1
+import QtQuick.Controls.Styles 1.1
+import Qt.labs.settings 1.0
+
+ApplicationWindow {
+ id: window
+
+ width: 640
+ height: 480
+ visible: true
+
+ property int hspacing: 10
+ property int vspacing: 35
+
+ Settings {
+ property alias windowX: window.x
+ property alias windowY: window.y
+ property alias windowWidth: window.width
+ property alias windowHeight: window.height
+ property alias orientation: oriItem.currentIndex
+ property alias layoutDirection: ldItem.currentIndex
+ property alias verticalLayoutDirection: vldItem.currentIndex
+ property alias hasHeader: hItem.checked
+ property alias headerPositioning: shItem.currentIndex
+ property alias hasFooter: fItem.checked
+ property alias footerPositioning: sfItem.currentIndex
+ property alias clipEnabled: clipItem.checked
+ property alias filterEnabled: filterItem.checked
+ property alias opacityEnabled: opacityItem.checked
+ property alias inlineSections: isItem.checked
+ property alias stickyCurrentSection: scsItem.checked
+ property alias stickyNextSection: snsItem.checked
+ }
+
+ toolBar: GridLayout {
+ rows: 3
+ flow: GridLayout.TopToBottom
+
+ anchors.margins: hspacing
+ anchors.left: parent.left
+ anchors.right: parent.right
+
+ ComboBox { id: oriItem; currentIndex: 1; model: ["Horizontal", "Vertical"] }
+ ComboBox { id: ldItem; model: ["LeftToRight", "RightToLeft"] }
+ ComboBox { id: vldItem; model: ["TopToBottom", "BottomToTop"] }
+
+ CheckBox { id: clipItem; text: "Clip"; checked: true }
+ CheckBox { id: opacityItem; text: "Opaque"; checked: true }
+ CheckBox { id: filterItem; text: "Filter" }
+
+ CheckBox { id: hItem; text: "Header:" }
+ CheckBox { id: fItem; text: "Footer:" }
+ Item { width: 1; height: 1 }
+
+ ComboBox { id: shItem; model: shModel; textRole: "name"; enabled: hItem.checked }
+ ComboBox { id: sfItem; model: sfModel; textRole: "name"; enabled: fItem.checked }
+ Item { width: 1; height: 1 }
+
+ CheckBox { id: scsItem; text: "Sticky current section" }
+ CheckBox { id: snsItem; text: "Sticky next section" }
+ CheckBox { id: isItem; text: "Inline sections" }
+
+ Button { text: "Beginning"; onClicked: listview.positionViewAtBeginning() }
+ Button { text: "Middle"; onClicked: listview.positionViewAtIndex(50, ListView.Center) }
+ Button { text: "End"; onClicked: listview.positionViewAtEnd() }
+ }
+
+ ListModel {
+ id: shModel
+ ListElement { name: "Inline"; value: ListView.InlineHeader }
+ ListElement { name: "Overlay"; value: ListView.OverlayHeader }
+ ListElement { name: "PullBack"; value: ListView.PullBackHeader }
+ }
+
+ ListModel {
+ id: sfModel
+ ListElement { name: "Inline"; value: ListView.InlineFooter }
+ ListElement { name: "Overlay"; value: ListView.OverlayFooter }
+ ListElement { name: "PullBack"; value: ListView.PullBackFooter }
+ }
+
+ statusBar: RowLayout {
+ anchors.margins: window.hspacing
+ anchors.left: parent.left
+ anchors.right: parent.right
+ Text {
+ anchors.left: parent.left
+ text: listview.currentSection ? "#" + listview.currentSection : ""
+ visible: scsItem.checked || snsItem.checked || isItem.checked
+ }
+ Text {
+ anchors.right: parent.right
+ property string pos: listview.isVertical ? listview.contentY.toFixed(2) : listview.contentX.toFixed(2)
+ property string size: listview.isVertical ? listview.contentHeight.toFixed(2) : listview.contentWidth.toFixed(2)
+ function padded(str) {
+ return String(" " + str).slice(-8)
+ }
+ text: padded(pos) + " /" + padded(size)
+ }
+ }
+
+ ListView {
+ id: listview
+
+ property bool isVertical: orientation == ListView.Vertical
+
+ anchors.fill: parent
+ anchors.leftMargin: window.hspacing
+ anchors.rightMargin: window.hspacing
+ anchors.topMargin: window.vspacing
+ anchors.bottomMargin: window.vspacing
+
+ clip: clipItem.checked
+
+ orientation: oriItem.currentIndex === 0 ? ListView.Horizontal : ListView.Vertical
+ layoutDirection: ldItem.currentIndex === 0 ? ListView.LeftToRight : ListView.RightToLeft
+ verticalLayoutDirection: vldItem.currentIndex === 0 ? ListView.TopToBottom : ListView.BottomToTop
+
+ model: ListModel {
+ Component.onCompleted: {
+ for (var i = 0; i < 100; ++i)
+ append({section: Math.floor(i / 10)})
+ }
+ }
+
+ delegate: Rectangle {
+ clip: true
+ property bool filterOut: filterItem.checked && index % 5
+ visible: !filterOut
+ width: filterOut ? 0 : parent && listview.isVertical ? parent.width : label.implicitHeight
+ height: filterOut ? 0 : !parent || listview.isVertical ? label.implicitHeight : parent.height
+ color: index % 2 ? "#ffffff" : "#f3f3f3"
+ Text {
+ id: label
+ anchors.centerIn: parent
+ rotation: listview.isVertical ? 0 : -90
+ text: index
+ }
+ }
+
+ section.property: "section"
+ section.delegate: Rectangle {
+ width: parent && listview.orientation == ListView.Vertical ? parent.width : sectionLabel.implicitHeight
+ height: !parent || listview.orientation == ListView.Vertical ? sectionLabel.implicitHeight : parent.height
+ color: "darkgray"
+ opacity: opacityItem.checked ? 1.0 : 0.8
+ Text {
+ id: sectionLabel
+ anchors.centerIn: parent
+ rotation: listview.isVertical ? 0 : -90
+ text: "#" + section
+ }
+ }
+ section.labelPositioning: (isItem.checked ? ViewSection.InlineLabels : 0) |
+ (scsItem.checked ? ViewSection.CurrentLabelAtStart : 0) |
+ (snsItem.checked ? ViewSection.NextLabelAtEnd : 0)
+
+ headerPositioning: shModel.get(shItem.currentIndex).value
+ header: hItem.checked ? headerComponent : null
+
+ footerPositioning: sfModel.get(sfItem.currentIndex).value
+ footer: fItem.checked ? footerComponent : null
+
+ Rectangle {
+ border.width: 1
+ anchors.fill: parent
+ color: "transparent"
+ border.color: "darkgray"
+ }
+
+ Component {
+ id: headerComponent
+ Rectangle {
+ z: 3
+ width: parent && listview.orientation == ListView.Vertical ? parent.width : headerLabel.implicitHeight * 2
+ height: !parent || listview.orientation == ListView.Vertical ? headerLabel.implicitHeight * 2 : parent.height
+ color: "steelblue"
+ opacity: opacityItem.checked ? 1.0 : 0.8
+ Text {
+ id: headerLabel
+ text: "Header"
+ font.pointSize: 12
+ anchors.centerIn: parent
+ rotation: listview.isVertical ? 0 : -90
+ }
+ }
+ }
+
+ Component {
+ id: footerComponent
+ Rectangle {
+ z: 3
+ width: parent && listview.orientation == ListView.Vertical ? parent.width : footerLabel.implicitHeight * 2
+ height: !parent || listview.orientation == ListView.Vertical ? footerLabel.implicitHeight * 2 : parent.height
+ color: "steelblue"
+ opacity: opacityItem.checked ? 1.0 : 0.8
+ Text {
+ id: footerLabel
+ text: "Footer"
+ font.pointSize: 10
+ anchors.centerIn: parent
+ rotation: listview.isVertical ? 0 : -90
+ }
+ }
+ }
+ }
+}