aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2022-01-07 15:43:59 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-20 18:33:06 +0000
commitdef37f47b0b07070ef1395adeab092406fe13af2 (patch)
tree73471dab445a2799d75c8f18aa5c07ae988d5e6e /tests
parent905eea6c506eb87079d416fdd8e2ec640a7c130d (diff)
QQuickListView: Stop overlap for section and firstItem delegates
Problem: The first delegate after a section delegate would have the same position as the section delegate, if the section delegate is invisible during initialization. In case the section delegates become visible later on during program execution, the delegates would be re-positioned again in the QQuickListViewPrivate::layoutVisibleItems function. But this would not call setPosition for the first item (delegate). It would only call setPosition for all delegates after the first one. This would mean that the position for the first delegate would never be updated, after the delegate was first created. Solution: Call FxListItemSG::setPosition() for the first item in QQuickListViewPrivate::layoutVisibleItems, just like we're already doing for all the items after the first one in the for-loop. Fixes: QTBUG-94848 Change-Id: I34a5ada336ab507b31e3675a1c11eba066fa139a Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 3aad05bc09f40d81df7748cbc246974230a3ca17) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicklistview2/data/sectionsNoOverlap.qml124
-rw-r--r--tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp49
2 files changed, 173 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview2/data/sectionsNoOverlap.qml b/tests/auto/quick/qquicklistview2/data/sectionsNoOverlap.qml
new file mode 100644
index 0000000000..4cf48a567c
--- /dev/null
+++ b/tests/auto/quick/qquicklistview2/data/sectionsNoOverlap.qml
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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
+import QtQuick.Controls
+
+Rectangle {
+ property string sectionProperty: "section"
+ property int sectionPositioning: ViewSection.InlineLabels
+
+ width: 640
+ height: 480
+ color: "#FFFFFF"
+
+ resources: [
+ Component {
+ id: myDelegate
+ Text {
+ objectName: model.title
+ width: parent.width
+ height: 40
+ text: "NormalDelegate: " + model.title
+ visible: model.isVisible
+ verticalAlignment: Text.AlignVCenter
+ }
+ }
+ ]
+ ListView {
+ id: list
+ objectName: "list"
+ anchors.fill: parent
+ clip: true
+
+ model: ListModel {
+ ListElement {
+ title: "element1"
+ isVisible: true
+ section: "section1"
+ }
+ ListElement {
+ title: "element2"
+ isVisible: true
+ section: "section1"
+ }
+ ListElement {
+ title: "element3"
+ isVisible: true
+ section: "section2"
+ }
+ ListElement {
+ title: "element4"
+ isVisible: true
+ section: "section2"
+ }
+ }
+
+ delegate: myDelegate
+
+ section.property: "section"
+ section.criteria: ViewSection.FullString
+ section.delegate: Component {
+ Text {
+ id: sectionDelegate
+ objectName: section
+ visible: false
+ width: parent.width
+ height: visible ? 48 : 0
+ text: "Section delegate: " + section
+ verticalAlignment: Text.AlignVCenter
+ elide: Text.ElideMiddle
+ Component.onCompleted: function(){
+ Qt.callLater(function(){sectionDelegate.visible = true})
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
index b177b69602..7a39cec598 100644
--- a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
+++ b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
@@ -52,6 +52,8 @@ private slots:
void delegateChooserEnumRole();
void QTBUG_92809();
void footerUpdate();
+
+ void sectionsNoOverlap();
};
tst_QQuickListView2::tst_QQuickListView2()
@@ -223,6 +225,53 @@ void tst_QQuickListView2::footerUpdate()
QTRY_COMPARE(footer->y(), 0);
}
+void tst_QQuickListView2::sectionsNoOverlap()
+{
+ QScopedPointer<QQuickView> window(createView());
+ QTRY_VERIFY(window);
+ window->setSource(testFileUrl("sectionsNoOverlap.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list");
+ QTRY_VERIFY(listview != nullptr);
+
+ QQuickItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != nullptr);
+ QVERIFY(QQuickTest::qWaitForItemPolished(listview));
+
+ const unsigned int sectionCount = 2, normalDelegateCount = 2;
+ const unsigned int expectedSectionHeight = 48;
+ const unsigned int expectedNormalDelegateHeight = 40;
+
+ unsigned int normalDelegateCounter = 0;
+ for (unsigned int sectionIndex = 0; sectionIndex < sectionCount; ++sectionIndex) {
+ QQuickItem *sectionDelegate =
+ findItem<QQuickItem>(contentItem, "section" + QString::number(sectionIndex + 1));
+ QVERIFY(sectionDelegate);
+
+ QCOMPARE(sectionDelegate->height(), expectedSectionHeight);
+ QVERIFY(sectionDelegate->isVisible());
+ QCOMPARE(sectionDelegate->y(),
+ qreal(sectionIndex * expectedSectionHeight
+ + (sectionIndex * normalDelegateCount * expectedNormalDelegateHeight)));
+
+ for (; normalDelegateCounter < ((sectionIndex + 1) * normalDelegateCount);
+ ++normalDelegateCounter) {
+ QQuickItem *normalDelegate = findItem<QQuickItem>(
+ contentItem, "element" + QString::number(normalDelegateCounter + 1));
+ QVERIFY(normalDelegate);
+
+ QCOMPARE(normalDelegate->height(), expectedNormalDelegateHeight);
+ QVERIFY(normalDelegate->isVisible());
+ QCOMPARE(normalDelegate->y(),
+ qreal((sectionIndex + 1) * expectedSectionHeight
+ + normalDelegateCounter * expectedNormalDelegateHeight
+ + listview->spacing() * normalDelegateCounter));
+ }
+ }
+}
+
QTEST_MAIN(tst_QQuickListView2)
#include "tst_qquicklistview2.moc"