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
|
// 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>
using namespace QQuickVisualTestUtils;
using namespace QQuickControlsTestUtils;
class tst_qquickcontainer : public QQmlDataTest
{
Q_OBJECT
public:
tst_qquickcontainer();
private slots:
void zeroSize_data();
void zeroSize();
};
tst_qquickcontainer::tst_qquickcontainer()
: QQmlDataTest(QT_QMLTEST_DATADIR)
{
qputenv("QML_NO_TOUCH_COMPRESSION", "1");
QQuickStyle::setStyle("Basic");
}
void tst_qquickcontainer::zeroSize_data()
{
QTest::addColumn<QString>("qmlFileName");
QTest::addColumn<bool>("isItemView");
QTest::newRow("ListView") << "zeroSizeWithListView.qml" << true;
// See QQuickContainerPrivate::maybeCullItem for why this is false.
QTest::newRow("Repeater") << "zeroSizeWithRepeater.qml" << false;
}
// 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(bool, isItemView);
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);
QCOMPARE(QQuickItemPrivate::get(text1)->culled, isItemView);
auto *text2 = helper.window->property("text2").value<QQuickItem *>();
QVERIFY(text2);
QCOMPARE(QQuickItemPrivate::get(text2)->culled, isItemView);
auto *text3 = helper.window->property("text3").value<QQuickItem *>();
QVERIFY(text3);
QCOMPARE(QQuickItemPrivate::get(text3)->culled, isItemView);
// 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);
QCOMPARE(QQuickItemPrivate::get(text4)->culled, isItemView);
// Give it a non-zero size (via its parent, which it fills).
container->parentItem()->setWidth(text1->implicitWidth());
container->parentItem()->setHeight(text1->implicitHeight());
if (isItemView) {
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, isItemView);
QCOMPARE(QQuickItemPrivate::get(text4)->culled, isItemView);
// Go back to a zero size.
container->parentItem()->setWidth(0);
container->parentItem()->setHeight(0);
if (isItemView) {
QVERIFY(QQuickTest::qIsPolishScheduled(helper.window));
QVERIFY(QQuickTest::qWaitForPolish(helper.window));
}
QCOMPARE(QQuickItemPrivate::get(text1)->culled, isItemView);
QCOMPARE(QQuickItemPrivate::get(text2)->culled, isItemView);
QCOMPARE(QQuickItemPrivate::get(text3)->culled, isItemView);
QCOMPARE(QQuickItemPrivate::get(text4)->culled, isItemView);
}
QTEST_MAIN(tst_qquickcontainer)
#include "tst_qquickcontainer.moc"
|