aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qquickmenu/tst_qquickmenu.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Restructure tests in preparation for merging into qtdeclarativeMitch Curtis2021-07-221-1912/+0
| | | | | | | Task-number: QTBUG-95173 Change-Id: I541dc26cf2cdd6f2640824f693f7d059445367d9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Be sure to click outside the menu in tst_QQuickMenu::mouse()Shawn Rutledge2021-07-071-1/+2
| | | | | | | | It seems that with Fusion style, the menu is somehow larger. Pick-to: 6.2 Change-Id: I2270d5db3cdb89da36f31d5b49225c16e34f114f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix layout is always RTL when locale is RTLHyunkook Khang2021-05-261-12/+30
| | | | | | | | | | | | | | | | isMirrored() will always return true when locale is RTL, so that we cannot change the layout. To fix this, remove out the relation between LayoutMirroring.enabled and locale's text direction. [ChangeLog][Controls][Important Behavior Changes] Control's locale property no longer affects layout direction. Use LayoutMirroring instead. Fixes: QTBUG-91227 Change-Id: Ibedd3f09828f81f1889077892452a27c90e21533 Reviewed-by: Hyunkook Khang <hyunkook.khang@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* QQuickAbstractButton: don't accept key release if we're not pressedMitch Curtis2020-10-211-0/+27
| | | | | | | | | | | | | A control should have been pressed if it's going to accept a release. This prevents an issue where a menu opened by pressing enter (handled via attached Keys property) would instantly trigger the first menu item. Pick-to: 5.15 5.12 Fixes: QTBUG-83698 Change-Id: I6b1afbb76f37623012472b2b1148b4862c159239 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* tst_qquickmenu: fix flaky testRichard Moe Gustavsen2020-09-041-1/+1
| | | | | | | | | The included test fails every now and then for Imagine, Fusion and Mac style. By using QTRY_VERIFY to wait a bit before we check if the menu is highlighted, it seems to pass each time. Change-Id: Ib8b207e1b5f81b3086595bb8ad7dc6881272def1 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Menu: Close menu by Alt key on platforms supporting mnemonic shortcutsYuya Nishihara2020-09-021-4/+10
| | | | | | | | | | | | | | | | | | | | | | | This is close to what the widget QMenu (and Windows native menu) do. Before, the active menu was left open and Alt+<key> shortcut would be delivered to one of the matching items, which might be an item shadowed by the active menu popup. With this patch, the active menu is closed on Alt key pressed so the subsequent shortcut event will (likely) be delivered to the matching MenuBar item. Since I'm going to fix the issue of &mnemonic key conflict resolution, I need to first change the way of delivering a shortcut event to the parent MenuBar. The test cases use the undocumented function to simulate low-level behavior of Alt itself and Alt+<key> events. Apparently, there's no public QTest function to send multiple key events without releasing Alt modifier. Task-number: QTBUG-86276 Pick-to: 5.15 Change-Id: I0ed6ea94f0fee7983a5cb6352d388036d3a1f8df Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Fix tst_QQuickMenu::subMenuPosition()Mitch Curtis2020-07-141-10/+19
| | | | | | | | | | | | | | | | | | | | | | | | We're still getting failures after QCOMPARE was fixed (in c78a960198d59fb9a9ddd83ad7098b1db396edfd): FAIL! : tst_QQuickMenu::Material::subMenuPosition(cascading,flip) Compared doubles are not the same (fuzzy compare) Actual (subSubMenu1->popupItem()->x()) : 3.88240550819e-11 Expected (subMenu1->popupItem()->x() - subSubMenu1->width() + overlap): 0 tst_qquickmenu.cpp(1532) : failure location Quoting Eddy: "[...] the threshold for double equality is one part in 1e12; the threshold for fuzzy-is-zero is likewise 1e-12; so 3e-11 is non-zero. One work-around, of course, would be to cast float(each operand) so as to get float's wider tolerance (one part in 100,000, null if less than 1e-5)." So that's what we do in this patch. Change-Id: Iecf1b6f4b2cf2c81eb652bb0f565ac682b024dae Pick-to: 5.15 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QQuickApplicationHelper: don't use QTest macros outside test functionsMitch Curtis2020-06-171-0/+27
| | | | | | | | | This has no effect. Task-number: QTBUG-66320 Pick-to: 5.15 5.12 Change-Id: Ie6efb26243178c4044ac0bc721c21ad89769c982 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* ApplicationWindow: remove deprecated overlay APIMitch Curtis2020-06-081-10/+15
| | | | | | | | | | [ChangeLog][Controls][ApplicationWindow] The deprecated overlay properties and attached API were removed. Use the Overlay attached type instead. Task-number: QTBUG-84715 Change-Id: I0781ea55ea502ffe5277385e82492291724d2090 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Menu: remove deprecated removeItem(var) overloadMitch Curtis2020-05-111-6/+0
| | | | | | | | | [ChangeLog][Controls][Menu] The deprecated removeItem(var) function was removed. removeItem(Item) or takeItem(int) can be used instead. Change-Id: I79757c22b4f81e1b380798623bd1f15eb09c1647 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Revert "tst_qquickmenu: fix flakiness resulting from floating point comparison"Mitch Curtis2020-05-071-11/+10
| | | | | | | | | | | This reverts commit c463f09fcb63927c66bc3307ddcc88d85d38b2bc. After c78a960198d59fb9a9ddd83ad7098b1db396edfd in qtbase, this shouldn't be necessary. Pick-to: 5.15 Change-Id: I1789eae295b1ebc44630b758414087344909ea60 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* tst_qquickmenu: fix flakiness resulting from floating point comparisonMitch Curtis2020-04-151-10/+11
| | | | | | | | | | | | From the docs of QCOMPARE: "[...] expecting 0 can fail when the actual value may be affected by rounding errors. One solution to this is to offset both actual and expected values by adding some suitable constant (such as 1)." Pick-to: 5.15 Change-Id: Ie7c0db9b4eb6c7d9fdb503421242d309a39bc2ec Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Account for the padding around a menu when checking if it is interactiveAndy Shaw2020-03-181-0/+1
| | | | | | | | | | If there is padding around the menu then it will mean the available height is smaller than the containing item and as such should be interactive. Fixes: QTBUG-82473 Change-Id: Ie3e7568ab66aa3da93e5448c1a27c9bd2a5e486a Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Fix Flaky testsDimitrios Apostolou2019-07-221-20/+20
| | | | | | | | | | | | These tests where failing sometimes in our CI, because centerOnScreen() was invoked which asks the window manager to move the window, but does not wait for the event's completion. The solution is to do all that *before* the initial qWaitForWindowActive(). Fixes: QTBUG-73128 Change-Id: I06c1f85d5ff9657dccab50f29084f7624cd7e194 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Fix flaky tst_qquickmenu testMitch Curtis2019-05-071-2/+3
| | | | | | | | | | The important part of the "cascading" test is checking that the sub-sub menu eventually opens, so move the !visible check to the non-cascading branch of the if statement. Change-Id: I5a09bf0b5d45832f7b75c3e8c397fdb9e6fcc011 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
* Fix MenuItem width not matching Menu's available widthMitch Curtis2019-05-031-0/+150
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Short version: There are currently two problems with MenuItems: - Mirrored MenuItems don't fill the Menu's available width. - MenuItem does not fill the Menu's available width when changed after Component completion. This patch fixes both of them by listening to geometry changes in both the contentItem and individual menu items, and setting the explicit width of those menu items when either changes. Longer version: The first problem can be seen whenever the MenuItem's implicitWidth changes: - QQmlEngine::retranslate() is called, causing all bindings to be re-evaluated - The MenuItem's font size changes - The MenuItem's icon size changes - etc. We fix this by making Menu listen to the width of each of its MenuItems and call resizeItem() if it doesn't have an explicit width. The second problem can be seen when e.g. resizing a Menu to account for new items that are wider and hence require more space. This can be fixed by listening to width changes in Menu's contentItem, which was actually done in earlier versions but (probably accidentally) removed in 482ecb0f. I had tried to solve both issues by setting the explicit width of MenuItem to the width of its Menu, or undefined if it has none (which means it reverts to its implicit width). However, this does not account for e.g. MenuSeparator and custom items that can be added to Menu - they should also have their width fill the Menu automatically if they don't have an explicit width set. Change-Id: I95dd0da0919a1e297f2e2030da746ff1f1a17644 Fixes: QTBUG-75051 Fixes: QTBUG-75142 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Make tst_qquickmenu run with all stylesMitch Curtis2019-05-031-82/+128
| | | | | | | | | This is a prerequisite for ensuring that an Imagine-style-specific fix works. Fixes: QTBUG-75141 Change-Id: Iafef3bf947151cb35b88a1230e3541d8e4e15fd9 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QQuickMenu: allow enter/return to be used to activate itemsMitch Curtis2019-02-281-1/+30
| | | | | | | | | | | Before this patch, only space was allowed. Windows 10 and macOS 10.14.2 both allow using enter to activate menu items. Change-Id: I64476347669ff73f233efd129563a18ba51618a5 Fixes: QTBUG-73354 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QQuickMenu: don't give focus to disabled menu itemsMitch Curtis2019-02-041-0/+64
| | | | | | Change-Id: I7eb394ca3991eae585fbbd8e665c46b11ef64a07 Fixes: QTBUG-70181 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
* Menu: fix disabled sub-menu items being highlightedMitch Curtis2019-02-041-0/+123
| | | | | | | | | | | When a menu item with a sub-menu was triggered by key or mouse, it would open the sub-menu with the first menu item highlighted. This doesn't make sense for disabled menu items, so this patch makes it find the first enabled item. Change-Id: I9df1c750749e5a77b027b6f476b8ae1f5ea035bd Fixes: QTBUG-69540 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Fix Menu not being dismissed when the triggered item disables itselfMitch Curtis2019-02-041-0/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem Consider the following code: Menu { title: "Menu" Action { text: "Item" onTriggered: enabled = false } } A MenuItem (AbstractButton) is created for the Action, and when it is clicked, this function is called: void QQuickAbstractButtonPrivate::trigger() { Q_Q(QQuickAbstractButton); if (action && action->isEnabled()) QQuickActionPrivate::get(action)->trigger(q, false); else if (effectiveEnable) emit q->clicked(); } QQuickActionPrivate::get(action)->trigger(q, false) results in this function being called: void QQuickAbstractButtonPrivate::click() { Q_Q(QQuickAbstractButton); if (effectiveEnable) emit q->clicked(); } Since the action (and hence the menu item) was disabled in the signal handler, the effectiveEnable check fails and clicked() is not emitted. This causes the menu to not be dismissed. Solution Before calling QQuickActionPrivate::get(action)->trigger(), store the button's enabled state. If triggering the action causes the action to be disabled (due to the signal handler), we can then choose whether or not we emit QQuickAbstractButton::clicked(). Specifically, we emit clicked() if: - we were enabled before triggering the action, and - we have no associated action, or it's no longer enabled Task-number: QTBUG-69682 Change-Id: Ib4e3c313b776decc74089a6beffe415605c430be Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Revert all Menu delegate patchesv5.12.0-rc2v5.12.0-rc1v5.12.0Mitch Curtis2018-11-151-200/+1
| | | | | | | | | | | | | | | | | | | | | This reverts the following commits: d5cb26bc56a3b6f6e99c88654d4f7a65f43551ac - Menu: ensure the correct delegates are used when created via Component d923dd467c1aeb3e195a09949b04862084002f88 - MenuBar: ensure the correct delegates are used when created via Component d56c193eb4ceb640611d66f22e1f26aae91cd7d1 - QQuickPopupPositioner: avoid adding duplicate item change listeners 567a2de8cd493aabe0055d6dbc367b39447e70dd - Stabilize tst_qquickmenubar 953fbac6131823e4fce0eb4707a854469c4c04ff - Fix Instantiator-created MenuItems disappearing 936d31179d44220571ded15840bedeccb581c83b - tst_qquickmenu: add a test for MenuItems before and after a Repeater fc1832810f6c09505d9413685ed0b2d6295bea4a - QQuickMenuBar: fix menu not opening The fix for QTBUG-67559 has caused lots of issues, with the latest being a crash right before the 5.12 release. The bug that they fix is a P2, so it's not worth the hassle. The patches might be able to be resubmitted to dev after the crash is fixed. Change-Id: Ic192c7a302176bcdb2503b636b3462b10898a2ba Fixes: QTBUG-71770 Reviewed-by: J-P Nurmi <jpnurmi@gmail.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* tst_qquickmenu: add a test for MenuItems before and after a Repeaterv5.12.0-beta4Mitch Curtis2018-11-021-1/+31
| | | | | | | | Just to verify that it works, as a similar test was added for Instantiator in another patch. Change-Id: I1ab55d98a3726bff1a2984db0d81ae444e05d630 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Fix Instantiator-created MenuItems disappearingMitch Curtis2018-11-021-0/+71
| | | | | | | | | | | | | | | When d5cb26bc fixed a bug in Menu, it also broke the use case of having an Instantiator create menu items. Using an Instantiator like this allows users to create a "Recent Files" menu, for example. The issue was that we would indiscriminately recreate items, even those owned by an Instantiator. This patch avoids recreating items owned by Instantiators. It also adds a logging category for Menu, to aid debugging. Fixes: QTBUG-71066 Change-Id: Ie0e46de1cbfaee81b43d63f3143435f2514371d5 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* tst_qquickmenu: fix memory leakv5.12.0-beta2Mitch Curtis2018-10-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | takeItem() unparents the item, so we need to make sure it gets deleted. The leak was caught by valgrind: ==10039== 832 (32 direct, 800 indirect) bytes in 1 blocks are definitely lost in loss record 6,465 of 6,706 ==10039== at 0x4C3017F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==10039== by 0x112C1E: tst_QQuickMenu::count() (tst_qquickmenu.cpp:121) ==10039== by 0x12F313: tst_QQuickMenu::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (tst_qquickmenu.moc:156) ==10039== by 0x612B6B2: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.cpp:2305) ==10039== by 0x41B07CD: invoke (qmetaobject.h:123) ==10039== by 0x41B07CD: QTest::TestMethods::invokeTestOnData(int) const (qtestcase.cpp:915) ==10039== by 0x41B15BF: QTest::TestMethods::invokeTest(int, char const*, QTest::WatchDog*) const (qtestcase.cpp:1114) ==10039== by 0x41B1D07: QTest::TestMethods::invokeTests(QObject*) const (qtestcase.cpp:1456) ==10039== by 0x41B2381: QTest::qRun() (qtestcase.cpp:1896) ==10039== by 0x41B24E1: QTest::qExec(QObject*, int, char**) (qtestcase.cpp:1783) ==10039== by 0x12F468: main (tst_qquickmenu.cpp:1505) Change-Id: I459c7897c1088c8b58152d2e0b5ceb8f3684e589 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Menu: ensure the correct delegates are used when created via ComponentMitch Curtis2018-09-051-0/+98
| | | | | | | | | | Don't add items until we're complete, as the delegate could change in the meantime. Instead, add them to contentData and create them when we're complete. Task-number: QTBUG-67559 Change-Id: I5f42129f49de861ff5f15d0069daeda0b4e5017c Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
* Menu: fix items not being scrollable when using WindowMitch Curtis2018-06-251-0/+27
| | | | | | | | | | Use Window.window instead of ApplicationWindow.window, as the former will always result in a window regardless of which type of window is in use. Task-number: QTBUG-68858 Change-Id: I3bdb60350d92b13621b0f4db9085bf067b6ff6e2 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Merge remote-tracking branch 'origin/5.9' into 5.10J-P Nurmi2017-09-271-0/+832
| | | | | | | | | | Conflicts: .gitignore tests/auto/auto.pro tests/auto/qquickmenu/tst_qquickmenu.cpp tests/auto/qquickpopup/tst_qquickpopup.cpp Change-Id: I7e5a7b39d890796fd63a7b24ae19765ab41fecda
* Rename tst_menu to tst_QQuickMenuJ-P Nurmi2017-09-271-0/+482
Change-Id: I1c7e1a2b337e9d16bc6c9b098db08f29f1b9d1e6 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>