From 315fabdb574d9952a072ec7122266f59011c0257 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 26 Aug 2019 15:01:11 +0300 Subject: Minor typo fix Change-Id: I335e59f09c48a8b52c7f690cedba95952c5adfa3 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickoverlay_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quicktemplates2/qquickoverlay_p.h b/src/quicktemplates2/qquickoverlay_p.h index 0d8bccf5..1d238163 100644 --- a/src/quicktemplates2/qquickoverlay_p.h +++ b/src/quicktemplates2/qquickoverlay_p.h @@ -86,7 +86,7 @@ Q_SIGNALS: protected: void itemChange(ItemChange change, const ItemChangeData &data) override; - void geometryChanged(const QRectF &oldGeometry, const QRectF &newGeometry) override; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; -- cgit v1.2.3 From 7ce1bdfe79d5c9aeb7202fb38b4174028ea2bf9c Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 26 Aug 2019 18:14:27 +0300 Subject: QQuickPopup: fix compiler warning > warning: unannotated fall-through between switch labels > note: insert 'break;' to avoid fall-through Change-Id: Ia70fb6b666f874a245a113d61a6cb3e8e7aa2712 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickpopup.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index dd7dede6..f0cf1869 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -2582,6 +2582,7 @@ void QQuickPopup::itemChange(QQuickItem::ItemChange change, const QQuickItem::It else d->popupItem->ungrabShortcut(); } + break; default: break; } -- cgit v1.2.3 From 7c1b29575db0f1e892d68fb2bd0cf894f18fafd5 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 26 Aug 2019 21:06:14 +0300 Subject: Modernize Gallery example by using Action where suitable Change-Id: I45c693941e88074eb63f9e6a498c85c1dfa93e9a Reviewed-by: Mitch Curtis --- examples/quickcontrols2/gallery/gallery.qml | 41 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/examples/quickcontrols2/gallery/gallery.qml b/examples/quickcontrols2/gallery/gallery.qml index e9f0b432..44987ada 100644 --- a/examples/quickcontrols2/gallery/gallery.qml +++ b/examples/quickcontrols2/gallery/gallery.qml @@ -70,15 +70,31 @@ ApplicationWindow { Shortcut { sequences: ["Esc", "Back"] enabled: stackView.depth > 1 - onActivated: { - stackView.pop() - listView.currentIndex = -1 + onActivated: navigateBackAction.trigger() + } + + Action { + id: navigateBackAction + icon.name: stackView.depth > 1 ? "back" : "drawer" + onTriggered: { + if (stackView.depth > 1) { + stackView.pop() + listView.currentIndex = -1 + } else { + drawer.open() + } } } Shortcut { sequence: "Menu" - onActivated: optionsMenu.open() + onActivated: optionsMenuAction.trigger() + } + + Action { + id: optionsMenuAction + icon.name: "menu" + onTriggered: optionsMenu.open() } header: ToolBar { @@ -89,15 +105,7 @@ ApplicationWindow { anchors.fill: parent ToolButton { - icon.name: stackView.depth > 1 ? "back" : "drawer" - onClicked: { - if (stackView.depth > 1) { - stackView.pop() - listView.currentIndex = -1 - } else { - drawer.open() - } - } + action: navigateBackAction } Label { @@ -111,19 +119,18 @@ ApplicationWindow { } ToolButton { - icon.name: "menu" - onClicked: optionsMenu.open() + action: optionsMenuAction Menu { id: optionsMenu x: parent.width - width transformOrigin: Menu.TopRight - MenuItem { + Action { text: "Settings" onTriggered: settingsDialog.open() } - MenuItem { + Action { text: "About" onTriggered: aboutDialog.open() } -- cgit v1.2.3 From 1e99cb6e809ff0c8647c5017c11ead68ae1a591d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 3 Sep 2019 13:20:29 +0200 Subject: Fix flakiness in tst_qquickdrawer tests Although it's not ideal to add arbitrary delays to tests, it does reflect a more realistic testing environment, and more importantly, seems to fix the flakiness on OpenSUSE. (cherry picked from commit 97fc102cd079f32cc1a4f00a764ceea981699fc0) Fixes: QTBUG-77946 Change-Id: I2998611759106386091d7375b31e56523c95371f Reviewed-by: Mitch Curtis Reviewed-by: Liang Qi --- tests/auto/qquickdrawer/tst_qquickdrawer.cpp | 6 ++++-- tests/auto/qquickpopup/tst_qquickpopup.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp index 816f9b67..4cf0dabe 100644 --- a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp +++ b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp @@ -350,7 +350,8 @@ void tst_QQuickDrawer::position() QVERIFY(drawer); drawer->setEdge(edge); - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, press); + // Give it some time (50 ms) before the press to avoid flakiness on OpenSUSE: QTBUG-77946 + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, press, 50); QTest::mouseMove(window, from); QTest::mouseMove(window, to); QCOMPARE(drawer->position(), position); @@ -403,7 +404,8 @@ void tst_QQuickDrawer::dragMargin() int leftX = qMax(0, dragMargin); int leftDistance = startDragDistance + drawer->width() * 0.45; QVERIFY(leftDistance > QGuiApplication::styleHints()->startDragDistance()); - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(leftX, drawer->height() / 2)); + // Give it some time (50 ms) before the press to avoid flakiness on OpenSUSE: QTBUG-77946 + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(leftX, drawer->height() / 2), 50); QTest::mouseMove(window, QPoint(leftX + startDragDistance, drawer->height() / 2)); QTest::mouseMove(window, QPoint(leftX + leftDistance, drawer->height() / 2)); QCOMPARE(drawer->position(), dragFromLeft); diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp index 81b2d583..4046bd3d 100644 --- a/tests/auto/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp @@ -493,7 +493,7 @@ void tst_QQuickPopup::closePolicy() QTRY_VERIFY(popup->isOpened()); // press outside popup and its parent - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1), 50); if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) || closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent)) QTRY_VERIFY(!popup->isVisible()); else -- cgit v1.2.3 From 616c430d2b7f36e70987df7b2dc97e71f0e8b589 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 2 May 2019 16:50:31 +0200 Subject: ComboBox: document the behavior surrounding the accepted() signal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I65be8e54ded284d2f80b5a1f301b75223bd81bb3 Fixes: QTBUG-75338 Reviewed-by: Henning Gründl Reviewed-by: Mitch Curtis Reviewed-by: Paul Wicking --- .../qtquickcontrols2-combobox-accepted.qml | 45 ++++++++++++++++++++++ src/quicktemplates2/qquickcombobox.cpp | 35 ++++++++--------- 2 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 src/imports/controls/doc/snippets/qtquickcontrols2-combobox-accepted.qml diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-combobox-accepted.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-combobox-accepted.qml new file mode 100644 index 00000000..9f2ad928 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-combobox-accepted.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +//! [combobox] +ComboBox { + editable: true + model: ListModel { + id: model + ListElement { text: "Banana" } + ListElement { text: "Apple" } + ListElement { text: "Coconut" } + } + onAccepted: { + if (find(editText) === -1) + model.append({text: editText}) + } +} +//! [combobox] diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index 78ec7ef8..372b7905 100644 --- a/src/quicktemplates2/qquickcombobox.cpp +++ b/src/quicktemplates2/qquickcombobox.cpp @@ -90,21 +90,7 @@ QT_BEGIN_NAMESPACE The following example demonstrates appending content to an editable combo box by reacting to the \l accepted signal. - \code - ComboBox { - editable: true - model: ListModel { - id: model - ListElement { text: "Banana" } - ListElement { text: "Apple" } - ListElement { text: "Coconut" } - } - onAccepted: { - if (find(editText) === -1) - model.append({text: editText}) - } - } - \endcode + \snippet qtquickcontrols2-combobox-accepted.qml combobox \section1 ComboBox Model Roles @@ -167,9 +153,22 @@ QT_BEGIN_NAMESPACE \qmlsignal void QtQuick.Controls::ComboBox::accepted() This signal is emitted when the \uicontrol Return or \uicontrol Enter key is pressed - on an \l editable combo box. If the confirmed string is not currently in the model, - the \l currentIndex will be set to \c -1 and the \l currentText will be updated - accordingly. + on an \l editable combo box. + + You can handle this signal in order to add the newly entered + item to the model, for example: + + \snippet qtquickcontrols2-combobox-accepted.qml combobox + + Before the signal is emitted, a check is done to see if the string + exists in the model. If it does, \l currentIndex will be set to its index, + and \l currentText to the string itself. + + After the signal has been emitted, and if the first check failed (that is, + the item did not exist), another check will be done to see if the item was + added by the signal handler. If it was, the \l currentIndex and + \l currentText are updated accordingly. Otherwise, they will be set to + \c -1 and \c "", respectively. \note If there is a \l validator set on the combo box, the signal will only be emitted if the input is in an acceptable state. -- cgit v1.2.3