1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtQuickTemplates2/private/qquickcontainer_p.h>
#include <QtQuickControls2/qquickstyle.h>
#include <QtQuickTest/QtQuickTest>
#include <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtQuickTestUtils/private/visualtestutils_p.h>
#include <QtQuickControlsTestUtils/private/controlstestutils_p.h>
#include <QtQuick/private/qquicklistview_p.h>
using namespace QQuickVisualTestUtils;
using namespace QQuickControlsTestUtils;
class tst_qquickcontainer : public QQmlDataTest
{
Q_OBJECT
public:
tst_qquickcontainer();
private slots:
void zeroSize_data();
void zeroSize();
void skipReorderContentModelItem();
};
tst_qquickcontainer::tst_qquickcontainer()
: QQmlDataTest(QT_QMLTEST_DATADIR)
{
qputenv("QML_NO_TOUCH_COMPRESSION", "1");
QQuickStyle::setStyle("Basic");
}
enum ContentItemType {
View,
Repeater,
Positioner,
};
void tst_qquickcontainer::zeroSize_data()
{
QTest::addColumn<QString>("qmlFileName");
QTest::addColumn<ContentItemType>("contentItemType");
QTest::newRow("ListView") << "zeroSizeWithListView.qml" << View;
QTest::newRow("Repeater") << "zeroSizeWithRepeater.qml" << Repeater;
QTest::newRow("Repeater in Row") << "zeroSizeWithRepeaterInRow.qml" << Positioner;
}
// Tests that a zero-size Container with a QQuickItemView sub-class culls its items.
// Based on a use case involving SwipeView: QTBUG-125416
void tst_qquickcontainer::zeroSize()
{
QFETCH(QString, qmlFileName);
QFETCH(ContentItemType, contentItemType);
const bool isView = contentItemType == View;
const bool isPositioner = contentItemType == Positioner;
QQuickControlsApplicationHelper helper(this, qmlFileName);
QVERIFY2(helper.ready, helper.failureMessage());
centerOnScreen(helper.window);
helper.window->show();
QVERIFY(QTest::qWaitForWindowExposed(helper.window));
auto *text1 = helper.window->property("text1").value<QQuickItem *>();
QVERIFY(text1);
// Since the items also have zero sizes, they will also be culled by positioners.
QCOMPARE(QQuickItemPrivate::get(text1)->culled, isView || isPositioner);
auto *text2 = helper.window->property("text2").value<QQuickItem *>();
QVERIFY(text2);
QCOMPARE(QQuickItemPrivate::get(text2)->culled, isView || isPositioner);
auto *text3 = helper.window->property("text3").value<QQuickItem *>();
QVERIFY(text3);
QCOMPARE(QQuickItemPrivate::get(text3)->culled, isView || isPositioner);
// Add an item and check that it's culled appropriately.
QVERIFY(QMetaObject::invokeMethod(helper.window, "addTextItem"));
auto *container = helper.window->property("container").value<QQuickContainer *>();
QVERIFY(container);
auto *text4 = container->itemAt(3);
QVERIFY(text4);
if (isView || isPositioner) {
QVERIFY(QQuickTest::qIsPolishScheduled(helper.window));
QVERIFY(QQuickTest::qWaitForPolish(helper.window));
}
QCOMPARE(QQuickItemPrivate::get(text4)->culled, isView || isPositioner);
// Give it a non-zero size (via its parent, which it fills).
container->parentItem()->setWidth(text1->implicitWidth());
container->parentItem()->setHeight(text1->implicitHeight());
if (isView || isPositioner) {
QVERIFY(QQuickTest::qIsPolishScheduled(helper.window));
QVERIFY(QQuickTest::qWaitForPolish(helper.window));
}
QCOMPARE(QQuickItemPrivate::get(text1)->culled, false);
// This one won't be culled for views either, because of cacheBuffer (and
// clipping apparently doesn't affect culling, if we were to set clip to true).
QCOMPARE(QQuickItemPrivate::get(text2)->culled, false);
QCOMPARE(QQuickItemPrivate::get(text3)->culled, isView);
QCOMPARE(QQuickItemPrivate::get(text4)->culled, isView);
// Go back to a zero size.
container->parentItem()->setWidth(0);
container->parentItem()->setHeight(0);
if (isView || isPositioner) {
QVERIFY(QQuickTest::qIsPolishScheduled(helper.window));
QVERIFY(QQuickTest::qWaitForPolish(helper.window));
}
QCOMPARE(QQuickItemPrivate::get(text1)->culled, isView || isPositioner);
QCOMPARE(QQuickItemPrivate::get(text2)->culled, isView || isPositioner);
QCOMPARE(QQuickItemPrivate::get(text3)->culled, isView || isPositioner);
QCOMPARE(QQuickItemPrivate::get(text4)->culled, isView || isPositioner);
}
void tst_qquickcontainer::skipReorderContentModelItem()
{
QQuickControlsApplicationHelper helper(this, "skipReorderContentModelItem.qml");
QVERIFY2(helper.ready, helper.failureMessage());
centerOnScreen(helper.window);
helper.window->show();
QVERIFY(QTest::qWaitForWindowExposed(helper.window));
const auto *container = helper.window->property("navigationBar").value<QQuickContainer *>();
QVERIFY(container);
const auto *listView = container->property("listView").value<QQuickListView *>();
QVERIFY(listView);
const auto *contentModel = container->property("contentModel").value<QQmlObjectModel *>();
QVERIFY(contentModel);
QCOMPARE(listView->count(), contentModel->count());
int totalWidth = listView->spacing() * (contentModel->count() - 1);
for (int index = 0; index < contentModel->count(); index++)
totalWidth += qobject_cast<QQuickText *>(listView->itemAtIndex(index))->width();
QVERIFY(totalWidth > listView->width());
for (int index = 0; index < listView->count(); index++) {
const auto *textItem = qobject_cast<QQuickText *>(listView->itemAtIndex(index));
QCOMPARE(textItem->text().toInt(), index + 1);
}
}
QTEST_MAIN(tst_qquickcontainer)
#include "tst_qquickcontainer.moc"
|