* Remove the ImplicitDefaultAction intelligence, so ToggleActionMenu is not more than a KActionMenu with setDefaultAction(). * Instead, reset the default action when it gets removed from the menu(). This is done by filtering QActionEvent from menu(). * Add an autotest for ToggleActionMenu. This replaces prior efforts to fix problems in ToggleActionMenu in !245 and !254, following the discussion on the virtual meeting at 2021-02-26.remotes/origin/work/spdx6b26a2b4band1786e6c99have already ported PageView and AnnotationActionHandler to the simplified interface.
parent
394001017e
commit
5a58d3bb8e
4 changed files with 179 additions and 136 deletions
@ -0,0 +1,88 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2020 David Hurka <david.hurka@mailbox.org> * |
||||
* * |
||||
* This program is free software; you can redistribute it and/or modify * |
||||
* it under the terms of the GNU General Public License as published by * |
||||
* the Free Software Foundation; either version 2 of the License, or * |
||||
* (at your option) any later version. * |
||||
***************************************************************************/ |
||||
|
||||
#include <QtTest> |
||||
|
||||
#include "../part/toggleactionmenu.h" |
||||
#include <QToolBar> |
||||
|
||||
class ToggleActionMenuTest : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
private Q_SLOTS: |
||||
void testSetDefaultAction(); |
||||
void testDeleteToolBarButton(); |
||||
}; |
||||
|
||||
void ToggleActionMenuTest::testSetDefaultAction() |
||||
{ |
||||
QToolBar dummyToolBar; |
||||
ToggleActionMenu menu(QStringLiteral("Menu"), this); |
||||
QAction *actionA = new QAction(QStringLiteral("A"), this); |
||||
QAction *actionB = new QAction(QStringLiteral("B"), this); |
||||
|
||||
// Do not set a default action, the menu should behave as plain KActionMenu.
|
||||
QCOMPARE(menu.defaultAction(), &menu); |
||||
QToolButton *menuButton = qobject_cast<QToolButton *>(menu.createWidget(&dummyToolBar)); |
||||
QVERIFY(menuButton); |
||||
QCOMPARE(menuButton->defaultAction(), &menu); |
||||
|
||||
// Should still behave as plain KActionMenu when actions are added.
|
||||
menu.addAction(actionA); |
||||
QCOMPARE(menu.defaultAction(), &menu); |
||||
QCOMPARE(menuButton->defaultAction(), &menu); |
||||
|
||||
// Set an action from the menu as default action, should work.
|
||||
menu.setDefaultAction(actionA); |
||||
QCOMPARE(menu.defaultAction(), actionA); |
||||
QCOMPARE(menuButton->defaultAction(), actionA); |
||||
|
||||
// Set a foreign action as default action, should reset the default action.
|
||||
menu.setDefaultAction(actionB); |
||||
QCOMPARE(menu.defaultAction(), &menu); |
||||
QCOMPARE(menuButton->defaultAction(), &menu); |
||||
|
||||
// Set an action of the menu as default action, should work.
|
||||
menu.setDefaultAction(actionA); |
||||
QCOMPARE(menu.defaultAction(), actionA); |
||||
QCOMPARE(menuButton->defaultAction(), actionA); |
||||
|
||||
// Remove default action from menu, should reset the default action.
|
||||
menu.removeAction(actionA); |
||||
QCOMPARE(menu.defaultAction(), &menu); |
||||
QCOMPARE(menuButton->defaultAction(), &menu); |
||||
} |
||||
|
||||
void ToggleActionMenuTest::testDeleteToolBarButton() |
||||
{ |
||||
QToolBar dummyToolBar; |
||||
ToggleActionMenu menu(QStringLiteral("Menu"), this); |
||||
QAction *actionA = new QAction(QStringLiteral("A"), this); |
||||
QAction *actionB = new QAction(QStringLiteral("B"), this); |
||||
|
||||
// Setup: set a default action and create two toolbar buttons.
|
||||
menu.addAction(actionA); |
||||
menu.addAction(actionB); |
||||
menu.setDefaultAction(actionA); |
||||
QToolButton *menuButtonA = qobject_cast<QToolButton *>(menu.createWidget(&dummyToolBar)); |
||||
QVERIFY(menuButtonA); |
||||
QCOMPARE(menuButtonA->defaultAction(), actionA); |
||||
QToolButton *menuButtonB = qobject_cast<QToolButton *>(menu.createWidget(&dummyToolBar)); |
||||
QVERIFY(menuButtonB); |
||||
|
||||
// Delete button B, and set a new default action. Button A shall be updated without segfaulting on the deleted button B.
|
||||
delete menuButtonB; |
||||
menu.setDefaultAction(actionB); |
||||
QCOMPARE(menuButtonA->defaultAction(), actionB); |
||||
} |
||||
|
||||
QTEST_MAIN(ToggleActionMenuTest) |
||||
|
||||
#include "toggleactionmenutest.moc" |
||||
Loading…
Reference in new issue