From 8b9a67dd7b2c270f00bc48e1aa3cff50cdf058e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Tue, 24 Sep 2019 15:56:50 +0200 Subject: Fix bug when highlight was not respected after currentIndex changed QQuickListViewPrivate::fixup() seems to only do "fixup" if moveReason != QQuickListViewPrivate::SetIndex By default, moveReason is set to Other. In the snippet given in QTBUG-77418, this is why the highlight was respected when resizing the ListView initially. However, after the currentIndex was changed, moveReason was changed to SetIndex. When we then resized the ListView, it still had the value SetIndex, and would fail to "fixup" properly. Since the ListView preferredHighlightBegin is bound to width, we should set moveReason to Other in the property setters that are related to highlight. This is then consistent with how setCurrentIndex() does it (it similarly sets d->moveReason = QQuickItemViewPrivate::SetIndex;) Change-Id: I7edf77fc977e8c7e3fc656ff5bb22b4dd01afbe4 Task-number: QTBUG-77418 Reviewed-by: Richard Moe Gustavsen --- .../quick/qquicklistview/tst_qquicklistview.cpp | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index b896418de0..9419dae362 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -1943,6 +1943,31 @@ void tst_QQuickListView::enforceRange() QTRY_COMPARE(listview->currentIndex(), 6); + // Test for [QTBUG-77418] { + // explicit set current index + listview->setCurrentIndex(5); + QTRY_COMPARE(listview->contentY(), 0); + + // then check if contentY changes if the highlight range is changed + listview->setPreferredHighlightBegin(80); + listview->setPreferredHighlightEnd(80); + QTRY_COMPARE(listview->contentY(), 20); + + // verify that current index does not change with no highlight + listview->setHighlightRangeMode(QQuickListView::NoHighlightRange); + listview->setContentY(100); + QTRY_COMPARE(listview->currentIndex(), 5); + + // explicit set current index, contentY should not change now + listview->setCurrentIndex(6); + QTRY_COMPARE(listview->contentY(), 100); + QTest::qWait(50); // This was needed in order to reproduce a failure for the following test + + // verify that contentY changes if we turn on highlight again + listview->setHighlightRangeMode(QQuickListView::StrictlyEnforceRange); + QTRY_COMPARE(listview->contentY(), 40); + // } Test for [QTBUG-77418] + // change model QaimModel model2; for (int i = 0; i < 5; i++) -- cgit v1.2.3 From 290dc2da70655db9d4590600dfd37b825b81c1f8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 7 Oct 2019 11:09:47 +0200 Subject: Be more fussy about the MakeDay() calculation The ES Date spec goes into minute detail about doing various algorithms in the dumbest possible way (like InLeapYear() calling DaysInYear(), rather than the other way round) but, in MakeDay(), leaves the implementation to solve the problem of finding the start of the first day of a specified month in a given year. So exercise the freedom we have in that to be a little more robust; and actually check we have met the conditions the spec requires, returning NaN (as specified) if not. Added tests for some denormal dates and date-times and for a date mentioned in QTBUG-78996. Task-number: QTBUG-78996 Change-Id: I8d9a841dd1f1d9995273a3de8f6f9130207c7c2b Reviewed-by: Ulf Hermann Reviewed-by: Qt CI Bot --- .../qml/qqmlecmascript/data/checkDate-October.qml | 12 ++++ .../qqmlecmascript/data/checkDate-denormal-Feb.qml | 11 +++ .../data/checkDate-denormal-March.qml | 11 +++ .../data/checkDate-denormal-leap.qml | 11 +++ .../data/checkDate-denormal-wrap.qml | 11 +++ .../data/checkDate-denormal-year.qml | 11 +++ .../qqmlecmascript/data/checkDateTime-October.qml | 16 +++++ .../data/checkDateTime-denormal-March.qml | 15 ++++ .../data/checkDateTime-denormal-hours.qml | 15 ++++ .../data/checkDateTime-denormal-leap.qml | 15 ++++ .../data/checkDateTime-denormal-minutes.qml | 15 ++++ .../data/checkDateTime-denormal-seconds.qml | 15 ++++ .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 80 ++++++++++++++++++++++ 13 files changed, 238 insertions(+) create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDate-October.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDateTime-October.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-March.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-hours.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-leap.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-minutes.qml create mode 100644 tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-seconds.qml (limited to 'tests') diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-October.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-October.qml new file mode 100644 index 0000000000..6686831e1c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDate-October.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + // QTBUG-78996 + dateProperty = new Date(2019, 9, 3) + boolProperty = (dateProperty.getFullYear() == 2019 + && dateProperty.getMonth() == 9 + && dateProperty.getDate() == 3) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml new file mode 100644 index 0000000000..29ec40ffbd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateProperty = new Date(2019, 2, 0) // Feb 28th + boolProperty = (dateProperty.getFullYear() == 2019 + && dateProperty.getMonth() == 1 + && dateProperty.getDate() == 28) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml new file mode 100644 index 0000000000..7fc8bf43bd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateProperty = new Date(2019, 1, 29) // March 1st + boolProperty = (dateProperty.getFullYear() == 2019 + && dateProperty.getMonth() == 2 + && dateProperty.getDate() == 1) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml new file mode 100644 index 0000000000..6dd84810e6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateProperty = new Date(2020, 2, 0) // Feb 29th + boolProperty = (dateProperty.getFullYear() == 2020 + && dateProperty.getMonth() == 1 + && dateProperty.getDate() == 29) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml new file mode 100644 index 0000000000..ddb79727ef --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateProperty = new Date(2017, 40, -61) // 2020, Feb 29th + boolProperty = (dateProperty.getFullYear() == 2020 + && dateProperty.getMonth() == 1 + && dateProperty.getDate() == 29) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml new file mode 100644 index 0000000000..90514c39c8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateProperty = new Date(2019, 12, 0) // Dec 31 + boolProperty = (dateProperty.getFullYear() == 2019 + && dateProperty.getMonth() == 11 + && dateProperty.getDate() == 31) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDateTime-October.qml b/tests/auto/qml/qqmlecmascript/data/checkDateTime-October.qml new file mode 100644 index 0000000000..c97076f887 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDateTime-October.qml @@ -0,0 +1,16 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + // QTBUG-78996 + dateTimeProperty = new Date(2019, 9, 3, 12) + boolProperty = (dateTimeProperty.getFullYear() == 2019 + && dateTimeProperty.getMonth() == 9 + && dateTimeProperty.getDate() == 3 + && dateTimeProperty.getHours() == 12 + && dateTimeProperty.getMinutes() == 0 + && dateTimeProperty.getSeconds() == 0 + && dateTimeProperty.getMilliseconds() == 0) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-March.qml b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-March.qml new file mode 100644 index 0000000000..2b6b9af3e1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-March.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateTimeProperty = new Date(2019, 1, 28, 23, 59, 59, 1001) // 2019-3-1 0:0:0.001 + boolProperty = (dateTimeProperty.getFullYear() == 2019 + && dateTimeProperty.getMonth() == 2 + && dateTimeProperty.getDate() == 1 + && dateTimeProperty.getHours() == 0 + && dateTimeProperty.getMinutes() == 0 + && dateTimeProperty.getSeconds() == 0 + && dateTimeProperty.getMilliseconds() == 1) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-hours.qml b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-hours.qml new file mode 100644 index 0000000000..7d018e2904 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-hours.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateTimeProperty = new Date(2019, 11, 31, 1440) // 2020-2-29 0:0:0 + boolProperty = (dateTimeProperty.getFullYear() == 2020 + && dateTimeProperty.getMonth() == 1 + && dateTimeProperty.getDate() == 29 + && dateTimeProperty.getHours() == 0 + && dateTimeProperty.getMinutes() == 0 + && dateTimeProperty.getSeconds() == 0 + && dateTimeProperty.getMilliseconds() == 0) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-leap.qml b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-leap.qml new file mode 100644 index 0000000000..0a7687c669 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-leap.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateTimeProperty = new Date(2020, 2, 1, 0, 0, 0, -1) // 2020-2-29 23:59:59.999 + boolProperty = (dateTimeProperty.getFullYear() == 2020 + && dateTimeProperty.getMonth() == 1 + && dateTimeProperty.getDate() == 29 + && dateTimeProperty.getHours() == 23 + && dateTimeProperty.getMinutes() == 59 + && dateTimeProperty.getSeconds() == 59 + && dateTimeProperty.getMilliseconds() == 999) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-minutes.qml b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-minutes.qml new file mode 100644 index 0000000000..738d603b4b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-minutes.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateTimeProperty = new Date(2020, 1, 28, 0, 1440) // 2020-2-29 0:0:0 + boolProperty = (dateTimeProperty.getFullYear() == 2020 + && dateTimeProperty.getMonth() == 1 + && dateTimeProperty.getDate() == 29 + && dateTimeProperty.getHours() == 0 + && dateTimeProperty.getMinutes() == 0 + && dateTimeProperty.getSeconds() == 0 + && dateTimeProperty.getMilliseconds() == 0) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-seconds.qml b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-seconds.qml new file mode 100644 index 0000000000..d48534f0d0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/checkDateTime-denormal-seconds.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + dateTimeProperty = new Date(2020, 1, 28, 23, 0, 3600) // 2020-2-29 0:0:0 + boolProperty = (dateTimeProperty.getFullYear() == 2020 + && dateTimeProperty.getMonth() == 1 + && dateTimeProperty.getDate() == 29 + && dateTimeProperty.getHours() == 0 + && dateTimeProperty.getMinutes() == 0 + && dateTimeProperty.getSeconds() == 0 + && dateTimeProperty.getMilliseconds() == 0) + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index df4963cb6e..7a9c611269 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -78,6 +78,10 @@ private slots: void assignDate(); void exportDate_data(); void exportDate(); + void checkDate_data(); + void checkDate(); + void checkDateTime_data(); + void checkDateTime(); void idShortcutInvalidates(); void boolPropertiesEvaluateAsBool(); void methods(); @@ -565,6 +569,82 @@ void tst_qqmlecmascript::exportDate() QCOMPARE(object->boolProperty(), true); } +void tst_qqmlecmascript::checkDate_data() +{ + QTest::addColumn("source"); + QTest::addColumn("date"); + // NB: JavaScript month-indices are Jan = 0 to Dec = 11; QDate's are Jan = 1 to Dec = 12. + QTest::newRow("denormal-March") + << testFileUrl("checkDate-denormal-March.qml") + << QDate(2019, 3, 1); + QTest::newRow("denormal-leap") + << testFileUrl("checkDate-denormal-leap.qml") + << QDate(2020, 2, 29); + QTest::newRow("denormal-Feb") + << testFileUrl("checkDate-denormal-Feb.qml") + << QDate(2019, 2, 28); + QTest::newRow("denormal-year") + << testFileUrl("checkDate-denormal-year.qml") + << QDate(2019, 12, 31); + QTest::newRow("denormal-wrap") + << testFileUrl("checkDate-denormal-wrap.qml") + << QDate(2020, 2, 29); + QTest::newRow("October") + << testFileUrl("checkDate-October.qml") + << QDate(2019, 10, 3); +} + +void tst_qqmlecmascript::checkDate() +{ + QFETCH(const QUrl, source); + QFETCH(const QDate, date); + QQmlEngine e; + QQmlComponent component(&e, source); + QScopedPointer obj(component.create()); + MyTypeObject *object = qobject_cast(obj.data()); + QVERIFY(object != nullptr); + QCOMPARE(object->dateProperty(), date); + QVERIFY(object->boolProperty()); +} + +void tst_qqmlecmascript::checkDateTime_data() +{ + QTest::addColumn("source"); + QTest::addColumn("when"); + // NB: JavaScript month-indices are Jan = 0 to Dec = 11; QDate's are Jan = 1 to Dec = 12. + QTest::newRow("denormal-March") + << testFileUrl("checkDateTime-denormal-March.qml") + << QDateTime(QDate(2019, 3, 1), QTime(0, 0, 0, 1), Qt::LocalTime); + QTest::newRow("denormal-leap") + << testFileUrl("checkDateTime-denormal-leap.qml") + << QDateTime(QDate(2020, 2, 29), QTime(23, 59, 59, 999), Qt::LocalTime); + QTest::newRow("denormal-hours") + << testFileUrl("checkDateTime-denormal-hours.qml") + << QDateTime(QDate(2020, 2, 29), QTime(0, 0), Qt::LocalTime); + QTest::newRow("denormal-minutes") + << testFileUrl("checkDateTime-denormal-minutes.qml") + << QDateTime(QDate(2020, 2, 29), QTime(0, 0), Qt::LocalTime); + QTest::newRow("denormal-seconds") + << testFileUrl("checkDateTime-denormal-seconds.qml") + << QDateTime(QDate(2020, 2, 29), QTime(0, 0), Qt::LocalTime); + QTest::newRow("October") + << testFileUrl("checkDateTime-October.qml") + << QDateTime(QDate(2019, 10, 3), QTime(12, 0), Qt::LocalTime); +} + +void tst_qqmlecmascript::checkDateTime() +{ + QFETCH(const QUrl, source); + QFETCH(const QDateTime, when); + QQmlEngine e; + QQmlComponent component(&e, source); + QScopedPointer obj(component.create()); + MyTypeObject *object = qobject_cast(obj.data()); + QVERIFY(object != nullptr); + QCOMPARE(object->dateTimeProperty(), when); + QVERIFY(object->boolProperty()); +} + void tst_qqmlecmascript::idShortcutInvalidates() { QQmlEngine engine; -- cgit v1.2.3 From 26e99aeacdb2527e6b439d8244a774cd719d732a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 5 Sep 2019 13:57:19 +0200 Subject: PathView: grab mouse on press if already moving A side effect of 8fd398c9d2f5f54e446e0b402bc63a2edb50da6f is that it became possible for the highlight to stop between items, rather than snapping to a specific item, if the user taps, clicks or drags an additional time while the movement is ongoing. That was because it didn't get a mouse grab, so it missed the release event. QQuickPathViewPrivate::handleMouseReleaseEvent() needs to take care of the snapping behavior after the user stops dragging. This only affects behavior in the case that the PathView is already moving and the mouse is pressed again: we assume the user wants to alter the PathView's velocity, not interact with any delegate inside or with any parent item. Task-number: QTBUG-77173 Task-number: QTBUG-59620 Change-Id: I7b2f69a6ef8d8022d7c917a5bf9e8fb40c8848db Reviewed-by: Mitch Curtis (cherry picked from commit e2df4233a77ce8a37d2c8ef26b7b42fc0d33a24b) --- tests/auto/qml/ecmascripttests/test262 | 2 +- .../quick/qquickpathview/data/nestedmousearea2.qml | 101 +++++++++++++++++++++ .../quick/qquickpathview/tst_qquickpathview.cpp | 27 ++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 tests/auto/quick/qquickpathview/data/nestedmousearea2.qml (limited to 'tests') diff --git a/tests/auto/qml/ecmascripttests/test262 b/tests/auto/qml/ecmascripttests/test262 index 3c69133cc4..6b0c42c63c 160000 --- a/tests/auto/qml/ecmascripttests/test262 +++ b/tests/auto/qml/ecmascripttests/test262 @@ -1 +1 @@ -Subproject commit 3c69133cc419840c1be34638039cd8c48a7ef581 +Subproject commit 6b0c42c63c2492bd0a7a96d3179d122b5f71793f diff --git a/tests/auto/quick/qquickpathview/data/nestedmousearea2.qml b/tests/auto/quick/qquickpathview/data/nestedmousearea2.qml new file mode 100644 index 0000000000..ff11002552 --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/nestedmousearea2.qml @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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 2.0 + +PathView { + id: view + width: 400; height: 240 + highlight: Rectangle { width: 80; height: 80; color: "lightsteelblue" } + preferredHighlightBegin: 0.5 + preferredHighlightEnd: 0.5 + model: ListModel { + id: appModel + ListElement { name: "Music" } + ListElement { name: "Movies" } + ListElement { name: "Camera" } + ListElement { name: "Calendar" } + ListElement { name: "Messaging" } + ListElement { name: "Todo List" } + ListElement { name: "Contacts" } + } + delegate: Rectangle { + width: 100; height: 100 + scale: PathView.iconScale + border.color: "lightgrey" + color: "transparent" + Text { + anchors { horizontalCenter: parent.horizontalCenter } + text: name + smooth: true + color: ma.pressed ? "red" : "black" + } + + MouseArea { + id: ma + anchors.fill: parent + onClicked: view.currentIndex = index + } + } + path: Path { + startX: 10 + startY: 50 + PathAttribute { name: "iconScale"; value: 0.5 } + PathQuad { x: 200; y: 150; controlX: 50; controlY: 200 } + PathAttribute { name: "iconScale"; value: 1.0 } + PathQuad { x: 390; y: 50; controlX: 350; controlY: 200 } + PathAttribute { name: "iconScale"; value: 0.5 } + } + Text { + anchors.horizontalCenter: parent.horizontalCenter + y: 20 + text: view.currentIndex + " @ " + offset.toFixed(2) + } +} diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index e3dc0434b1..ed02a4ef48 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -120,6 +120,7 @@ private slots: void undefinedPath(); void mouseDrag(); void nestedMouseAreaDrag(); + void flickNClick(); void treeModel(); void changePreferredHighlight(); void missingPercent(); @@ -1601,6 +1602,32 @@ void tst_QQuickPathView::nestedMouseAreaDrag() QVERIFY(pathview->isMoving()); } +void tst_QQuickPathView::flickNClick() // QTBUG-77173 +{ + QScopedPointer window(createView()); + QQuickViewTestUtil::moveMouseAway(window.data()); + window->setSource(testFileUrl("nestedmousearea2.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QCOMPARE(window.data(), qGuiApp->focusWindow()); + + QQuickPathView *pathview = qobject_cast(window->rootObject()); + QVERIFY(pathview != nullptr); + + for (int duration = 100; duration > 0; duration -= 20) { + // Dragging the child mouse area should animate the PathView (MA has no drag target) + flick(window.data(), QPoint(200,200), QPoint(400,200), duration); + QVERIFY(pathview->isMoving()); + + // Now while it's still moving, click it. + // The PathView should stop at a position such that offset is a whole number. + QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); + QTRY_VERIFY(!pathview->isMoving()); + QVERIFY(qFuzzyIsNull(pathview->offset() - int(pathview->offset()))); + } +} + void tst_QQuickPathView::treeModel() { QScopedPointer window(createView()); -- cgit v1.2.3 From 44c51303b6968a4c8c5cf80fa92618852d017fd0 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 9 Oct 2019 08:25:17 +0200 Subject: Add signal spies to tst_QQuickPathView::flickNClick test QTBUG-78926 is about failing to emit the movingChanged signal. The test verifies that e2df4233a77ce8a37d2c8ef26b7b42fc0d33a24b fixed it. While we're at it, might as well verify a few more signals in this test scenario where we flick the PathView at various speeds and then stop the flick by clicking. Fixes: QTBUG-78926 Change-Id: I1253dfcd88a63abdbdd280dd9097b484a93cc491 Reviewed-by: Mitch Curtis --- .../quick/qquickpathview/tst_qquickpathview.cpp | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests') diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index ed02a4ef48..e2d3253e44 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -1614,16 +1614,55 @@ void tst_QQuickPathView::flickNClick() // QTBUG-77173 QQuickPathView *pathview = qobject_cast(window->rootObject()); QVERIFY(pathview != nullptr); + QSignalSpy movingChangedSpy(pathview, SIGNAL(movingChanged())); + QSignalSpy draggingSpy(pathview, SIGNAL(draggingChanged())); + QSignalSpy dragStartedSpy(pathview, SIGNAL(dragStarted())); + QSignalSpy dragEndedSpy(pathview, SIGNAL(dragEnded())); + QSignalSpy currentIndexSpy(pathview, SIGNAL(currentIndexChanged())); + QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted())); + QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded())); + QSignalSpy flickingSpy(pathview, SIGNAL(flickingChanged())); + QSignalSpy flickStartedSpy(pathview, SIGNAL(flickStarted())); + QSignalSpy flickEndedSpy(pathview, SIGNAL(flickEnded())); for (int duration = 100; duration > 0; duration -= 20) { + movingChangedSpy.clear(); + draggingSpy.clear(); + dragStartedSpy.clear(); + dragEndedSpy.clear(); + currentIndexSpy.clear(); + moveStartedSpy.clear(); + moveEndedSpy.clear(); + flickingSpy.clear(); + flickStartedSpy.clear(); + flickEndedSpy.clear(); // Dragging the child mouse area should animate the PathView (MA has no drag target) flick(window.data(), QPoint(200,200), QPoint(400,200), duration); QVERIFY(pathview->isMoving()); + QCOMPARE(movingChangedSpy.count(), 1); + QCOMPARE(draggingSpy.count(), 2); + QCOMPARE(dragStartedSpy.count(), 1); + QCOMPARE(dragEndedSpy.count(), 1); + QVERIFY(currentIndexSpy.count() > 0); + QCOMPARE(moveStartedSpy.count(), 1); + QCOMPARE(moveEndedSpy.count(), 0); + QCOMPARE(flickingSpy.count(), 1); + QCOMPARE(flickStartedSpy.count(), 1); + QCOMPARE(flickEndedSpy.count(), 0); // Now while it's still moving, click it. // The PathView should stop at a position such that offset is a whole number. QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); QTRY_VERIFY(!pathview->isMoving()); + QCOMPARE(movingChangedSpy.count(), 2); // QTBUG-78926 + QCOMPARE(draggingSpy.count(), 2); + QCOMPARE(dragStartedSpy.count(), 1); + QCOMPARE(dragEndedSpy.count(), 1); + QCOMPARE(moveStartedSpy.count(), 1); + QCOMPARE(moveEndedSpy.count(), 1); + QCOMPARE(flickingSpy.count(), 2); + QCOMPARE(flickStartedSpy.count(), 1); + QCOMPARE(flickEndedSpy.count(), 1); QVERIFY(qFuzzyIsNull(pathview->offset() - int(pathview->offset()))); } } -- cgit v1.2.3 From cb9bfcd5c0a8bf541d3b67a80ca22ed11662b422 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 9 Oct 2019 17:54:09 +0200 Subject: Fix signed/unsigned comparison warnings This is a follow-up to commit 59410dd2f587945441791e76a5ac07acbe15989f Change-Id: Ie5257791662c6f2fef32cc667849598cf428e825 Reviewed-by: Ulf Hermann --- .../qv4identifiertable/tst_qv4identifiertable.cpp | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp b/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp index 308fba9049..157d0f2a62 100644 --- a/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp +++ b/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2016 basysKom GmbH. ** Contact: https://www.qt.io/licensing/ ** @@ -110,8 +111,8 @@ void tst_qv4identifiertable::sweepCenterEntryInBucket() table.asPropertyKey(entry2); table.asPropertyKey(entry3); - QCOMPARE(table.size, 3); - QCOMPARE(table.alloc, 5); + QCOMPARE(table.size, 3u); + QCOMPARE(table.alloc, 5u); QCOMPARE(table.entriesByHash[0], entry1); QCOMPARE(table.entriesByHash[1], entry2); @@ -153,8 +154,8 @@ void tst_qv4identifiertable::sweepLastEntryInBucket() table.asPropertyKey(entry2); table.asPropertyKey(entry3); - QCOMPARE(table.size, 3); - QCOMPARE(table.alloc, 5); + QCOMPARE(table.size, 3u); + QCOMPARE(table.alloc, 5u); QCOMPARE(table.entriesByHash[0], entry1); QCOMPARE(table.entriesByHash[1], entry2); @@ -193,8 +194,8 @@ void tst_qv4identifiertable::sweepFirstEntryInSameBucketWithDifferingHash() table.asPropertyKey(entry1); table.asPropertyKey(entry2); - QCOMPARE(table.size, 2); - QCOMPARE(table.alloc, 5); + QCOMPARE(table.size, 2u); + QCOMPARE(table.alloc, 5u); QCOMPARE(table.entriesByHash[0], entry1); QCOMPARE(table.entriesByHash[1], entry2); @@ -231,8 +232,8 @@ void tst_qv4identifiertable::dontSweepAcrossBucketBoundaries() table.asPropertyKey(entry1); table.asPropertyKey(entry2); - QCOMPARE(table.size, 2); - QCOMPARE(table.alloc, 5); + QCOMPARE(table.size, 2u); + QCOMPARE(table.alloc, 5u); QCOMPARE(table.entriesByHash[0], entry1); QCOMPARE(table.entriesByHash[1], entry2); @@ -279,8 +280,8 @@ void tst_qv4identifiertable::sweepAcrossBucketBoundariesIfFirstBucketFull() table.asPropertyKey(entry3); table.asPropertyKey(entry4); - QCOMPARE(table.size, 4); - QCOMPARE(table.alloc, 11); + QCOMPARE(table.size, 4u); + QCOMPARE(table.alloc, 11u); QCOMPARE(table.entriesByHash[0], entry1); QCOMPARE(table.entriesByHash[1], entry2); @@ -336,8 +337,8 @@ void tst_qv4identifiertable::sweepBucketGap() table.asPropertyKey(entry3); table.asPropertyKey(entry4); - QCOMPARE(table.size, 4); - QCOMPARE(table.alloc, 11); + QCOMPARE(table.size, 4u); + QCOMPARE(table.alloc, 11u); QCOMPARE(table.entriesByHash[0], entry1); QCOMPARE(table.entriesByHash[1], entry2); -- cgit v1.2.3 From 6fceeab1d15e1d6c1fa3d8e067f2acdeccb78e64 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 10 Oct 2019 11:37:59 +0200 Subject: QML ListModel: Emit a warning when adding an object with undefined or null member The current code in ListModel simply did a reset of an existing property, in case a role existed and was set to null/undefined. If the role did not exist, the code would simply skip over the member and do nothing. However, this does not make any sense for newly inserted items, and most likely indicates a misunderstanding of how ListModel works. Creating an undefined/null role does not really make sense, as those could only ever store a undefined/null value. Change-Id: I4c1361647a82146565eaffe064598c94c748b4f5 Task-number: QTBUG-63569 Reviewed-by: Mitch Curtis Reviewed-by: Ulf Hermann --- tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index b47062ee94..75a932b6f4 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -129,6 +129,7 @@ private slots: void crash_append_empty_array(); void dynamic_roles_crash_QTBUG_38907(); void nestedListModelIteration(); + void undefinedAppendShouldCauseError(); }; bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object) @@ -1694,6 +1695,35 @@ void tst_qqmllistmodel::nestedListModelIteration() QScopedPointer(component.create()); } +// QTBUG-63569 +void tst_qqmllistmodel::undefinedAppendShouldCauseError() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData( + R"(import QtQuick 2.5 + Item { + width: 640 + height: 480 + ListModel { + id : model + } + Component.onCompleted: { + var tempData = { + faulty: undefined + } + model.insert(0, tempData) + tempData.faulty = null + model.insert(0, tempData) + } + })", + QUrl()); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, ": faulty is undefined. Adding an object with a undefined member does not create a role for it."); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, ": faulty is null. Adding an object with a null member does not create a role for it."); + QScopedPointer(component.create()); +} + + QTEST_MAIN(tst_qqmllistmodel) #include "tst_qqmllistmodel.moc" -- cgit v1.2.3