diff options
Diffstat (limited to 'tests/auto/quick')
6 files changed, 242 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickmousearea/data/containsMouse.qml b/tests/auto/quick/qquickmousearea/data/containsMouse.qml new file mode 100644 index 0000000000..c4f1299e49 --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/containsMouse.qml @@ -0,0 +1,14 @@ +import QtQuick 2.15 + +Rectangle { + width: 200 + height: 200 + visible: true + MouseArea { + id: mouseArea + objectName: "mouseArea" + anchors.fill: parent + hoverEnabled: true + visible: false + } +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 91fcae40af..1c99357ab7 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -160,6 +160,7 @@ private slots: void mask(); void nestedEventDelivery(); void settingHiddenInPressUngrabs(); + void containsMouseAndVisibility(); private: int startDragDistance() const { @@ -2450,6 +2451,55 @@ void tst_QQuickMouseArea::settingHiddenInPressUngrabs() QVERIFY(!mouseArea->pressed()); } +// QTBUG-87197 +void tst_QQuickMouseArea::containsMouseAndVisibility() +{ + QQuickView window; + QByteArray errorMessage; + QVERIFY2(QQuickTest::initView(window, testFileUrl("containsMouse.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea"); + QVERIFY(mouseArea != nullptr); + QVERIFY(!mouseArea->isVisible()); + + QTest::mouseMove(&window, QPoint(10, 10)); + QTRY_VERIFY(!mouseArea->hovered()); + + mouseArea->setVisible(true); + QVERIFY(mouseArea->isVisible()); + QTRY_VERIFY(mouseArea->hovered()); + + /* we (ab-)use QPointF() as the 'reset' value in QQuickWindow's leave-event handling, + but can't verify that this leaves an invalid interpretation of states for position + QPoint(0, 0) as QTest::mouseMove interprets a null-position as "center of the window". + + So instead, verify the current (unexpectedly expected) behavior as far as testing is + concern. + */ + QTest::mouseMove(&window, QPoint(0, 0)); + QTRY_VERIFY(mouseArea->hovered()); + QTRY_VERIFY(mouseArea->isUnderMouse()); + + // move to the edge (can't move outside) + QTest::mouseMove(&window, QPoint(window.width() - 1, window.height() / 2)); + // then pretend we left + QEvent event(QEvent::Leave); + QGuiApplication::sendEvent(&window, &event); + QVERIFY(!mouseArea->hovered()); + + // toggle mouse area visibility - the hover state should not change + mouseArea->setVisible(false); + QVERIFY(!mouseArea->isVisible()); + QVERIFY(!mouseArea->hovered()); + + mouseArea->setVisible(true); + QVERIFY(mouseArea->isVisible()); + QVERIFY(!mouseArea->hovered()); +} + QTEST_MAIN(tst_QQuickMouseArea) #include "tst_qquickmousearea.moc" diff --git a/tests/auto/quick/qquicktableview/data/sizefromdelegate.qml b/tests/auto/quick/qquicktableview/data/sizefromdelegate.qml new file mode 100644 index 0000000000..b4a04c89cb --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/sizefromdelegate.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 + +Item { + width: 640 + height: 450 + + property alias tableView: tableView + + TableView { + id: tableView + width: 600 + height: 400 + anchors.margins: 1 + delegate: tableViewDelegate + columnSpacing: 1 + rowSpacing: 1 + } + + Component { + id: tableViewDelegate + Rectangle { + color: "lightgray" + implicitWidth: text.width + implicitHeight: text.height + + Text { + id: text + anchors.centerIn: parent + text: modelData + } + } + } + +} diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index d489a873e4..d14c37d8e3 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -121,7 +121,9 @@ private slots: void checkForceLayoutFunction(); void checkForceLayoutEndUpDoingALayout(); void checkForceLayoutDuringModelChange(); + void checkForceLayoutWhenAllItemsAreHidden(); void checkContentWidthAndHeight(); + void checkContentWidthAndHeightForSmallTables(); void checkPageFlicking(); void checkExplicitContentWidthAndHeight(); void checkExtents_origin(); @@ -625,6 +627,38 @@ void tst_QQuickTableView::checkForceLayoutDuringModelChange() QCOMPARE(tableView->rows(), initialRowCount + 1); } +void tst_QQuickTableView::checkForceLayoutWhenAllItemsAreHidden() +{ + // Check that you can have a TableView where all columns are + // initially hidden, and then show some columns and call + // forceLayout(). This should make the columns become visible. + LOAD_TABLEVIEW("forcelayout.qml"); + + // Tell all columns to be hidden + const char *propertyName = "columnWidths"; + view->rootObject()->setProperty(propertyName, 0); + + const int rows = 3; + const int columns = 3; + auto model = TestModelAsVariant(rows, columns); + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + // Check that the we have no items loaded + QCOMPARE(tableViewPrivate->loadedColumns.count(), 0); + QCOMPARE(tableViewPrivate->loadedRows.count(), 0); + QCOMPARE(tableViewPrivate->loadedItems.count(), 0); + + // Tell all columns to be visible + view->rootObject()->setProperty(propertyName, 10); + tableView->forceLayout(); + + QCOMPARE(tableViewPrivate->loadedRows.count(), rows); + QCOMPARE(tableViewPrivate->loadedColumns.count(), columns); + QCOMPARE(tableViewPrivate->loadedItems.count(), rows * columns); +} + void tst_QQuickTableView::checkContentWidthAndHeight() { // Check that contentWidth/Height reports the correct size of the @@ -673,6 +707,30 @@ void tst_QQuickTableView::checkContentWidthAndHeight() QCOMPARE(tableView->contentHeight(), expectedSizeInit); } +void tst_QQuickTableView::checkContentWidthAndHeightForSmallTables() +{ + // For tables where all the columns in the model are loaded, we know + // the exact table width, and can therefore update the content width + // if e.g new rows are added or removed. The same is true for rows. + // This test will check that we do so. + LOAD_TABLEVIEW("sizefromdelegate.qml"); + + TestModel model(3, 3); + tableView->setModel(QVariant::fromValue(&model)); + WAIT_UNTIL_POLISHED; + + const qreal initialContentWidth = tableView->contentWidth(); + const qreal initialContentHeight = tableView->contentHeight(); + const QString longText = QStringLiteral("Adding a row with a very long text"); + model.insertRow(0); + model.setModelData(QPoint(0, 0), QSize(1, 1), longText); + + WAIT_UNTIL_POLISHED; + + QVERIFY(tableView->contentWidth() > initialContentWidth); + QVERIFY(tableView->contentHeight() > initialContentHeight); +} + void tst_QQuickTableView::checkPageFlicking() { // Check that we rebuild the table instead of refilling edges, if the viewport moves diff --git a/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml b/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml new file mode 100644 index 0000000000..e6f07b4687 --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml @@ -0,0 +1,16 @@ +import QtQuick 2.12 + +Rectangle { + width: 200 + height: 200 + TextInput { + objectName: "textInput" + leftPadding: 10 + focus: true + cursorDelegate: Rectangle { + objectName: "cursorDelegate" + width: 5 + color: "red" + } + } +} diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 2e64c80b85..ac502bcb28 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -236,6 +236,7 @@ private slots: void QTBUG_51115_readOnlyResetsSelection(); void QTBUG_77814_InsertRemoveNoSelection(); + void checkCursorDelegateWhenPaddingChanged(); private: void simulateKey(QWindow *, int key); @@ -7054,6 +7055,35 @@ void tst_qquicktextinput::QTBUG_77814_InsertRemoveNoSelection() QCOMPARE(textInput->selectedText(), QString()); } +void tst_qquicktextinput::checkCursorDelegateWhenPaddingChanged() +{ + QQuickView view; + view.setSource(testFileUrl("checkCursorDelegateWhenPaddingChanged.qml")); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QQuickTextInput *textInput = view.rootObject()->findChild<QQuickTextInput *>("textInput"); + QVERIFY(textInput); + + QQuickItem *cursorDelegate = textInput->findChild<QQuickItem *>("cursorDelegate"); + QVERIFY(cursorDelegate); + + QCOMPARE(cursorDelegate->x(), textInput->leftPadding()); + QCOMPARE(cursorDelegate->y(), textInput->topPadding()); + + textInput->setPadding(5); + QCOMPARE(cursorDelegate->x(), textInput->leftPadding()); + QCOMPARE(cursorDelegate->y(), textInput->topPadding()); + + textInput->setTopPadding(10); + QCOMPARE(cursorDelegate->x(), textInput->leftPadding()); + QCOMPARE(cursorDelegate->y(), textInput->topPadding()); + + textInput->setLeftPadding(10); + QCOMPARE(cursorDelegate->x(), textInput->leftPadding()); + QCOMPARE(cursorDelegate->y(), textInput->topPadding()); +} + QTEST_MAIN(tst_qquicktextinput) #include "tst_qquicktextinput.moc" |