summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-03-18 17:02:11 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-03-29 11:18:57 +0100
commitbcaff2b06fc46fce8a3ae6d613c025c8d097229c (patch)
treefde5485241a96c5ea1222e8299b046fdea9084e6
parente3d01840656a07f17549864da163b67094c03c0e (diff)
Remove QGuiAction again and split QAction implementation up instead
Duplicating the number of classes is a high price to pay to be able to have some QAction functionality behave differently, or be only available in widgets applications. Instead, declare the entire API in QtGui in QAction* classes, and delegate the implementation of QtWidgets specific functionality to the private. The creation of the private is then delegated to the Q(Gui)ApplicationPrivate instance through a virtual factory function. Change some public APIs that are primarily useful for specialized tools such as Designer to operate on QObject* rather than QWidget*. APIs that depend on QtWidgets types have been turned into inline template functions, so that they are instantiated only at the caller side, where we can expect the respective types to be fully defined. This way, we only need to forward declare a few classes in the header, and don't need to generate any additional code for e.g. language bindings. Change-Id: Id0b27f9187652ec531a2e8b1b9837e82dc81625c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.cpp2
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.cpp2
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.cpp1
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp2
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp1
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.cpp1
-rw-r--r--src/gui/CMakeLists.txt4
-rw-r--r--src/gui/kernel/kernel.pri12
-rw-r--r--src/gui/kernel/qaction.cpp (renamed from src/gui/kernel/qguiaction.cpp)503
-rw-r--r--src/gui/kernel/qaction.h (renamed from src/gui/kernel/qguiaction.h)113
-rw-r--r--src/gui/kernel/qaction_p.h (renamed from src/gui/kernel/qguiaction_p.h)30
-rw-r--r--src/gui/kernel/qactiongroup.cpp (renamed from src/gui/kernel/qguiactiongroup.cpp)180
-rw-r--r--src/gui/kernel/qactiongroup.h (renamed from src/gui/kernel/qguiactiongroup.h)32
-rw-r--r--src/gui/kernel/qactiongroup_p.h (renamed from src/gui/kernel/qguiactiongroup_p.h)18
-rw-r--r--src/gui/kernel/qevent.cpp6
-rw-r--r--src/gui/kernel/qevent.h10
-rw-r--r--src/gui/kernel/qguiapplication_p.h7
-rw-r--r--src/printsupport/dialogs/qprintpreviewdialog.cpp3
-rw-r--r--src/tools/uic/qclass_lib_map.h4
-rw-r--r--src/widgets/CMakeLists.txt3
-rw-r--r--src/widgets/accessible/qaccessiblemenu.cpp19
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp1
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.cpp10
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.h2
-rw-r--r--src/widgets/kernel/kernel.pri7
-rw-r--r--src/widgets/kernel/qaction.cpp354
-rw-r--r--src/widgets/kernel/qaction_widgets.cpp (renamed from src/widgets/kernel/qaction.h)109
-rw-r--r--src/widgets/kernel/qaction_widgets_p.h (renamed from src/widgets/kernel/qaction_p.h)50
-rw-r--r--src/widgets/kernel/qactiongroup.cpp188
-rw-r--r--src/widgets/kernel/qactiongroup.h80
-rw-r--r--src/widgets/kernel/qapplication.cpp1
-rw-r--r--src/widgets/kernel/qapplication_p.h4
-rw-r--r--src/widgets/kernel/qshortcut.cpp27
-rw-r--r--src/widgets/kernel/qwidget.cpp12
-rw-r--r--src/widgets/kernel/qwidgetaction.cpp1
-rw-r--r--src/widgets/kernel/qwidgetaction.h2
-rw-r--r--src/widgets/kernel/qwidgetaction_p.h4
-rw-r--r--src/widgets/styles/qstyleoption.cpp2
-rw-r--r--src/widgets/util/qsystemtrayicon.cpp1
-rw-r--r--src/widgets/util/qundostack_p.h2
-rw-r--r--src/widgets/widgets/qdialogbuttonbox.cpp2
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp4
-rw-r--r--src/widgets/widgets/qlineedit_p.h4
-rw-r--r--src/widgets/widgets/qmenu.cpp6
-rw-r--r--src/widgets/widgets/qmenu.h4
-rw-r--r--src/widgets/widgets/qtoolbar.cpp11
-rw-r--r--src/widgets/widgets/qtoolbar.h2
-rw-r--r--src/widgets/widgets/qtoolbar_p.h2
-rw-r--r--src/widgets/widgets/qtoolbarlayout.cpp2
-rw-r--r--src/widgets/widgets/qtoolbarlayout_p.h2
-rw-r--r--tests/auto/gui/kernel/kernel.pro8
-rw-r--r--tests/auto/gui/kernel/qaction/.gitignore (renamed from tests/auto/gui/kernel/qguiaction/.gitignore)0
-rw-r--r--tests/auto/gui/kernel/qaction/CMakeLists.txt14
-rw-r--r--tests/auto/gui/kernel/qaction/qaction.pro (renamed from tests/auto/gui/kernel/qguiaction/qguiaction.pro)4
-rw-r--r--tests/auto/gui/kernel/qaction/tst_qaction.cpp (renamed from tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp)80
-rw-r--r--tests/auto/gui/kernel/qactiongroup/.gitignore (renamed from tests/auto/gui/kernel/qguiactiongroup/.gitignore)0
-rw-r--r--tests/auto/gui/kernel/qactiongroup/CMakeLists.txt12
-rw-r--r--tests/auto/gui/kernel/qactiongroup/qactiongroup.pro (renamed from tests/auto/gui/kernel/qguiactiongroup/qguiactiongroup.pro)2
-rw-r--r--tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp (renamed from tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp)80
-rw-r--r--tests/auto/tools/uic/baseline/browserwidget.ui.h2
-rw-r--r--tests/auto/tools/uic/baseline/chatmainwindow.ui.h2
-rw-r--r--tests/auto/tools/uic/baseline/default.ui.h2
-rw-r--r--tests/auto/tools/uic/baseline/mainwindow.ui.h2
-rw-r--r--tests/auto/tools/uic/baseline/pagefold.ui.h2
-rw-r--r--tests/auto/tools/uic/baseline/qttrid.ui.h2
-rw-r--r--tests/auto/tools/uic/baseline/remotecontrol.ui.h2
-rw-r--r--tests/auto/tools/uic/baseline/trpreviewtool.ui.h2
-rw-r--r--tests/auto/widgets/kernel/qaction/tst_qaction.cpp3
-rw-r--r--tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp1
-rw-r--r--tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp2
-rw-r--r--tests/manual/cocoa/menurama/main.cpp2
-rw-r--r--tests/manual/foreignwindows/main.cpp2
72 files changed, 858 insertions, 1217 deletions
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
index 5662518ddc..a7e73debb6 100644
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
@@ -50,7 +50,7 @@
#include "colorswatch.h"
-#include <QAction>
+#include <QActionGroup>
#include <QtEvents>
#include <QFrame>
#include <QMainWindow>
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
index 4ba180f312..a43adfceac 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
@@ -52,7 +52,7 @@
#include "colorswatch.h"
#include "toolbar.h"
-#include <QAction>
+#include <QActionGroup>
#include <QLayout>
#include <QMenu>
#include <QMenuBar>
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
index 36d4108b1e..6a5faf248f 100644
--- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
@@ -52,6 +52,7 @@
#include <QRandomGenerator>
+#include <QActionGroup>
#include <QMainWindow>
#include <QMenu>
#include <QPainter>
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
index 7cfe3f6c05..eccc29d26d 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QAction>
+#include <QActionGroup>
#include <QApplication>
#include <QClipboard>
#include <QColorDialog>
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index be92f83c75..aa5ed852fd 100644
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
@@ -53,6 +53,7 @@
#include "iconsizespinbox.h"
#include "imagedelegate.h"
+#include <QActionGroup>
#include <QApplication>
#include <QButtonGroup>
#include <QCheckBox>
diff --git a/examples/widgets/widgets/tablet/mainwindow.cpp b/examples/widgets/widgets/tablet/mainwindow.cpp
index c5b631ee44..102fb813b8 100644
--- a/examples/widgets/widgets/tablet/mainwindow.cpp
+++ b/examples/widgets/widgets/tablet/mainwindow.cpp
@@ -51,6 +51,7 @@
#include "mainwindow.h"
#include "tabletcanvas.h"
+#include <QActionGroup>
#include <QApplication>
#include <QColorDialog>
#include <QDir>
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 67a6465b75..e34ad697e4 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -450,8 +450,8 @@ qt_extend_target(Gui CONDITION APPLE AND QT_FEATURE_accessibility
qt_extend_target(Gui CONDITION QT_FEATURE_action
SOURCES
- kernel/qguiaction.cpp kernel/qguiaction.h kernel/qguiaction_p.h
- kernel/qguiactiongroup.cpp kernel/qguiactiongroup.h kernel/qguiactiongroup_p.h
+ kernel/qaction.cpp kernel/qaction.h kernel/qaction_p.h
+ kernel/qactiongroup.cpp kernel/qactiongroup.h kernel/qactiongroup_p.h
)
qt_extend_target(Gui CONDITION QT_FEATURE_draganddrop
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
index d47fd6e4e4..518220ad3e 100644
--- a/src/gui/kernel/kernel.pri
+++ b/src/gui/kernel/kernel.pri
@@ -128,14 +128,14 @@ SOURCES += \
qtConfig(action) {
HEADERS += \
- kernel/qguiaction.h \
- kernel/qguiaction_p.h \
- kernel/qguiactiongroup.h \
- kernel/qguiactiongroup_p.h
+ kernel/qaction.h \
+ kernel/qaction_p.h \
+ kernel/qactiongroup.h \
+ kernel/qactiongroup_p.h
SOURCES += \
- kernel/qguiactiongroup.cpp \
- kernel/qguiaction.cpp
+ kernel/qactiongroup.cpp \
+ kernel/qaction.cpp
}
qtConfig(draganddrop) {
diff --git a/src/gui/kernel/qguiaction.cpp b/src/gui/kernel/qaction.cpp
index 84750194b6..99a614ddd9 100644
--- a/src/gui/kernel/qguiaction.cpp
+++ b/src/gui/kernel/qaction.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
@@ -37,10 +37,10 @@
**
****************************************************************************/
-#include "qguiaction.h"
-#include "qguiactiongroup.h"
+#include "qaction.h"
+#include "qactiongroup.h"
-#include "qguiaction_p.h"
+#include "qaction_p.h"
#include "qguiapplication.h"
#include "qevent.h"
#include "qlist.h"
@@ -53,7 +53,7 @@
#define QAPP_CHECK(functionName) \
if (Q_UNLIKELY(!QCoreApplication::instance())) { \
- qWarning("QGuiAction: Initialize Q(Gui)Application before calling '" functionName "'."); \
+ qWarning("QAction: Initialize Q(Gui)Application before calling '" functionName "'."); \
return; \
}
@@ -72,7 +72,12 @@ static QString qt_strippedText(QString s)
return s.trimmed();
}
-QGuiActionPrivate::QGuiActionPrivate() :
+QActionPrivate *QGuiApplicationPrivate::createActionPrivate() const
+{
+ return new QActionPrivate;
+}
+
+QActionPrivate::QActionPrivate() :
#if QT_CONFIG(shortcut)
autorepeat(1),
#endif
@@ -85,17 +90,21 @@ QGuiActionPrivate::QGuiActionPrivate() :
#if QT_CONFIG(shortcut)
static bool dummy(QObject *, Qt::ShortcutContext) { return false; } // only for GUI testing.
-QShortcutMap::ContextMatcher QGuiActionPrivate::contextMatcher() const
+QShortcutMap::ContextMatcher QActionPrivate::contextMatcher() const
{
return dummy;
-}
+};
#endif // QT_CONFIG(shortcut)
-QGuiActionPrivate::~QGuiActionPrivate() = default;
+QActionPrivate::~QActionPrivate() = default;
-void QGuiActionPrivate::sendDataChanged()
+void QActionPrivate::destroy()
{
- Q_Q(QGuiAction);
+}
+
+void QActionPrivate::sendDataChanged()
+{
+ Q_Q(QAction);
QActionEvent e(QEvent::ActionChanged, q);
QCoreApplication::sendEvent(q, &e);
@@ -103,9 +112,9 @@ void QGuiActionPrivate::sendDataChanged()
}
#if QT_CONFIG(shortcut)
-void QGuiActionPrivate::redoGrab(QShortcutMap &map)
+void QActionPrivate::redoGrab(QShortcutMap &map)
{
- Q_Q(QGuiAction);
+ Q_Q(QAction);
if (shortcutId)
map.removeShortcut(shortcutId, q);
if (shortcut.isEmpty())
@@ -117,9 +126,9 @@ void QGuiActionPrivate::redoGrab(QShortcutMap &map)
map.setShortcutAutoRepeat(false, shortcutId, q);
}
-void QGuiActionPrivate::redoGrabAlternate(QShortcutMap &map)
+void QActionPrivate::redoGrabAlternate(QShortcutMap &map)
{
- Q_Q(QGuiAction);
+ Q_Q(QAction);
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
if (const int id = alternateShortcutIds.at(i))
map.removeShortcut(id, q);
@@ -148,9 +157,9 @@ void QGuiActionPrivate::redoGrabAlternate(QShortcutMap &map)
}
}
-void QGuiActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
+void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
{
- Q_Q(QGuiAction);
+ Q_Q(QAction);
if (shortcutId)
map.setShortcutEnabled(enable, shortcutId, q);
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
@@ -160,11 +169,29 @@ void QGuiActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
}
#endif // QT_NO_SHORTCUT
+bool QActionPrivate::showStatusText(QObject *object, const QString &str)
+{
+ if (QObject *receiver = object ? object : parent) {
+ QStatusTipEvent tip(str);
+ QCoreApplication::sendEvent(receiver, &tip);
+ return true;
+ }
+ return false;
+}
+
+void QActionPrivate::setMenu(QObject *)
+{
+}
+
+QObject *QActionPrivate::menu() const
+{
+ return nullptr;
+}
/*!
- \class QGuiAction
- \brief QGuiAction is the base class for actions, an abstract user interface
- action that can be inserted into widgets.
+ \class QAction
+ \brief The QAction class provides an abstraction for user commands
+ that can be added to different user interface components.
\since 6.0
\inmodule QtGui
@@ -180,12 +207,7 @@ void QGuiActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
if the user presses a Bold toolbar button, the Bold menu item
will automatically be checked.
- Actions can be created as independent objects, but they may
- also be created during the construction of menus; the QMenu class
- contains convenience functions for creating actions suitable for
- use as menu items.
-
- A QGuiAction may contain an icon, menu text, a shortcut, status text,
+ A QAction may contain an icon, menu text, a shortcut, status text,
"What's This?" text, and a tooltip. Most of these can be set in
the constructor. They can also be set independently with
setIcon(), setText(), setIconText(), setShortcut(),
@@ -196,23 +218,42 @@ void QGuiActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
they are used in. In most cases actions will be children of
the application's main window.
+ \section1 QAction in widget applications
+
+ Once a QAction has been created, it should be added to the relevant
+ menu and toolbar, then connected to the slot which will perform
+ the action. For example:
+
+ \snippet mainwindows/application/mainwindow.cpp 19
+
+ Actions are added to widgets using QWidget::addAction() or
+ QGraphicsWidget::addAction(). Note that an action must be added to a
+ widget before it can be used. This is also true when the shortcut should
+ be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext).
+
+ Actions can be created as independent objects. But they may
+ also be created during the construction of menus. The QMenu class
+ contains convenience functions for creating actions suitable for
+ use as menu items.
+
+
\sa QMenu, QToolBar, {Application Example}
*/
/*!
- \fn void QGuiAction::trigger()
+ \fn void QAction::trigger()
This is a convenience slot that calls activate(Trigger).
*/
/*!
- \fn void QGuiAction::hover()
+ \fn void QAction::hover()
This is a convenience slot that calls activate(Hover).
*/
/*!
- \enum QGuiAction::MenuRole
+ \enum QAction::MenuRole
This enum describes how an action should be moved into the application menu on \macos.
@@ -239,8 +280,8 @@ void QGuiActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
\note The \a parent argument is optional since Qt 5.7.
*/
-QGuiAction::QGuiAction(QObject *parent)
- : QGuiAction(*new QGuiActionPrivate, parent)
+QAction::QAction(QObject *parent)
+ : QAction(*QGuiApplicationPrivate::instance()->createActionPrivate(), parent)
{
}
@@ -257,10 +298,10 @@ QGuiAction::QGuiAction(QObject *parent)
setToolTip().
*/
-QGuiAction::QGuiAction(const QString &text, QObject *parent)
- : QGuiAction(parent)
+QAction::QAction(const QString &text, QObject *parent)
+ : QAction(parent)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
d->text = text;
}
@@ -276,38 +317,38 @@ QGuiAction::QGuiAction(const QString &text, QObject *parent)
tooltips unless you specify a different text using
setToolTip().
*/
-QGuiAction::QGuiAction(const QIcon &icon, const QString &text, QObject *parent)
- : QGuiAction(text, parent)
+QAction::QAction(const QIcon &icon, const QString &text, QObject *parent)
+ : QAction(text, parent)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
d->icon = icon;
}
/*!
\internal
*/
-QGuiAction::QGuiAction(QGuiActionPrivate &dd, QObject *parent)
+QAction::QAction(QActionPrivate &dd, QObject *parent)
: QObject(dd, parent)
{
- Q_D(QGuiAction);
- d->group = qobject_cast<QGuiActionGroup *>(parent);
+ Q_D(QAction);
+ d->group = qobject_cast<QActionGroup *>(parent);
if (d->group)
d->group->addAction(this);
}
#if QT_CONFIG(shortcut)
/*!
- \property QGuiAction::shortcut
+ \property QAction::shortcut
\brief the action's primary shortcut key
Valid keycodes for this property can be found in \l Qt::Key and
\l Qt::Modifier. There is no default shortcut key.
*/
-void QGuiAction::setShortcut(const QKeySequence &shortcut)
+void QAction::setShortcut(const QKeySequence &shortcut)
{
QAPP_CHECK("setShortcut");
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->shortcut == shortcut)
return;
@@ -322,9 +363,9 @@ void QGuiAction::setShortcut(const QKeySequence &shortcut)
\sa shortcut
*/
-void QGuiAction::setShortcuts(const QList<QKeySequence> &shortcuts)
+void QAction::setShortcuts(const QList<QKeySequence> &shortcuts)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
QList <QKeySequence> listCopy = shortcuts;
@@ -352,7 +393,7 @@ void QGuiAction::setShortcuts(const QList<QKeySequence> &shortcuts)
\sa QKeySequence::keyBindings()
*/
-void QGuiAction::setShortcuts(QKeySequence::StandardKey key)
+void QAction::setShortcuts(QKeySequence::StandardKey key)
{
QList <QKeySequence> list = QKeySequence::keyBindings(key);
setShortcuts(list);
@@ -363,9 +404,9 @@ void QGuiAction::setShortcuts(QKeySequence::StandardKey key)
\sa setShortcuts()
*/
-QKeySequence QGuiAction::shortcut() const
+QKeySequence QAction::shortcut() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->shortcut;
}
@@ -375,9 +416,9 @@ QKeySequence QGuiAction::shortcut() const
\sa setShortcuts()
*/
-QList<QKeySequence> QGuiAction::shortcuts() const
+QList<QKeySequence> QAction::shortcuts() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
QList <QKeySequence> shortcuts;
if (!d->shortcut.isEmpty())
shortcuts << d->shortcut;
@@ -387,15 +428,15 @@ QList<QKeySequence> QGuiAction::shortcuts() const
}
/*!
- \property QGuiAction::shortcutContext
+ \property QAction::shortcutContext
\brief the context for the action's shortcut
Valid values for this property can be found in \l Qt::ShortcutContext.
The default value is Qt::WindowShortcut.
*/
-void QGuiAction::setShortcutContext(Qt::ShortcutContext context)
+void QAction::setShortcutContext(Qt::ShortcutContext context)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->shortcutContext == context)
return;
QAPP_CHECK("setShortcutContext");
@@ -405,14 +446,14 @@ void QGuiAction::setShortcutContext(Qt::ShortcutContext context)
d->sendDataChanged();
}
-Qt::ShortcutContext QGuiAction::shortcutContext() const
+Qt::ShortcutContext QAction::shortcutContext() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->shortcutContext;
}
/*!
- \property QGuiAction::autoRepeat
+ \property QAction::autoRepeat
\brief whether the action can auto repeat
If true, the action will auto repeat when the keyboard shortcut
@@ -420,9 +461,9 @@ Qt::ShortcutContext QGuiAction::shortcutContext() const
enabled on the system.
The default value is true.
*/
-void QGuiAction::setAutoRepeat(bool on)
+void QAction::setAutoRepeat(bool on)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->autorepeat == on)
return;
QAPP_CHECK("setAutoRepeat");
@@ -432,28 +473,28 @@ void QGuiAction::setAutoRepeat(bool on)
d->sendDataChanged();
}
-bool QGuiAction::autoRepeat() const
+bool QAction::autoRepeat() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->autorepeat;
}
#endif // QT_CONFIG(shortcut)
/*!
- \property QGuiAction::font
+ \property QAction::font
\brief the action's font
The font property is used to render the text set on the
- QGuiAction. The font will can be considered a hint as it will not be
+ QAction. The font can be considered a hint as it will not be
consulted in all cases based upon application and style.
By default, this property contains the application's default font.
\sa setText()
*/
-void QGuiAction::setFont(const QFont &font)
+void QAction::setFont(const QFont &font)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->font == font)
return;
@@ -462,9 +503,9 @@ void QGuiAction::setFont(const QFont &font)
d->sendDataChanged();
}
-QFont QGuiAction::font() const
+QFont QAction::font() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->font;
}
@@ -472,9 +513,12 @@ QFont QGuiAction::font() const
/*!
Destroys the object and frees allocated resources.
*/
-QGuiAction::~QGuiAction()
+QAction::~QAction()
{
- Q_D(QGuiAction);
+ Q_D(QAction);
+
+ d->destroy();
+
if (d->group)
d->group->removeAction(this);
#if QT_CONFIG(shortcut)
@@ -492,11 +536,11 @@ QGuiAction::~QGuiAction()
Actions within the group will be mutually exclusive.
- \sa QGuiActionGroup, guiActionGroup()
+ \sa QActionGroup, actionGroup()
*/
-void QGuiAction::setActionGroup(QGuiActionGroup *group)
+void QAction::setActionGroup(QActionGroup *group)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if(group == d->group)
return;
@@ -512,17 +556,53 @@ void QGuiAction::setActionGroup(QGuiActionGroup *group)
Returns the action group for this action. If no action group manages
this action, then \nullptr will be returned.
- \sa QGuiActionGroup, setActionGroup()
+ \sa QActionGroup, setActionGroup()
*/
-QGuiActionGroup *QGuiAction::guiActionGroup() const
+QActionGroup *QAction::actionGroup() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->group;
}
+/*!
+ \since 6.0
+ Returns a list of objects this action has been added to.
+
+ \sa QWidget::addAction(), QGraphicsWidget::addAction()
+*/
+QVector<QObject*> QAction::associatedObjects() const
+{
+ Q_D(const QAction);
+ return d->associatedObjects;
+}
+
+/*!
+ \fn QWidget *QAction::parentWidget() const
+ \obsolete Use parent() with qobject_cast() instead.
+
+ Returns the parent widget.
+*/
+
+/*!
+ \fn QList<QWidget*> QAction::associatedWidgets() const
+ \obsolete Use associatedObjects() with qobject_cast() instead.
+
+ Returns a list of widgets this action has been added to.
+
+ \sa QWidget::addAction(), associatedObjects(), associatedGraphicsWidgets()
+*/
+
+/*!
+ \fn QList<QWidget*> QAction::associatedGraphicsWidgets() const
+ \obsolete Use associatedObjects() with qobject_cast() instead.
+
+ Returns a list of graphics widgets this action has been added to.
+
+ \sa QGraphicsWidget::addAction(), associatedObjects(), associatedWidgets()
+*/
/*!
- \property QGuiAction::icon
+ \property QAction::icon
\brief the action's icon
In toolbars, the icon is used as the tool button icon; in menus,
@@ -532,16 +612,16 @@ QGuiActionGroup *QGuiAction::guiActionGroup() const
If a null icon (QIcon::isNull()) is passed into this function,
the icon of the action is cleared.
*/
-void QGuiAction::setIcon(const QIcon &icon)
+void QAction::setIcon(const QIcon &icon)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
d->icon = icon;
d->sendDataChanged();
}
-QIcon QGuiAction::icon() const
+QIcon QAction::icon() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->icon;
}
@@ -554,9 +634,9 @@ QIcon QGuiAction::icon() const
\sa isSeparator()
*/
-void QGuiAction::setSeparator(bool b)
+void QAction::setSeparator(bool b)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->separator == b)
return;
@@ -570,14 +650,14 @@ void QGuiAction::setSeparator(bool b)
\sa setSeparator()
*/
-bool QGuiAction::isSeparator() const
+bool QAction::isSeparator() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->separator;
}
/*!
- \property QGuiAction::text
+ \property QAction::text
\brief the action's descriptive text
If the action is added to a menu, the menu option will consist of
@@ -588,9 +668,9 @@ bool QGuiAction::isSeparator() const
\sa iconText
*/
-void QGuiAction::setText(const QString &text)
+void QAction::setText(const QString &text)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->text == text)
return;
@@ -598,9 +678,9 @@ void QGuiAction::setText(const QString &text)
d->sendDataChanged();
}
-QString QGuiAction::text() const
+QString QAction::text() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
QString s = d->text;
if(s.isEmpty()) {
s = d->iconText;
@@ -610,7 +690,7 @@ QString QGuiAction::text() const
}
/*!
- \property QGuiAction::iconText
+ \property QAction::iconText
\brief the action's descriptive icon text
If QToolBar::toolButtonStyle is set to a value that permits text to
@@ -628,9 +708,9 @@ QString QGuiAction::text() const
\sa setToolTip(), setStatusTip()
*/
-void QGuiAction::setIconText(const QString &text)
+void QAction::setIconText(const QString &text)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->iconText == text)
return;
@@ -638,16 +718,16 @@ void QGuiAction::setIconText(const QString &text)
d->sendDataChanged();
}
-QString QGuiAction::iconText() const
+QString QAction::iconText() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
if (d->iconText.isEmpty())
return qt_strippedText(d->text);
return d->iconText;
}
/*!
- \property QGuiAction::toolTip
+ \property QAction::toolTip
\brief the action's tooltip
This text is used for the tooltip. If no tooltip is specified,
@@ -657,9 +737,9 @@ QString QGuiAction::iconText() const
\sa setStatusTip(), setShortcut()
*/
-void QGuiAction::setToolTip(const QString &tooltip)
+void QAction::setToolTip(const QString &tooltip)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->tooltip == tooltip)
return;
@@ -667,9 +747,9 @@ void QGuiAction::setToolTip(const QString &tooltip)
d->sendDataChanged();
}
-QString QGuiAction::toolTip() const
+QString QAction::toolTip() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
if (d->tooltip.isEmpty()) {
if (!d->text.isEmpty())
return qt_strippedText(d->text);
@@ -679,7 +759,7 @@ QString QGuiAction::toolTip() const
}
/*!
- \property QGuiAction::statusTip
+ \property QAction::statusTip
\brief the action's status tip
The status tip is displayed on all status bars provided by the
@@ -689,9 +769,9 @@ QString QGuiAction::toolTip() const
\sa setToolTip(), showStatusText()
*/
-void QGuiAction::setStatusTip(const QString &statustip)
+void QAction::setStatusTip(const QString &statustip)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->statustip == statustip)
return;
@@ -699,14 +779,28 @@ void QGuiAction::setStatusTip(const QString &statustip)
d->sendDataChanged();
}
-QString QGuiAction::statusTip() const
+QString QAction::statusTip() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->statustip;
}
/*!
- \property QGuiAction::whatsThis
+ Updates the relevant status bar for the UI represented by \a object by sending a
+ QStatusTipEvent. Returns \c true if an event was sent, otherwise returns \c false.
+
+ If a null widget is specified, the event is sent to the action's parent.
+
+ \sa statusTip
+*/
+bool QAction::showStatusText(QObject *object)
+{
+ Q_D(QAction);
+ return d->showStatusText(object, statusTip());
+}
+
+/*!
+ \property QAction::whatsThis
\brief the action's "What's This?" help text
The "What's This?" text is used to provide a brief description of
@@ -715,9 +809,9 @@ QString QGuiAction::statusTip() const
\sa QWhatsThis
*/
-void QGuiAction::setWhatsThis(const QString &whatsthis)
+void QAction::setWhatsThis(const QString &whatsthis)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->whatsthis == whatsthis)
return;
@@ -725,14 +819,14 @@ void QGuiAction::setWhatsThis(const QString &whatsthis)
d->sendDataChanged();
}
-QString QGuiAction::whatsThis() const
+QString QAction::whatsThis() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->whatsthis;
}
/*!
- \enum QGuiAction::Priority
+ \enum QAction::Priority
This enum defines priorities for actions in user interface.
@@ -749,7 +843,7 @@ QString QGuiAction::whatsThis() const
/*!
- \property QGuiAction::priority
+ \property QAction::priority
\brief the actions's priority in the user interface.
@@ -760,9 +854,9 @@ QString QGuiAction::whatsThis() const
mode set, then actions with LowPriority will not show the text
labels.
*/
-void QGuiAction::setPriority(Priority priority)
+void QAction::setPriority(Priority priority)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->priority == priority)
return;
@@ -770,14 +864,14 @@ void QGuiAction::setPriority(Priority priority)
d->sendDataChanged();
}
-QGuiAction::Priority QGuiAction::priority() const
+QAction::Priority QAction::priority() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->priority;
}
/*!
- \property QGuiAction::checkable
+ \property QAction::checkable
\brief whether the action is a checkable action
A checkable action is one which has an on/off state. For example,
@@ -790,19 +884,19 @@ QGuiAction::Priority QGuiAction::priority() const
on the state of others. For example, "Left Align", "Center" and
"Right Align" toggle actions are mutually exclusive. To achieve
exclusive toggling, add the relevant toggle actions to a
- QGuiActionGroup with the QGuiActionGroup::exclusive property set to
+ QActionGroup with the QActionGroup::exclusive property set to
true.
\sa setChecked()
*/
-void QGuiAction::setCheckable(bool b)
+void QAction::setCheckable(bool b)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->checkable == b)
return;
d->checkable = b;
- QPointer<QGuiAction> guard(this);
+ QPointer<QAction> guard(this);
d->sendDataChanged();
if (guard)
emit checkableChanged(b);
@@ -810,59 +904,59 @@ void QGuiAction::setCheckable(bool b)
emit toggled(b);
}
-bool QGuiAction::isCheckable() const
+bool QAction::isCheckable() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->checkable;
}
/*!
- \fn void QGuiAction::toggle()
+ \fn void QAction::toggle()
This is a convenience function for the \l checked property.
Connect to it to change the checked state to its opposite state.
*/
-void QGuiAction::toggle()
+void QAction::toggle()
{
- Q_D(QGuiAction);
+ Q_D(QAction);
setChecked(!d->checked);
}
/*!
- \property QGuiAction::checked
+ \property QAction::checked
\brief whether the action is checked.
Only checkable actions can be checked. By default, this is false
(the action is unchecked).
\note The notifier signal for this property is toggled(). As toggling
- a QGuiAction changes its state, it will also emit a changed() signal.
+ a QAction changes its state, it will also emit a changed() signal.
\sa checkable, toggled()
*/
-void QGuiAction::setChecked(bool b)
+void QAction::setChecked(bool b)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->checked == b)
return;
d->checked = b;
if (!d->checkable)
return;
- QPointer<QGuiAction> guard(this);
+ QPointer<QAction> guard(this);
d->sendDataChanged();
if (guard)
emit toggled(b);
}
-bool QGuiAction::isChecked() const
+bool QAction::isChecked() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->checked && d->checkable;
}
/*!
- \fn void QGuiAction::setDisabled(bool b)
+ \fn void QAction::setDisabled(bool b)
This is a convenience function for the \l enabled property, that
is useful for signals--slots connections. If \a b is true the
@@ -870,7 +964,7 @@ bool QGuiAction::isChecked() const
*/
/*!
- \property QGuiAction::enabled
+ \property QAction::enabled
\brief whether the action is enabled
Disabled actions cannot be chosen by the user. They do not
@@ -879,7 +973,7 @@ bool QGuiAction::isChecked() const
be displayed using only shades of gray.
\uicontrol{What's This?} help on disabled actions is still available, provided
- that the QGuiAction::whatsThis property is set.
+ that the QAction::whatsThis property is set.
An action will be disabled when all widgets to which it is added
(with QWidget::addAction()) are disabled or not visible. When an
@@ -890,9 +984,9 @@ bool QGuiAction::isChecked() const
\sa text
*/
-void QGuiAction::setEnabled(bool b)
+void QAction::setEnabled(bool b)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->explicitEnabledValue == b && d->explicitEnabled)
return;
d->explicitEnabledValue = b;
@@ -901,9 +995,9 @@ void QGuiAction::setEnabled(bool b)
d->setEnabled(b, false);
}
-bool QGuiActionPrivate::setEnabled(bool b, bool byGroup)
+bool QActionPrivate::setEnabled(bool b, bool byGroup)
{
- Q_Q(QGuiAction);
+ Q_Q(QAction);
if (b && !visible)
b = false;
if (b && !byGroup && (group && !group->isEnabled()))
@@ -925,23 +1019,23 @@ bool QGuiActionPrivate::setEnabled(bool b, bool byGroup)
return true;
}
-void QGuiAction::resetEnabled()
+void QAction::resetEnabled()
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (!d->explicitEnabled)
return;
d->explicitEnabled = false;
d->setEnabled(true, false);
}
-bool QGuiAction::isEnabled() const
+bool QAction::isEnabled() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->enabled;
}
/*!
- \property QGuiAction::visible
+ \property QAction::visible
\brief whether the action can be seen (e.g. in menus and toolbars)
If \e visible is true the action can be seen (e.g. in menus and
@@ -953,9 +1047,9 @@ bool QGuiAction::isEnabled() const
By default, this property is \c true (actions are visible).
*/
-void QGuiAction::setVisible(bool b)
+void QAction::setVisible(bool b)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (b == d->visible && b != d->forceInvisible)
return;
QAPP_CHECK("setVisible");
@@ -969,25 +1063,31 @@ void QGuiAction::setVisible(bool b)
}
-bool QGuiAction::isVisible() const
+bool QAction::isVisible() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->visible;
}
/*!
\reimp
*/
-bool QGuiAction::event(QEvent *e)
+bool QAction::event(QEvent *e)
{
+ Q_D(QAction);
+ if (e->type() == QEvent::ActionChanged) {
+ for (auto object : qAsConst(d->associatedObjects))
+ QCoreApplication::sendEvent(object, e);
+ }
+
#if QT_CONFIG(shortcut)
if (e->type() == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()),
- "QGuiAction::event",
+ "QAction::event",
"Received shortcut event from incorrect shortcut");
if (se->isAmbiguous())
- qWarning("QGuiAction::event: Ambiguous shortcut overload: %s", se->key().toString(QKeySequence::NativeText).toLatin1().constData());
+ qWarning("QAction::event: Ambiguous shortcut overload: %s", se->key().toString(QKeySequence::NativeText).toLatin1().constData());
else
activate(Trigger);
return true;
@@ -997,13 +1097,13 @@ bool QGuiAction::event(QEvent *e)
}
/*!
- Returns the user data as set in QGuiAction::setData.
+ Returns the user data as set in QAction::setData.
\sa setData()
*/
-QVariant QGuiAction::data() const
+QVariant QAction::data() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->userData;
}
@@ -1012,9 +1112,9 @@ QVariant QGuiAction::data() const
\sa data()
*/
-void QGuiAction::setData(const QVariant &data)
+void QAction::setData(const QVariant &data)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->userData == data)
return;
d->userData = data;
@@ -1024,19 +1124,19 @@ void QGuiAction::setData(const QVariant &data)
/*!
Sends the relevant signals for ActionEvent \a event.
- Action based widgets use this API to cause the QGuiAction
+ Action-based widgets use this API to cause the QAction
to emit signals as well as emitting their own.
*/
-void QGuiAction::activate(ActionEvent event)
+void QAction::activate(ActionEvent event)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if(event == Trigger) {
QPointer<QObject> guard = this;
if(d->checkable) {
// the checked action of an exclusive group may not be unchecked
if (d->checked && (d->group
- && d->group->exclusionPolicy() == QGuiActionGroup::ExclusionPolicy::Exclusive
- && d->group->checkedGuiAction() == this)) {
+ && d->group->exclusionPolicy() == QActionGroup::ExclusionPolicy::Exclusive
+ && d->group->checkedAction() == this)) {
if (!guard.isNull())
emit triggered(true);
return;
@@ -1051,7 +1151,7 @@ void QGuiAction::activate(ActionEvent event)
}
/*!
- \fn void QGuiAction::triggered(bool checked)
+ \fn void QAction::triggered(bool checked)
This signal is emitted when an action is activated by the user;
for example, when the user clicks a menu option, toolbar button,
@@ -1066,12 +1166,12 @@ void QGuiAction::activate(ActionEvent event)
*/
/*!
- \fn void QGuiAction::toggled(bool checked)
+ \fn void QAction::toggled(bool checked)
This signal is emitted whenever a checkable action changes its
isChecked() status. This can be the result of a user interaction,
or because setChecked() was called. As setChecked() changes the
- QGuiAction, it emits changed() in addition to toggled().
+ QAction, it emits changed() in addition to toggled().
\a checked is true if the action is checked, or false if the
action is unchecked.
@@ -1080,7 +1180,7 @@ void QGuiAction::activate(ActionEvent event)
*/
/*!
- \fn void QGuiAction::hovered()
+ \fn void QAction::hovered()
This signal is emitted when an action is highlighted by the user;
for example, when the user pauses with the cursor over a menu option,
@@ -1090,7 +1190,7 @@ void QGuiAction::activate(ActionEvent event)
*/
/*!
- \fn void QGuiAction::changed()
+ \fn void QAction::changed()
This signal is emitted when an action has changed. If you
are only interested in actions in a given widget, you can
@@ -1101,17 +1201,17 @@ void QGuiAction::activate(ActionEvent event)
*/
/*!
- \enum QGuiAction::ActionEvent
+ \enum QAction::ActionEvent
- This enum type is used when calling QGuiAction::activate()
+ This enum type is used when calling QAction::activate()
- \value Trigger this will cause the QGuiAction::triggered() signal to be emitted.
+ \value Trigger this will cause the QAction::triggered() signal to be emitted.
- \value Hover this will cause the QGuiAction::hovered() signal to be emitted.
+ \value Hover this will cause the QAction::hovered() signal to be emitted.
*/
/*!
- \property QGuiAction::menuRole
+ \property QAction::menuRole
\brief the action's menu role
This indicates what role the action serves in the application menu on
@@ -1122,9 +1222,9 @@ void QGuiAction::activate(ActionEvent event)
bar in \macos (usually just before the first application window is
shown).
*/
-void QGuiAction::setMenuRole(MenuRole menuRole)
+void QAction::setMenuRole(MenuRole menuRole)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->menuRole == menuRole)
return;
@@ -1132,14 +1232,43 @@ void QGuiAction::setMenuRole(MenuRole menuRole)
d->sendDataChanged();
}
-QGuiAction::MenuRole QGuiAction::menuRole() const
+QAction::MenuRole QAction::menuRole() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
return d->menuRole;
}
/*!
- \property QGuiAction::iconVisibleInMenu
+ \fn QMenu *QAction::menu() const
+ \obsolete
+
+ Returns the menu contained by this action.
+
+ In widget applications, actions that contain menus can be used to create menu
+ items with submenus, or inserted into toolbars to create buttons with popup menus.
+
+ \sa QMenu::addAction()
+*/
+QObject* QAction::menuObject() const
+{
+ Q_D(const QAction);
+ return d->menu();
+}
+
+/*!
+ \fn void QAction::setMenu(QMenu *menu)
+ \obsolete
+
+ Sets the menu contained by this action to the specified \a menu.
+*/
+void QAction::setMenuObject(QObject *object)
+{
+ Q_D(QAction);
+ d->setMenu(object);
+}
+
+/*!
+ \property QAction::iconVisibleInMenu
\brief Whether or not an action should show an icon in a menu
In some applications, it may make sense to have actions with icons in the
@@ -1155,9 +1284,9 @@ QGuiAction::MenuRole QGuiAction::menuRole() const
\sa icon, QCoreApplication::setAttribute()
*/
-void QGuiAction::setIconVisibleInMenu(bool visible)
+void QAction::setIconVisibleInMenu(bool visible)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->iconVisibleInMenu == -1 || visible != bool(d->iconVisibleInMenu)) {
int oldValue = d->iconVisibleInMenu;
d->iconVisibleInMenu = visible;
@@ -1169,9 +1298,9 @@ void QGuiAction::setIconVisibleInMenu(bool visible)
}
}
-bool QGuiAction::isIconVisibleInMenu() const
+bool QAction::isIconVisibleInMenu() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
if (d->iconVisibleInMenu == -1) {
return !QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus);
}
@@ -1179,7 +1308,7 @@ bool QGuiAction::isIconVisibleInMenu() const
}
/*!
- \property QGuiAction::shortcutVisibleInContextMenu
+ \property QAction::shortcutVisibleInContextMenu
\brief Whether or not an action should show a shortcut in a context menu
In some applications, it may make sense to have actions with shortcuts in
@@ -1192,9 +1321,9 @@ bool QGuiAction::isIconVisibleInMenu() const
\sa shortcut, QCoreApplication::setAttribute()
*/
-void QGuiAction::setShortcutVisibleInContextMenu(bool visible)
+void QAction::setShortcutVisibleInContextMenu(bool visible)
{
- Q_D(QGuiAction);
+ Q_D(QAction);
if (d->shortcutVisibleInContextMenu == -1 || visible != bool(d->shortcutVisibleInContextMenu)) {
int oldValue = d->shortcutVisibleInContextMenu;
d->shortcutVisibleInContextMenu = visible;
@@ -1206,9 +1335,9 @@ void QGuiAction::setShortcutVisibleInContextMenu(bool visible)
}
}
-bool QGuiAction::isShortcutVisibleInContextMenu() const
+bool QAction::isShortcutVisibleInContextMenu() const
{
- Q_D(const QGuiAction);
+ Q_D(const QAction);
if (d->shortcutVisibleInContextMenu == -1) {
return !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus)
&& QGuiApplication::styleHints()->showShortcutsInContextMenus();
@@ -1217,11 +1346,11 @@ bool QGuiAction::isShortcutVisibleInContextMenu() const
}
#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug d, const QGuiAction *action)
+Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAction *action)
{
QDebugStateSaver saver(d);
d.nospace();
- d << "QGuiAction(" << static_cast<const void *>(action);
+ d << "QAction(" << static_cast<const void *>(action);
if (action) {
d << " text=" << action->text();
if (!action->toolTip().isEmpty())
@@ -1246,4 +1375,4 @@ Q_GUI_EXPORT QDebug operator<<(QDebug d, const QGuiAction *action)
QT_END_NAMESPACE
-#include "moc_qguiaction.cpp"
+#include "moc_qaction.cpp"
diff --git a/src/gui/kernel/qguiaction.h b/src/gui/kernel/qaction.h
index 1306c3cf94..37c6b3a647 100644
--- a/src/gui/kernel/qguiaction.h
+++ b/src/gui/kernel/qaction.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QGUIACTION_H
-#define QGUIACTION_H
+#ifndef QACTION_H
+#define QACTION_H
#include <QtGui/qtguiglobal.h>
#if QT_CONFIG(shortcut)
@@ -53,13 +53,18 @@ QT_REQUIRE_CONFIG(action);
QT_BEGIN_NAMESPACE
class QActionEvent;
-class QGuiActionGroup;
-class QGuiActionPrivate;
+class QActionGroup;
+class QActionPrivate;
+#if QT_DEPRECATED_SINCE(6,0)
+class QWidget;
+class QGraphicsWidget;
+class QMenu;
+#endif
-class Q_GUI_EXPORT QGuiAction : public QObject
+class Q_GUI_EXPORT QAction : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QGuiAction)
+ Q_DECLARE_PRIVATE(QAction)
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
@@ -91,14 +96,56 @@ public:
NormalPriority = 128,
HighPriority = 256};
Q_ENUM(Priority)
- explicit QGuiAction(QObject *parent = nullptr);
- explicit QGuiAction(const QString &text, QObject *parent = nullptr);
- explicit QGuiAction(const QIcon &icon, const QString &text, QObject *parent = nullptr);
-
- ~QGuiAction();
+ explicit QAction(QObject *parent = nullptr);
+ explicit QAction(const QString &text, QObject *parent = nullptr);
+ explicit QAction(const QIcon &icon, const QString &text, QObject *parent = nullptr);
+
+ ~QAction();
+
+ QVector<QObject *> associatedObjects() const;
+
+#if QT_DEPRECATED_SINCE(6,0)
+#ifdef Q_CLANG_QDOC
+ QWidget *parentWidget() const;
+ QList<QWidget*> associatedWidgets() const;
+ QList<QGraphicsWidget*> associatedGraphicsWidgets() const;
+#else
+ /*
+ These are templates so that instantiation happens only in calling code, when
+ QWidget, QMenu, and QGraphicsWidget can be expected to be fully defined.
+ */
+ template<typename T = QWidget*>
+ T parentWidget() const
+ {
+ auto result = parent();
+ while (result && !qobject_cast<T>(result))
+ result = result->parent();
+ return static_cast<T>(result);
+ }
+
+ template<typename T = QWidget*>
+ QList<T> associatedWidgets() const
+ {
+ QList<T> result;
+ for (auto object : associatedObjects())
+ if (auto widget = qobject_cast<T>(object))
+ result.append(widget);
+ return result;
+ }
+ template<typename T = QGraphicsWidget*>
+ QList<T> associatedGraphicsWidgets() const
+ {
+ QList<T> result;
+ for (auto object : associatedObjects())
+ if (auto graphicsWidget = qobject_cast<T>(object))
+ result.append(graphicsWidget);
+ return result;
+ }
+#endif
+#endif
- void setActionGroup(QGuiActionGroup *group);
- QGuiActionGroup *guiActionGroup() const;
+ void setActionGroup(QActionGroup *group);
+ QActionGroup *actionGroup() const;
void setIcon(const QIcon &icon);
QIcon icon() const;
@@ -159,15 +206,35 @@ public:
void setMenuRole(MenuRole menuRole);
MenuRole menuRole() const;
+#if QT_DEPRECATED_SINCE(6,0)
+#ifdef Q_CLANG_QDOC
+ QMenu *menu() const;
+ void setMenu(QMenu *menu);
+#else
+ template<typename T = QMenu*>
+ T menu() const
+ {
+ return qobject_cast<T>(menuObject());
+ }
+ template<typename T = QMenu*>
+ void setMenu(T m)
+ {
+ setMenuObject(m);
+ }
+#endif
+#endif
+
void setIconVisibleInMenu(bool visible);
bool isIconVisibleInMenu() const;
void setShortcutVisibleInContextMenu(bool show);
bool isShortcutVisibleInContextMenu() const;
+ bool showStatusText(QObject *object = nullptr);
+
protected:
bool event(QEvent *) override;
- QGuiAction(QGuiActionPrivate &dd, QObject *parent);
+ QAction(QActionPrivate &dd, QObject *parent);
public Q_SLOTS:
void trigger() { activate(Trigger); }
@@ -188,14 +255,22 @@ Q_SIGNALS:
void toggled(bool);
private:
- Q_DISABLE_COPY(QGuiAction)
- friend class QGuiActionGroup;
+ Q_DISABLE_COPY(QAction)
+ friend class QActionGroup;
+ friend class QWidget;
+ friend class QMenu;
+ friend class QMenuPrivate;
+ friend class QToolButton;
+ friend class QGraphicsWidget;
+
+ QObject *menuObject() const;
+ void setMenuObject(QObject *object);
};
#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug, const QGuiAction *);
+Q_GUI_EXPORT QDebug operator<<(QDebug, const QAction *);
#endif
QT_END_NAMESPACE
-#endif // QGUIACTION_H
+#endif // QACTION_H
diff --git a/src/gui/kernel/qguiaction_p.h b/src/gui/kernel/qaction_p.h
index 08d9708a7e..111cb2958b 100644
--- a/src/gui/kernel/qguiaction_p.h
+++ b/src/gui/kernel/qaction_p.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QGUIACTION_P_H
-#define QGUIACTION_P_H
+#ifndef QACTION_P_H
+#define QACTION_P_H
//
// W A R N I N G
@@ -52,7 +52,7 @@
//
#include <QtGui/private/qtguiglobal_p.h>
-#include <QtGui/qguiaction.h>
+#include <QtGui/qaction.h>
#include <QtGui/qfont.h>
#if QT_CONFIG(shortcut)
# include <QtGui/private/qshortcutmap_p.h>
@@ -65,25 +65,27 @@ QT_BEGIN_NAMESPACE
class QShortcutMap;
-class Q_GUI_EXPORT QGuiActionPrivate : public QObjectPrivate
+class Q_GUI_EXPORT QActionPrivate : public QObjectPrivate
{
- Q_DECLARE_PUBLIC(QGuiAction)
+ Q_DECLARE_PUBLIC(QAction)
public:
- QGuiActionPrivate();
- ~QGuiActionPrivate();
+ QActionPrivate();
+ ~QActionPrivate();
+
+ virtual void destroy();
#if QT_CONFIG(shortcut)
virtual QShortcutMap::ContextMatcher contextMatcher() const;
#endif
- static QGuiActionPrivate *get(QGuiAction *q)
+ static QActionPrivate *get(QAction *q)
{
return q->d_func();
}
bool setEnabled(bool enable, bool byGroup);
- QPointer<QGuiActionGroup> group;
+ QPointer<QActionGroup> group;
QString text;
QString iconText;
QIcon icon;
@@ -95,6 +97,11 @@ public:
QList<QKeySequence> alternateShortcuts;
#endif
QVariant userData;
+
+ QObjectList associatedObjects;
+ virtual QObject *menu() const;
+ virtual void setMenu(QObject *menu);
+
#if QT_CONFIG(shortcut)
int shortcutId = 0;
QVector<int> alternateShortcutIds;
@@ -112,8 +119,8 @@ public:
int iconVisibleInMenu : 2; // Only has values -1, 0, and 1
int shortcutVisibleInContextMenu : 2; // Only has values -1, 0, and 1
- QGuiAction::MenuRole menuRole = QGuiAction::TextHeuristicRole;
- QGuiAction::Priority priority = QGuiAction::NormalPriority;
+ QAction::MenuRole menuRole = QAction::TextHeuristicRole;
+ QAction::Priority priority = QAction::NormalPriority;
#if QT_CONFIG(shortcut)
void redoGrab(QShortcutMap &map);
@@ -121,6 +128,7 @@ public:
void setShortcutEnabled(bool enable, QShortcutMap &map);
#endif // QT_NO_SHORTCUT
+ bool showStatusText(QObject *widget, const QString &str);
void sendDataChanged();
};
diff --git a/src/gui/kernel/qguiactiongroup.cpp b/src/gui/kernel/qactiongroup.cpp
index defa5f15aa..6e2efdb74b 100644
--- a/src/gui/kernel/qguiactiongroup.cpp
+++ b/src/gui/kernel/qactiongroup.cpp
@@ -37,29 +37,29 @@
**
****************************************************************************/
-#include "qguiactiongroup.h"
+#include "qactiongroup.h"
-#include "qguiaction.h"
-#include "qguiaction_p.h"
-#include "qguiactiongroup_p.h"
+#include "qaction.h"
+#include "qaction_p.h"
+#include "qactiongroup_p.h"
#include "qevent.h"
#include "qlist.h"
QT_BEGIN_NAMESPACE
-QGuiActionGroupPrivate::QGuiActionGroupPrivate() :
+QActionGroupPrivate::QActionGroupPrivate() :
enabled(1), visible(1)
{
}
-QGuiActionGroupPrivate::~QGuiActionGroupPrivate() = default;
+QActionGroupPrivate::~QActionGroupPrivate() = default;
-void QGuiActionGroup::_q_actionChanged()
+void QActionGroup::_q_actionChanged()
{
- Q_D(QGuiActionGroup);
- auto action = qobject_cast<QGuiAction*>(sender());
- Q_ASSERT_X(action != nullptr, "QGuiActionGroup::_q_actionChanged", "internal error");
- if (d->exclusionPolicy != QGuiActionGroup::ExclusionPolicy::None) {
+ Q_D(QActionGroup);
+ auto action = qobject_cast<QAction*>(sender());
+ Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionChanged", "internal error");
+ if (d->exclusionPolicy != QActionGroup::ExclusionPolicy::None) {
if (action->isChecked()) {
if (action != d->current) {
if (!d->current.isNull())
@@ -72,44 +72,42 @@ void QGuiActionGroup::_q_actionChanged()
}
}
-void QGuiActionGroup::_q_actionTriggered()
+void QActionGroup::_q_actionTriggered()
{
- Q_D(QGuiActionGroup);
- auto action = qobject_cast<QGuiAction*>(sender());
- Q_ASSERT_X(action != nullptr, "QGuiActionGroup::_q_actionTriggered", "internal error");
- d->emitSignal(QGuiActionGroupPrivate::Triggered, action);
+ auto action = qobject_cast<QAction*>(sender());
+ Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionTriggered", "internal error");
+ emit triggered(action);
}
-void QGuiActionGroup::_q_actionHovered()
+void QActionGroup::_q_actionHovered()
{
- Q_D(QGuiActionGroup);
- auto action = qobject_cast<QGuiAction*>(sender());
- Q_ASSERT_X(action != nullptr, "QGuiActionGroup::_q_actionHovered", "internal error");
- d->emitSignal(QGuiActionGroupPrivate::Hovered, action);
+ auto action = qobject_cast<QAction*>(sender());
+ Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionHovered", "internal error");
+ emit hovered(action);
}
/*!
- \class QGuiActionGroup
- \brief The QGuiActionGroup class groups actions together.
+ \class QActionGroup
+ \brief The QActionGroup class groups actions together.
\since 6.0
\inmodule QtGui
- QGuiActionGroup is a base class for classes grouping
- classes inhheriting QGuiAction objects together.
+ QActionGroup is a base class for classes grouping
+ classes inhheriting QAction objects together.
- In some situations it is useful to group QGuiAction objects together.
+ In some situations it is useful to group QAction objects together.
For example, if you have a \uicontrol{Left Align} action, a \uicontrol{Right
Align} action, a \uicontrol{Justify} action, and a \uicontrol{Center} action,
only one of these actions should be active at any one time. One
simple way of achieving this is to group the actions together in
- an action group, inheriting QGuiActionGroup.
+ an action group, inheriting QActionGroup.
- \sa QGuiAction
+ \sa QAction
*/
/*!
- \enum QGuiActionGroup::ExclusionPolicy
+ \enum QActionGroup::ExclusionPolicy
This enum specifies the different policies that can be used to
control how the group performs exclusive checking on checkable actions.
@@ -134,14 +132,14 @@ void QGuiActionGroup::_q_actionHovered()
The action group is exclusive by default. Call setExclusive(false)
to make the action group non-exclusive. To make the group exclusive
but allow unchecking the active action call instead
- setExclusionPolicy(QGuiActionGroup::ExclusionPolicy::ExclusiveOptional)
+ setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional)
*/
-QGuiActionGroup::QGuiActionGroup(QObject* parent) :
- QGuiActionGroup(*new QGuiActionGroupPrivate, parent)
+QActionGroup::QActionGroup(QObject* parent) :
+ QActionGroup(*new QActionGroupPrivate, parent)
{
}
-QGuiActionGroup::QGuiActionGroup(QGuiActionGroupPrivate &dd, QObject *parent) :
+QActionGroup::QActionGroup(QActionGroupPrivate &dd, QObject *parent) :
QObject(dd, parent)
{
}
@@ -149,26 +147,26 @@ QGuiActionGroup::QGuiActionGroup(QGuiActionGroupPrivate &dd, QObject *parent) :
/*!
Destroys the action group.
*/
-QGuiActionGroup::~QGuiActionGroup() = default;
+QActionGroup::~QActionGroup() = default;
/*!
- \fn QGuiAction *QGuiActionGroup::addAction(QGuiAction *action)
+ \fn QAction *QActionGroup::addAction(QAction *action)
Adds the \a action to this group, and returns it.
Normally an action is added to a group by creating it with the
group as its parent, so this function is not usually used.
- \sa QGuiAction::setActionGroup()
+ \sa QAction::setActionGroup()
*/
-QGuiAction *QGuiActionGroup::addAction(QGuiAction* a)
+QAction *QActionGroup::addAction(QAction* a)
{
- Q_D(QGuiActionGroup);
+ Q_D(QActionGroup);
if (!d->actions.contains(a)) {
d->actions.append(a);
- QObject::connect(a, &QGuiAction::triggered, this, &QGuiActionGroup::_q_actionTriggered);
- QObject::connect(a, &QGuiAction::changed, this, &QGuiActionGroup::_q_actionChanged);
- QObject::connect(a, &QGuiAction::hovered, this, &QGuiActionGroup::_q_actionHovered);
+ QObject::connect(a, &QAction::triggered, this, &QActionGroup::_q_actionTriggered);
+ QObject::connect(a, &QAction::changed, this, &QActionGroup::_q_actionChanged);
+ QObject::connect(a, &QAction::hovered, this, &QActionGroup::_q_actionHovered);
}
a->d_func()->setEnabled(d->enabled, true);
if (!a->d_func()->forceInvisible) {
@@ -177,7 +175,7 @@ QGuiAction *QGuiActionGroup::addAction(QGuiAction* a)
}
if (a->isChecked())
d->current = a;
- QGuiActionGroup *oldGroup = a->d_func()->group;
+ QActionGroup *oldGroup = a->d_func()->group;
if (oldGroup != this) {
if (oldGroup)
oldGroup->removeAction(a);
@@ -188,20 +186,48 @@ QGuiAction *QGuiActionGroup::addAction(QGuiAction* a)
}
/*!
+ Creates and returns an action with \a text. The newly created
+ action is a child of this action group.
+
+ Normally an action is added to a group by creating it with the
+ group as parent, so this function is not usually used.
+
+ \sa QAction::setActionGroup()
+*/
+QAction *QActionGroup::addAction(const QString &text)
+{
+ return new QAction(text, this);
+}
+
+/*!
+ Creates and returns an action with \a text and an \a icon. The
+ newly created action is a child of this action group.
+
+ Normally an action is added to a group by creating it with the
+ group as its parent, so this function is not usually used.
+
+ \sa QAction::setActionGroup()
+*/
+QAction *QActionGroup::addAction(const QIcon &icon, const QString &text)
+{
+ return new QAction(icon, text, this);
+}
+
+/*!
Removes the \a action from this group. The action will have no
parent as a result.
- \sa QGuiAction::setActionGroup()
+ \sa QAction::setActionGroup()
*/
-void QGuiActionGroup::removeAction(QGuiAction *action)
+void QActionGroup::removeAction(QAction *action)
{
- Q_D(QGuiActionGroup);
+ Q_D(QActionGroup);
if (d->actions.removeAll(action)) {
if (action == d->current)
d->current = nullptr;
- QObject::disconnect(action, &QGuiAction::triggered, this, &QGuiActionGroup::_q_actionTriggered);
- QObject::disconnect(action, &QGuiAction::changed, this, &QGuiActionGroup::_q_actionChanged);
- QObject::disconnect(action, &QGuiAction::hovered, this, &QGuiActionGroup::_q_actionHovered);
+ QObject::disconnect(action, &QAction::triggered, this, &QActionGroup::_q_actionTriggered);
+ QObject::disconnect(action, &QAction::changed, this, &QActionGroup::_q_actionChanged);
+ QObject::disconnect(action, &QAction::hovered, this, &QActionGroup::_q_actionHovered);
action->d_func()->group = nullptr;
}
}
@@ -209,9 +235,9 @@ void QGuiActionGroup::removeAction(QGuiAction *action)
/*!
Returns the list of this groups's actions. This may be empty.
*/
-QList<QGuiAction*> QGuiActionGroup::guiActions() const
+QList<QAction*> QActionGroup::actions() const
{
- Q_D(const QGuiActionGroup);
+ Q_D(const QActionGroup);
return d->actions;
}
@@ -222,12 +248,12 @@ QList<QGuiAction*> QGuiActionGroup::guiActions() const
setExclusionPolicy(ExclusionPolicy::Exclusive) when \a b is true,
else setExclusionPolicy(QActionGroup::ExclusionPolicy::None).
- \sa QGuiActionGroup::exclusionPolicy
+ \sa QActionGroup::exclusionPolicy
*/
-void QGuiActionGroup::setExclusive(bool b)
+void QActionGroup::setExclusive(bool b)
{
- setExclusionPolicy(b ? QGuiActionGroup::ExclusionPolicy::Exclusive
- : QGuiActionGroup::ExclusionPolicy::None);
+ setExclusionPolicy(b ? QActionGroup::ExclusionPolicy::Exclusive
+ : QActionGroup::ExclusionPolicy::None);
}
/*!
@@ -237,13 +263,13 @@ void QGuiActionGroup::setExclusive(bool b)
or ExclusionOptional.
*/
-bool QGuiActionGroup::isExclusive() const
+bool QActionGroup::isExclusive() const
{
- return exclusionPolicy() != QGuiActionGroup::ExclusionPolicy::None;
+ return exclusionPolicy() != QActionGroup::ExclusionPolicy::None;
}
/*!
- \property QGuiActionGroup::exclusionPolicy
+ \property QActionGroup::exclusionPolicy
\brief This property holds the group exclusive checking policy
If exclusionPolicy is set to Exclusive, only one checkable
@@ -254,22 +280,22 @@ bool QGuiActionGroup::isExclusive() const
action in the group can be unchecked leaving the group with no actions
checked.
- \sa QGuiAction::checkable
+ \sa QAction::checkable
*/
-void QGuiActionGroup::setExclusionPolicy(QGuiActionGroup::ExclusionPolicy policy)
+void QActionGroup::setExclusionPolicy(QActionGroup::ExclusionPolicy policy)
{
- Q_D(QGuiActionGroup);
+ Q_D(QActionGroup);
d->exclusionPolicy = policy;
}
-QGuiActionGroup::ExclusionPolicy QGuiActionGroup::exclusionPolicy() const
+QActionGroup::ExclusionPolicy QActionGroup::exclusionPolicy() const
{
- Q_D(const QGuiActionGroup);
+ Q_D(const QActionGroup);
return d->exclusionPolicy;
}
/*!
- \fn void QGuiActionGroup::setDisabled(bool b)
+ \fn void QActionGroup::setDisabled(bool b)
This is a convenience function for the \l enabled property, that
is useful for signals--slots connections. If \a b is true the
@@ -277,26 +303,26 @@ QGuiActionGroup::ExclusionPolicy QGuiActionGroup::exclusionPolicy() const
*/
/*!
- \property QGuiActionGroup::enabled
+ \property QActionGroup::enabled
\brief whether the action group is enabled
Each action in the group will be enabled or disabled unless it
has been explicitly disabled.
- \sa QGuiAction::setEnabled()
+ \sa QAction::setEnabled()
*/
-void QGuiActionGroup::setEnabled(bool b)
+void QActionGroup::setEnabled(bool b)
{
- Q_D(QGuiActionGroup);
+ Q_D(QActionGroup);
d->enabled = b;
for (auto action : qAsConst(d->actions)) {
action->d_func()->setEnabled(b, true);
}
}
-bool QGuiActionGroup::isEnabled() const
+bool QActionGroup::isEnabled() const
{
- Q_D(const QGuiActionGroup);
+ Q_D(const QActionGroup);
return d->enabled;
}
@@ -304,24 +330,24 @@ bool QGuiActionGroup::isEnabled() const
Returns the currently checked action in the group, or \nullptr if
none are checked.
*/
-QGuiAction *QGuiActionGroup::checkedGuiAction() const
+QAction *QActionGroup::checkedAction() const
{
- Q_D(const QGuiActionGroup);
+ Q_D(const QActionGroup);
return d->current.data();
}
/*!
- \property QGuiActionGroup::visible
+ \property QActionGroup::visible
\brief whether the action group is visible
Each action in the action group will match the visible state of
this group unless it has been explicitly hidden.
- \sa QGuiAction::setEnabled()
+ \sa QAction::setEnabled()
*/
-void QGuiActionGroup::setVisible(bool b)
+void QActionGroup::setVisible(bool b)
{
- Q_D(QGuiActionGroup);
+ Q_D(QActionGroup);
d->visible = b;
for (auto action : qAsConst(d->actions)) {
if (!action->d_func()->forceInvisible) {
@@ -331,9 +357,9 @@ void QGuiActionGroup::setVisible(bool b)
}
}
-bool QGuiActionGroup::isVisible() const
+bool QActionGroup::isVisible() const
{
- Q_D(const QGuiActionGroup);
+ Q_D(const QActionGroup);
return d->visible;
}
diff --git a/src/gui/kernel/qguiactiongroup.h b/src/gui/kernel/qactiongroup.h
index ef08fb2e04..c485654d08 100644
--- a/src/gui/kernel/qguiactiongroup.h
+++ b/src/gui/kernel/qactiongroup.h
@@ -41,20 +41,20 @@
#define QGUIACTIONGROUP_H
#include <QtGui/qtguiglobal.h>
-#include <QtGui/qguiaction.h>
+#include <QtGui/qaction.h>
QT_REQUIRE_CONFIG(action);
QT_BEGIN_NAMESPACE
-class QGuiActionGroupPrivate;
+class QActionGroupPrivate;
-class Q_GUI_EXPORT QGuiActionGroup : public QObject
+class Q_GUI_EXPORT QActionGroup : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QGuiActionGroup)
+ Q_DECLARE_PRIVATE(QActionGroup)
- Q_PROPERTY(QGuiActionGroup::ExclusionPolicy exclusionPolicy READ exclusionPolicy WRITE setExclusionPolicy)
+ Q_PROPERTY(QActionGroup::ExclusionPolicy exclusionPolicy READ exclusionPolicy WRITE setExclusionPolicy)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
@@ -66,13 +66,15 @@ public:
};
Q_ENUM(ExclusionPolicy)
- explicit QGuiActionGroup(QObject *parent);
- ~QGuiActionGroup();
+ explicit QActionGroup(QObject *parent);
+ ~QActionGroup();
- QGuiAction *addAction(QGuiAction *a);
- void removeAction(QGuiAction *a);
- QList<QGuiAction*> guiActions() const;
- QGuiAction *checkedGuiAction() const;
+ QAction *addAction(QAction *a);
+ QAction *addAction(const QString &text);
+ QAction *addAction(const QIcon &icon, const QString &text);
+ void removeAction(QAction *a);
+ QList<QAction*> actions() const;
+ QAction *checkedAction() const;
bool isExclusive() const;
bool isEnabled() const;
@@ -87,16 +89,20 @@ public Q_SLOTS:
void setExclusive(bool);
void setExclusionPolicy(ExclusionPolicy policy);
+Q_SIGNALS:
+ void triggered(QAction *);
+ void hovered(QAction *);
+
private Q_SLOTS:
void _q_actionTriggered();
void _q_actionHovered();
void _q_actionChanged();
protected:
- QGuiActionGroup(QGuiActionGroupPrivate &dd, QObject *parent);
+ QActionGroup(QActionGroupPrivate &dd, QObject *parent);
private:
- Q_DISABLE_COPY(QGuiActionGroup)
+ Q_DISABLE_COPY(QActionGroup)
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qguiactiongroup_p.h b/src/gui/kernel/qactiongroup_p.h
index 99a58262c9..4b503783ed 100644
--- a/src/gui/kernel/qguiactiongroup_p.h
+++ b/src/gui/kernel/qactiongroup_p.h
@@ -52,7 +52,7 @@
//
#include <QtGui/private/qtguiglobal_p.h>
-#include <QtGui/qguiactiongroup.h>
+#include <QtGui/qactiongroup.h>
#include <QtGui/qfont.h>
#if QT_CONFIG(shortcut)
# include <QtGui/private/qshortcutmap_p.h>
@@ -63,22 +63,22 @@ QT_REQUIRE_CONFIG(action);
QT_BEGIN_NAMESPACE
-class Q_GUI_EXPORT QGuiActionGroupPrivate : public QObjectPrivate
+class Q_GUI_EXPORT QActionGroupPrivate : public QObjectPrivate
{
- Q_DECLARE_PUBLIC(QGuiActionGroup)
+ Q_DECLARE_PUBLIC(QActionGroup)
public:
enum Signal { Triggered, Hovered };
- QGuiActionGroupPrivate();
- ~QGuiActionGroupPrivate();
+ QActionGroupPrivate();
+ ~QActionGroupPrivate();
- virtual void emitSignal(Signal, QGuiAction *) {}
+ virtual void emitSignal(Signal, QAction *) {}
- QList<QGuiAction *> actions;
- QPointer<QGuiAction> current;
+ QList<QAction *> actions;
+ QPointer<QAction> current;
uint enabled : 1;
uint visible : 1;
- QGuiActionGroup::ExclusionPolicy exclusionPolicy = QGuiActionGroup::ExclusionPolicy::Exclusive;
+ QActionGroup::ExclusionPolicy exclusionPolicy = QActionGroup::ExclusionPolicy::Exclusive;
private:
void _q_actionTriggered(); //private slot
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 2f7d5c56c6..8b9fab36c2 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3278,7 +3278,7 @@ QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
/*!
\class QActionEvent
\brief The QActionEvent class provides an event that is generated
- when a QGuiAction is added, removed, or changed.
+ when a QAction is added, removed, or changed.
\ingroup events
\inmodule QtGui
@@ -3289,7 +3289,7 @@ QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
QWidget::actionEvent() to create \l{QToolButton}s for the
actions.
- \sa QGuiAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
+ \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
*/
/*!
@@ -3300,7 +3300,7 @@ QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
type is ActionAdded, the action is to be inserted before the
action \a before. If \a before is \nullptr, the action is appended.
*/
-QActionEvent::QActionEvent(int type, QGuiAction *action, QGuiAction *before)
+QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
: QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before)
{}
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 7d2d6dbdcc..984deb54f5 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -60,7 +60,7 @@
QT_BEGIN_NAMESPACE
class QFile;
-class QGuiAction;
+class QAction;
class QScreen;
class QTouchDevice;
#if QT_CONFIG(gestures)
@@ -728,13 +728,13 @@ private:
#if QT_CONFIG(action)
class Q_GUI_EXPORT QActionEvent : public QEvent
{
- QGuiAction *act, *bef;
+ QAction *act, *bef;
public:
- QActionEvent(int type, QGuiAction *action, QGuiAction *before = nullptr);
+ QActionEvent(int type, QAction *action, QAction *before = nullptr);
~QActionEvent();
- inline QGuiAction *action() const { return act; }
- inline QGuiAction *before() const { return bef; }
+ inline QAction *action() const { return act; }
+ inline QAction *before() const { return bef; }
};
#endif // QT_CONFIG(action)
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index dc2963aee7..80649d067b 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -78,6 +78,9 @@ class QPlatformDragQtResponse;
class QDrag;
#endif // QT_CONFIG(draganddrop)
class QInputDeviceManager;
+#ifndef QT_NO_ACTION
+class QActionPrivate;
+#endif
class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
{
@@ -326,6 +329,10 @@ public:
static void resetCachedDevicePixelRatio();
+#ifndef QT_NO_ACTION
+ virtual QActionPrivate *createActionPrivate() const;
+#endif
+
protected:
virtual void notifyThemeChanged();
diff --git a/src/printsupport/dialogs/qprintpreviewdialog.cpp b/src/printsupport/dialogs/qprintpreviewdialog.cpp
index 39575d5f57..e9f2b5e882 100644
--- a/src/printsupport/dialogs/qprintpreviewdialog.cpp
+++ b/src/printsupport/dialogs/qprintpreviewdialog.cpp
@@ -42,7 +42,8 @@
#include <private/qprinter_p.h>
#include "qprintdialog.h"
-#include <QtWidgets/qaction.h>
+#include <QtGui/qaction.h>
+#include <QtGui/qactiongroup.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qcombobox.h>
#include <QtWidgets/qlineedit.h>
diff --git a/src/tools/uic/qclass_lib_map.h b/src/tools/uic/qclass_lib_map.h
index 1ca431287f..352b4a5d20 100644
--- a/src/tools/uic/qclass_lib_map.h
+++ b/src/tools/uic/qclass_lib_map.h
@@ -656,8 +656,8 @@ QT_CLASS_LIB(QTreeView, QtWidgets, qtreeview.h)
QT_CLASS_LIB(QTreeWidgetItem, QtWidgets, qtreewidget.h)
QT_CLASS_LIB(QTreeWidget, QtWidgets, qtreewidget.h)
QT_CLASS_LIB(QTreeWidgetItemIterator, QtWidgets, qtreewidgetitemiterator.h)
-QT_CLASS_LIB(QAction, QtWidgets, qaction.h)
-QT_CLASS_LIB(QActionGroup, QtWidgets, qactiongroup.h)
+QT_CLASS_LIB(QAction, QtGui, qaction.h)
+QT_CLASS_LIB(QActionGroup, QtGui, qactiongroup.h)
QT_CLASS_LIB(QApplication, QtWidgets, qapplication.h)
QT_CLASS_LIB(QBoxLayout, QtWidgets, qboxlayout.h)
QT_CLASS_LIB(QHBoxLayout, QtWidgets, qboxlayout.h)
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt
index f3c04ac4c7..8fa3090475 100644
--- a/src/widgets/CMakeLists.txt
+++ b/src/widgets/CMakeLists.txt
@@ -323,8 +323,7 @@ qt_extend_target(Widgets CONDITION QT_FEATURE_graphicseffect
qt_extend_target(Widgets CONDITION QT_FEATURE_action
SOURCES
- kernel/qaction.cpp kernel/qaction.h kernel/qaction_p.h
- kernel/qactiongroup.cpp kernel/qactiongroup.h
+ kernel/qaction_widgets.cpp kernel/qaction_widgets_p.h
kernel/qwidgetaction.cpp kernel/qwidgetaction.h kernel/qwidgetaction_p.h
)
diff --git a/src/widgets/accessible/qaccessiblemenu.cpp b/src/widgets/accessible/qaccessiblemenu.cpp
index 99a9444ff1..de5196efb9 100644
--- a/src/widgets/accessible/qaccessiblemenu.cpp
+++ b/src/widgets/accessible/qaccessiblemenu.cpp
@@ -45,7 +45,7 @@
#if QT_CONFIG(menubar)
#include <qmenubar.h>
#endif
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <qstyle.h>
#include <private/qwidget_p.h>
@@ -118,16 +118,19 @@ QAccessibleInterface *QAccessibleMenu::child(int index) const
QAccessibleInterface *QAccessibleMenu::parent() const
{
if (QAction *menuAction = menu()->menuAction()) {
- const QList<QWidget*> parentCandidates =
- QList<QWidget*>() << menu()->parentWidget() << menuAction->associatedWidgets();
- for (QWidget *w : parentCandidates) {
- if (qobject_cast<QMenu*>(w)
+ QVector<QObject*> parentCandidates;
+ const QVector<QObject*> associatedObjects = menuAction->associatedObjects();
+ parentCandidates.reserve(associatedObjects.size() + 1);
+ parentCandidates << menu()->parentWidget() << associatedObjects;
+ for (QObject *object : qAsConst(parentCandidates)) {
+ if (qobject_cast<QMenu*>(object)
#if QT_CONFIG(menubar)
- || qobject_cast<QMenuBar*>(w)
+ || qobject_cast<QMenuBar*>(object)
#endif
) {
- if (w->actions().indexOf(menuAction) != -1)
- return getOrCreateMenu(w, menuAction);
+ QWidget *widget = static_cast<QWidget*>(object);
+ if (widget->actions().indexOf(menuAction) != -1)
+ return getOrCreateMenu(widget, menuAction);
}
}
}
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index e3d4680d6d..ef6178c421 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -48,6 +48,7 @@
#include <private/qguiapplication_p.h>
#include <qfontmetrics.h>
#include <qaction.h>
+#include <qactiongroup.h>
#include <qheaderview.h>
#if QT_CONFIG(shortcut)
# include <qshortcut.h>
diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp
index 472d61d437..713763ad0f 100644
--- a/src/widgets/graphicsview/qgraphicswidget.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget.cpp
@@ -232,9 +232,9 @@ QGraphicsWidget::~QGraphicsWidget()
Q_D(QGraphicsWidget);
#ifndef QT_NO_ACTION
// Remove all actions from this widget
- for (int i = 0; i < d->actions.size(); ++i) {
- QActionPrivate *apriv = d->actions.at(i)->d_func();
- apriv->graphicsWidgets.removeAll(this);
+ for (auto action : qAsConst(d->actions)) {
+ QActionPrivate *apriv = action->d_func();
+ apriv->associatedObjects.removeAll(this);
}
d->actions.clear();
#endif
@@ -2049,7 +2049,7 @@ void QGraphicsWidget::insertAction(QAction *before, QAction *action)
if (index == -1) {
QActionPrivate *apriv = action->d_func();
- apriv->graphicsWidgets.append(this);
+ apriv->associatedObjects.append(this);
}
QActionEvent e(QEvent::ActionAdded, action, before);
@@ -2092,7 +2092,7 @@ void QGraphicsWidget::removeAction(QAction *action)
Q_D(QGraphicsWidget);
QActionPrivate *apriv = action->d_func();
- apriv->graphicsWidgets.removeAll(this);
+ apriv->associatedObjects.removeAll(this);
if (d->actions.removeAll(action)) {
QActionEvent e(QEvent::ActionRemoved, action);
diff --git a/src/widgets/graphicsview/qgraphicswidget.h b/src/widgets/graphicsview/qgraphicswidget.h
index 6c5171cc02..03852d0897 100644
--- a/src/widgets/graphicsview/qgraphicswidget.h
+++ b/src/widgets/graphicsview/qgraphicswidget.h
@@ -43,7 +43,7 @@
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtGui/qfont.h>
#if QT_CONFIG(action)
-# include <QtWidgets/qaction.h>
+# include <QtGui/qaction.h>
#endif
#include <QtWidgets/qgraphicslayoutitem.h>
#include <QtWidgets/qgraphicsitem.h>
diff --git a/src/widgets/kernel/kernel.pri b/src/widgets/kernel/kernel.pri
index a960280959..e73617fd19 100644
--- a/src/widgets/kernel/kernel.pri
+++ b/src/widgets/kernel/kernel.pri
@@ -58,13 +58,10 @@ macx: {
}
qtConfig(action) {
- HEADERS += kernel/qaction.h \
- kernel/qaction_p.h \
- kernel/qactiongroup.h \
+ HEADERS += kernel/qaction_widgets_p.h \
kernel/qwidgetaction.h \
kernel/qwidgetaction_p.h
- SOURCES += kernel/qaction.cpp \
- kernel/qactiongroup.cpp \
+ SOURCES += kernel/qaction_widgets.cpp \
kernel/qwidgetaction.cpp
}
diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp
deleted file mode 100644
index 934fe576d1..0000000000
--- a/src/widgets/kernel/qaction.cpp
+++ /dev/null
@@ -1,354 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets 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$
-**
-****************************************************************************/
-
-#include "qaction.h"
-#include "qactiongroup.h"
-
-#include "qaction_p.h"
-#include "qapplication.h"
-#include "qevent.h"
-#include "qlist.h"
-#include "qstylehints.h"
-#if QT_CONFIG(shortcut)
-# include <private/qshortcutmap_p.h>
-#endif
-#include <private/qguiapplication_p.h>
-#if QT_CONFIG(menu)
-#include <private/qmenu_p.h>
-#endif
-#include <private/qdebug_p.h>
-
-
-QT_BEGIN_NAMESPACE
-
-#if QT_CONFIG(shortcut)
-QShortcutMap::ContextMatcher QActionPrivate::contextMatcher() const
-{
- return qWidgetShortcutContextMatcher;
-}
-#endif // QT_CONFIG(shortcut)
-
-bool QActionPrivate::showStatusText(QWidget *widget, const QString &str)
-{
-#if !QT_CONFIG(statustip)
- Q_UNUSED(widget);
- Q_UNUSED(str);
-#else
- if(QObject *object = widget ? widget : parent) {
- QStatusTipEvent tip(str);
- QCoreApplication::sendEvent(object, &tip);
- return true;
- }
-#endif
- return false;
-}
-
-/*!
- \class QAction
- \brief The QAction class provides an abstract user interface
- action that can be inserted into widgets.
-
- \ingroup mainwindow-classes
- \inmodule QtWidgets
-
- \omit
- * parent and widget are different
- * parent does not define context
- \endomit
-
- In applications many common commands can be invoked via menus,
- toolbar buttons, and keyboard shortcuts. Since the user expects
- each command to be performed in the same way, regardless of the
- user interface used, it is useful to represent each command as
- an \e action.
-
- Actions can be added to menus and toolbars, and will
- automatically keep them in sync. For example, in a word processor,
- if the user presses a Bold toolbar button, the Bold menu item
- will automatically be checked.
-
- Actions can be created as independent objects, but they may
- also be created during the construction of menus; the QMenu class
- contains convenience functions for creating actions suitable for
- use as menu items.
-
- A QAction may contain an icon, menu text, a shortcut, status text,
- "What's This?" text, and a tooltip. Most of these can be set in
- the constructor. They can also be set independently with
- setIcon(), setText(), setIconText(), setShortcut(),
- setStatusTip(), setWhatsThis(), and setToolTip(). For menu items,
- it is possible to set an individual font with setFont().
-
- Actions are added to widgets using QWidget::addAction() or
- QGraphicsWidget::addAction(). Note that an action must be added to a
- widget before it can be used; this is also true when the shortcut should
- be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext).
-
- Once a QAction has been created it should be added to the relevant
- menu and toolbar, then connected to the slot which will perform
- the action. For example:
-
- \snippet mainwindows/application/mainwindow.cpp 19
-
- We recommend that actions are created as children of the window
- they are used in. In most cases actions will be children of
- the application's main window.
-
- \sa QMenu, QToolBar, {Application Example}
-*/
-
-/*!
- \fn void QAction::trigger()
-
- This is a convenience slot that calls activate(Trigger).
-*/
-
-/*!
- \fn void QAction::hover()
-
- This is a convenience slot that calls activate(Hover).
-*/
-
-/*!
- \enum QAction::MenuRole
-
- This enum describes how an action should be moved into the application menu on \macos.
-
- \value NoRole This action should not be put into the application menu
- \value TextHeuristicRole This action should be put in the application menu based on the action's text
- as described in the QMenuBar documentation.
- \value ApplicationSpecificRole This action should be put in the application menu with an application specific role
- \value AboutQtRole This action handles the "About Qt" menu item.
- \value AboutRole This action should be placed where the "About" menu item is in the application menu. The text of
- the menu item will be set to "About <application name>". The application name is fetched from the
- \c{Info.plist} file in the application's bundle (See \l{Qt for macOS - Deployment}).
- \value PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu.
- \value QuitRole This action should be placed where the Quit menu item is in the application menu.
-
- Setting this value only has effect on items that are in the immediate menus
- of the menubar, not the submenus of those menus. For example, if you have
- File menu in your menubar and the File menu has a submenu, setting the
- MenuRole for the actions in that submenu have no effect. They will never be moved.
-*/
-
-/*!
- Constructs an action with \a parent. If \a parent is an action
- group the action will be automatically inserted into the group.
-
- \note The \a parent argument is optional since Qt 5.7.
-*/
-QAction::QAction(QObject* parent)
- : QAction(*new QActionPrivate, parent)
-{
-}
-
-
-/*!
- Constructs an action with some \a text and \a parent. If \a
- parent is an action group the action will be automatically
- inserted into the group.
-
- The action uses a stripped version of \a text (e.g. "\&Menu
- Option..." becomes "Menu Option") as descriptive text for
- tool buttons. You can override this by setting a specific
- description with setText(). The same text will be used for
- tooltips unless you specify a different text using
- setToolTip().
-
-*/
-QAction::QAction(const QString &text, QObject* parent)
- : QAction(parent)
-{
- Q_D(QAction);
- d->text = text;
-}
-
-/*!
- Constructs an action with an \a icon and some \a text and \a
- parent. If \a parent is an action group the action will be
- automatically inserted into the group.
-
- The action uses a stripped version of \a text (e.g. "\&Menu
- Option..." becomes "Menu Option") as descriptive text for
- tool buttons. You can override this by setting a specific
- description with setText(). The same text will be used for
- tooltips unless you specify a different text using
- setToolTip().
-*/
-QAction::QAction(const QIcon &icon, const QString &text, QObject* parent)
- : QAction(text, parent)
-{
- Q_D(QAction);
- d->icon = icon;
-}
-
-/*!
- \internal
-*/
-QAction::QAction(QActionPrivate &dd, QObject *parent)
- : QGuiAction(dd, parent)
-{
-}
-
-/*!
- \reimp
-*/
-
-bool QAction::event(QEvent *e)
-{
- Q_D(QAction);
- if (e->type() == QEvent::ActionChanged) {
- for (auto w : qAsConst(d->widgets))
- QCoreApplication::sendEvent(w, e);
-#if QT_CONFIG(graphicsview)
- for (auto gw : qAsConst(d->graphicsWidgets))
- QCoreApplication::sendEvent(gw, e);
-#endif
- }
- return QGuiAction::event(e);
-}
-
-/*!
- Returns the parent widget.
-*/
-QWidget *QAction::parentWidget() const
-{
- QObject *ret = parent();
- while (ret && !ret->isWidgetType())
- ret = ret->parent();
- return static_cast<QWidget*>(ret);
-}
-
-/*!
- \since 4.2
- Returns a list of widgets this action has been added to.
-
- \sa QWidget::addAction(), associatedGraphicsWidgets()
-*/
-QList<QWidget *> QAction::associatedWidgets() const
-{
- Q_D(const QAction);
- return d->widgets;
-}
-
-#if QT_CONFIG(graphicsview)
-/*!
- \since 4.5
- Returns a list of widgets this action has been added to.
-
- \sa QWidget::addAction(), associatedWidgets()
-*/
-QList<QGraphicsWidget *> QAction::associatedGraphicsWidgets() const
-{
- Q_D(const QAction);
- return d->graphicsWidgets;
-}
-#endif
-
-QAction::~QAction()
-{
- Q_D(QAction);
- for (int i = d->widgets.size()-1; i >= 0; --i) {
- QWidget *w = d->widgets.at(i);
- w->removeAction(this);
- }
-#if QT_CONFIG(graphicsview)
- for (int i = d->graphicsWidgets.size()-1; i >= 0; --i) {
- QGraphicsWidget *w = d->graphicsWidgets.at(i);
- w->removeAction(this);
- }
-#endif
-}
-
-/*!
- Returns the action group for this action. If no action group manages
- this action then \nullptr will be returned.
-
- \sa QActionGroup, QAction::setActionGroup()
- */
-QActionGroup *QAction::actionGroup() const
-{
- return static_cast<QActionGroup *>(guiActionGroup());
-}
-
-#if QT_CONFIG(menu)
-/*!
- Returns the menu contained by this action. Actions that contain
- menus can be used to create menu items with submenus, or inserted
- into toolbars to create buttons with popup menus.
-
- \sa QMenu::addAction()
-*/
-QMenu *QAction::menu() const
-{
- Q_D(const QAction);
- return d->menu;
-}
-
-/*!
- Sets the menu contained by this action to the specified \a menu.
-*/
-void QAction::setMenu(QMenu *menu)
-{
- Q_D(QAction);
- if (d->menu)
- d->menu->d_func()->setOverrideMenuAction(nullptr); //we reset the default action of any previous menu
- d->menu = menu;
- if (menu)
- menu->d_func()->setOverrideMenuAction(this);
- d->sendDataChanged();
-}
-#endif // QT_CONFIG(menu)
-
-/*!
- Updates the relevant status bar for the \a widget specified by sending a
- QStatusTipEvent to its parent widget. Returns \c true if an event was sent;
- otherwise returns \c false.
-
- If a null widget is specified, the event is sent to the action's parent.
-
- \sa statusTip
-*/
-bool
-QAction::showStatusText(QWidget *widget)
-{
- return d_func()->showStatusText(widget, statusTip());
-}
-
-QT_END_NAMESPACE
diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction_widgets.cpp
index 808ee9065d..ff609a66a1 100644
--- a/src/widgets/kernel/qaction.h
+++ b/src/widgets/kernel/qaction_widgets.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -37,76 +37,67 @@
**
****************************************************************************/
-#ifndef QACTION_H
-#define QACTION_H
+#include "qaction.h"
-#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtGui/qguiaction.h>
-#include <QtCore/qstring.h>
-#include <QtWidgets/qwidget.h>
-#include <QtCore/qvariant.h>
+#include <private/qapplication_p.h>
+#include "qaction_widgets_p.h"
+#if QT_CONFIG(menu)
+#include <private/qmenu_p.h>
+#endif
+#if QT_CONFIG(graphicsview)
+#include "qgraphicswidget.h"
+#endif
-QT_REQUIRE_CONFIG(action);
QT_BEGIN_NAMESPACE
-class QMenu;
-class QActionGroup;
-class QActionPrivate;
-class QGraphicsWidget;
-
-class Q_WIDGETS_EXPORT QAction : public QGuiAction
+QActionPrivate *QApplicationPrivate::createActionPrivate() const
{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QAction)
-public:
- QAction(QObject* parent = nullptr);
- QAction(const QString &text, QObject* parent = nullptr);
- QAction(const QIcon &icon, const QString &text, QObject* parent);
- ~QAction();
-
- QActionGroup *actionGroup() const;
-
-#if QT_CONFIG(menu)
- QMenu *menu() const;
- void setMenu(QMenu *menu);
-#endif
-
- bool showStatusText(QWidget *widget = nullptr);
+ return new QtWidgetsActionPrivate;
+}
- QWidget *parentWidget() const;
+QtWidgetsActionPrivate::~QtWidgetsActionPrivate() = default;
- QList<QWidget *> associatedWidgets() const;
+// we can't do this in the destructor, as it would only be called by ~QObject
+void QtWidgetsActionPrivate::destroy()
+{
+ Q_Q(QAction);
+ const auto objects = associatedObjects;
+ for (int i = objects.size()-1; i >= 0; --i) {
+ QObject *object = objects.at(i);
+ if (QWidget *widget = qobject_cast<QWidget*>(object))
+ widget->removeAction(q);
#if QT_CONFIG(graphicsview)
- QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
+ else if (QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget*>(object))
+ graphicsWidget->removeAction(q);
#endif
+ }
+}
-protected:
- QAction(QActionPrivate &dd, QObject *parent);
- bool event(QEvent *) override;
-
-private:
- Q_DISABLE_COPY(QAction)
-
- friend class QGraphicsWidget;
- friend class QWidget;
- friend class QMenu;
- friend class QMenuPrivate;
- friend class QMenuBar;
- friend class QToolButton;
-#ifdef Q_OS_MAC
- friend void qt_mac_clear_status_text(QAction *action);
-#endif
-};
+QShortcutMap::ContextMatcher QtWidgetsActionPrivate::contextMatcher() const
+{
+ return qWidgetShortcutContextMatcher;
+}
-#ifndef QT_NO_DEBUG_STREAM
-Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QAction *);
-#endif
+#if QT_CONFIG(menu)
+QObject *QtWidgetsActionPrivate::menu() const
+{
+ return m_menu;
+}
-QT_BEGIN_INCLUDE_NAMESPACE
-#include <QtWidgets/qactiongroup.h>
-QT_END_INCLUDE_NAMESPACE
+void QtWidgetsActionPrivate::setMenu(QObject *menu)
+{
+ Q_Q(QAction);
+ QMenu *theMenu = qobject_cast<QMenu*>(menu);
+ Q_ASSERT_X(!menu || theMenu, "QAction::setMenu",
+ "QAction::setMenu expects a QMenu* in widget applications");
+ if (m_menu)
+ m_menu->d_func()->setOverrideMenuAction(nullptr); //we reset the default action of any previous menu
+ m_menu = theMenu;
+ if (m_menu)
+ m_menu->d_func()->setOverrideMenuAction(q);
+ sendDataChanged();
+}
+#endif // QT_CONFIG(menu)
QT_END_NAMESPACE
-
-#endif // QACTION_H
diff --git a/src/widgets/kernel/qaction_p.h b/src/widgets/kernel/qaction_widgets_p.h
index b865769372..02387c7371 100644
--- a/src/widgets/kernel/qaction_p.h
+++ b/src/widgets/kernel/qaction_widgets_p.h
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the QtWidgets module of the Qt Toolkit.
+** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QACTION_P_H
-#define QACTION_P_H
+#ifndef QACTION_WIDGETS_P_H
+#define QACTION_WIDGETS_P_H
//
// W A R N I N G
@@ -51,50 +51,34 @@
// We mean it.
//
-#include <QtWidgets/private/qtwidgetsglobal_p.h>
-#include <QtGui/private/qguiaction_p.h>
-#include "QtWidgets/qaction.h"
-#if QT_CONFIG(menu)
-#include "QtWidgets/qmenu.h"
-#endif
-#if QT_CONFIG(graphicsview)
-#include "private/qgraphicswidget_p.h"
-#endif
-#include "private/qobject_p.h"
+#include <QtGui/private/qaction_p.h>
+#include <QtWidgets/qmenu.h>
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_ACTION
+QT_REQUIRE_CONFIG(action);
+QT_BEGIN_NAMESPACE
class QShortcutMap;
-class Q_WIDGETS_EXPORT QActionPrivate : public QGuiActionPrivate
+class Q_WIDGETS_EXPORT QtWidgetsActionPrivate : public QActionPrivate
{
Q_DECLARE_PUBLIC(QAction)
public:
- QActionPrivate() = default;
+ QtWidgetsActionPrivate() = default;
+ ~QtWidgetsActionPrivate();
+
+ void destroy() override;
#if QT_CONFIG(shortcut)
QShortcutMap::ContextMatcher contextMatcher() const override;
#endif
- static QActionPrivate *get(QAction *q)
- {
- return q->d_func();
- }
-
- bool showStatusText(QWidget *w, const QString &str);
+ QPointer<QMenu> m_menu;
- QPointer<QMenu> menu;
- QWidgetList widgets;
-#if QT_CONFIG(graphicsview)
- QList<QGraphicsWidget *> graphicsWidgets;
-#endif
+ QObject *menu() const override;
+ void setMenu(QObject *menu) override;
};
-#endif // QT_NO_ACTION
-
QT_END_NAMESPACE
-#endif // QACTION_P_H
+#endif // QACTION_WIDGETS_P_H
diff --git a/src/widgets/kernel/qactiongroup.cpp b/src/widgets/kernel/qactiongroup.cpp
deleted file mode 100644
index cc900cbb0f..0000000000
--- a/src/widgets/kernel/qactiongroup.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets 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$
-**
-****************************************************************************/
-
-#include "qactiongroup.h"
-#include <QtGui/private/qguiactiongroup_p.h>
-
-#include "qaction.h"
-
-QT_BEGIN_NAMESPACE
-
-class QActionGroupPrivate : public QGuiActionGroupPrivate
-{
- Q_DECLARE_PUBLIC(QActionGroup)
-public:
- void emitSignal(Signal, QGuiAction *) override;
-};
-
-void QActionGroupPrivate::emitSignal(Signal s, QGuiAction *action)
-{
- Q_Q(QActionGroup);
- switch (s) {
- case QGuiActionGroupPrivate::Triggered:
- emit q->triggered(static_cast<QAction *>(action));
- break;
- case QGuiActionGroupPrivate::Hovered:
- emit q->hovered(static_cast<QAction *>(action));
- break;
- }
-}
-
-/*!
- \class QActionGroup
- \brief The QActionGroup class groups actions together.
-
- \ingroup mainwindow-classes
- \inmodule QtWidgets
-
- In some situations it is useful to group QAction objects together.
- For example, if you have a \uicontrol{Left Align} action, a \uicontrol{Right
- Align} action, a \uicontrol{Justify} action, and a \uicontrol{Center} action,
- only one of these actions should be active at any one time. One
- simple way of achieving this is to group the actions together in
- an action group.
-
- Here's a example (from the \l{mainwindows/menus}{Menus} example):
-
- \snippet mainwindows/menus/mainwindow.cpp 6
-
- Here we create a new action group. Since the action group is
- exclusive by default, only one of the actions in the group is
- checked at any one time.
-
- \image qactiongroup-align.png Alignment options in a QMenu
-
- A QActionGroup emits an triggered() signal when one of its
- actions is chosen. Each action in an action group emits its
- triggered() signal as usual.
-
- As stated above, an action group is exclusive by default; it
- ensures that at most only one checkable action is active at any one time.
- If you want to group checkable actions without making them
- exclusive, you can turn off exclusiveness by calling
- setExclusive(false).
-
- By default the active action of an exclusive group cannot be unchecked.
- In some cases it may be useful to allow unchecking all the actions,
- you can allow this by calling
- setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional).
-
- Actions can be added to an action group using addAction(), but it
- is usually more convenient to specify a group when creating
- actions; this ensures that actions are automatically created with
- a parent. Actions can be visually separated from each other by
- adding a separator action to the group; create an action and use
- QAction's \l {QAction::}{setSeparator()} function to make it
- considered a separator. Action groups are added to widgets with
- the QWidget::addActions() function.
-
- \sa QAction
-*/
-
-/*!
- Constructs an action group for the \a parent object.
-
- The action group is exclusive by default. Call setExclusive(false)
- to make the action group non-exclusive. To make the group exclusive
- but allow unchecking the active action call instead
- setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional)
-*/
-QActionGroup::QActionGroup(QObject* parent) :
- QGuiActionGroup(*new QActionGroupPrivate, parent)
-{
-}
-
-/*!
- Destroys the action group.
-*/
-QActionGroup::~QActionGroup() = default;
-
-QAction *QActionGroup::checkedAction() const
-{
- return static_cast<QAction *>(checkedGuiAction());
-}
-
-QAction *QActionGroup::addAction(QAction *a)
-{
- QGuiActionGroup::addAction(a);
- return a;
-}
-
-/*!
- Creates and returns an action with \a text. The newly created
- action is a child of this action group.
-
- Normally an action is added to a group by creating it with the
- group as parent, so this function is not usually used.
-
- \sa QAction::setActionGroup()
-*/
-QAction *QActionGroup::addAction(const QString &text)
-{
- return new QAction(text, this);
-}
-
-/*!
- Creates and returns an action with \a text and an \a icon. The
- newly created action is a child of this action group.
-
- Normally an action is added to a group by creating it with the
- group as its parent, so this function is not usually used.
-
- \sa QAction::setActionGroup()
-*/
-QAction *QActionGroup::addAction(const QIcon &icon, const QString &text)
-{
- return new QAction(icon, text, this);
-}
-
-/*!
- Returns the list of this groups's actions. This may be empty.
-*/
-QList<QAction*> QActionGroup::actions() const
-{
- QList<QAction*> result;
- const auto baseActions = guiActions();
- result.reserve(baseActions.size());
- for (auto baseAction : baseActions)
- result.append(static_cast<QAction*>(baseAction));
- return result;
-}
-
-QT_END_NAMESPACE
diff --git a/src/widgets/kernel/qactiongroup.h b/src/widgets/kernel/qactiongroup.h
deleted file mode 100644
index 0a6a85f093..0000000000
--- a/src/widgets/kernel/qactiongroup.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets 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$
-**
-****************************************************************************/
-
-#ifndef QACTIONGROUP_H
-#define QACTIONGROUP_H
-
-#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtGui/qguiactiongroup.h>
-#include <QtWidgets/qaction.h>
-
-QT_REQUIRE_CONFIG(action);
-
-QT_BEGIN_NAMESPACE
-
-class QActionGroupPrivate;
-
-class Q_WIDGETS_EXPORT QActionGroup : public QGuiActionGroup
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QActionGroup)
-
-public:
- explicit QActionGroup(QObject* parent);
- ~QActionGroup();
-
- QAction *checkedAction() const;
-
- QAction *addAction(QAction *a);
- QAction *addAction(const QString &text);
- QAction *addAction(const QIcon &icon, const QString &text);
-
- QList<QAction*> actions() const;
-
-Q_SIGNALS:
- void triggered(QAction *);
- void hovered(QAction *);
-
-private:
- Q_DISABLE_COPY(QActionGroup)
-};
-
-QT_END_NAMESPACE
-
-#endif // QACTIONGROUP_H
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index a2c2dccbcc..de12347b89 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -90,6 +90,7 @@
#include <private/qthread_p.h>
#include <private/qfont_p.h>
+#include <private/qaction_p.h>
#include <stdlib.h>
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index ab6d85aeb9..f6e3e861d9 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -117,6 +117,10 @@ public:
void notifyWindowIconChanged() override;
+#ifndef QT_NO_ACTION
+ QActionPrivate *createActionPrivate() const override;
+#endif
+
//modality
bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const override;
static bool isBlockedByModal(QWidget *widget);
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp
index 4a2f8d66c2..aad89b6273 100644
--- a/src/widgets/kernel/qshortcut.cpp
+++ b/src/widgets/kernel/qshortcut.cpp
@@ -282,14 +282,14 @@ static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsW
#if QT_CONFIG(action)
static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window)
{
- const QWidgetList &widgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->widgets;
+ const QObjectList associatedObjects = a->associatedObjects();
#if defined(DEBUG_QSHORTCUTMAP)
- if (widgets.isEmpty())
+ if (associatedObjects.isEmpty())
qDebug() << a << "not connected to any widgets; won't trigger";
#endif
- for (auto w : widgets) {
+ for (auto object : associatedObjects) {
#if QT_CONFIG(menu)
- if (auto menu = qobject_cast<QMenu *>(w)) {
+ if (auto menu = qobject_cast<QMenu *>(object)) {
#ifdef Q_OS_DARWIN
// On Mac, menu item shortcuts are processed before reaching any window.
// That means that if a menu action shortcut has not been already processed
@@ -310,21 +310,18 @@ static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidge
return true;
} else
#endif
- if (correctWidgetContext(context, w, active_window))
+ if (auto widget = qobject_cast<QWidget*>(object)) {
+ if (correctWidgetContext(context, widget, active_window))
return true;
- }
-
+ }
#if QT_CONFIG(graphicsview)
- const auto &graphicsWidgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->graphicsWidgets;
-#if defined(DEBUG_QSHORTCUTMAP)
- if (graphicsWidgets.isEmpty())
- qDebug() << a << "not connected to any widgets; won't trigger";
+ else if (auto graphicsWidget = qobject_cast<QGraphicsWidget*>(object)) {
+ if (correctGraphicsWidgetContext(context, graphicsWidget, active_window))
+ return true;
+ }
#endif
- for (auto graphicsWidget : graphicsWidgets) {
- if (correctGraphicsWidgetContext(context, graphicsWidget, active_window))
- return true;
}
-#endif
+
return false;
}
#endif // QT_CONFIG(action)
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 03d6ea31e9..19945473da 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -89,7 +89,7 @@
#include "qwidget_p.h"
#include <QtGui/private/qwindow_p.h>
#if QT_CONFIG(action)
-# include "qaction_p.h"
+# include "QtGui/private/qaction_p.h"
#endif
#include "qlayout_p.h"
#if QT_CONFIG(graphicsview)
@@ -1429,9 +1429,9 @@ QWidget::~QWidget()
#ifndef QT_NO_ACTION
// remove all actions from this widget
- for (int i = 0; i < d->actions.size(); ++i) {
- QActionPrivate *apriv = d->actions.at(i)->d_func();
- apriv->widgets.removeAll(this);
+ for (auto action : qAsConst(d->actions)) {
+ QActionPrivate *apriv = action->d_func();
+ apriv->associatedObjects.removeAll(this);
}
d->actions.clear();
#endif
@@ -3133,7 +3133,7 @@ void QWidget::insertAction(QAction *before, QAction *action)
d->actions.insert(pos, action);
QActionPrivate *apriv = action->d_func();
- apriv->widgets.append(this);
+ apriv->associatedObjects.append(this);
QActionEvent e(QEvent::ActionAdded, action, before);
QCoreApplication::sendEvent(this, &e);
@@ -3170,7 +3170,7 @@ void QWidget::removeAction(QAction *action)
Q_D(QWidget);
QActionPrivate *apriv = action->d_func();
- apriv->widgets.removeAll(this);
+ apriv->associatedObjects.removeAll(this);
if (d->actions.removeAll(action)) {
QActionEvent e(QEvent::ActionRemoved, action);
diff --git a/src/widgets/kernel/qwidgetaction.cpp b/src/widgets/kernel/qwidgetaction.cpp
index 12250983f7..88e71fd800 100644
--- a/src/widgets/kernel/qwidgetaction.cpp
+++ b/src/widgets/kernel/qwidgetaction.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qwidgetaction.h"
+#include "qwidget.h"
#include "qdebug.h"
#include "qwidgetaction_p.h"
diff --git a/src/widgets/kernel/qwidgetaction.h b/src/widgets/kernel/qwidgetaction.h
index 4d302e8c61..e3bfc62ca7 100644
--- a/src/widgets/kernel/qwidgetaction.h
+++ b/src/widgets/kernel/qwidgetaction.h
@@ -41,7 +41,7 @@
#define QWIDGETACTION_H
#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtWidgets/qaction.h>
+#include <QtGui/qaction.h>
QT_REQUIRE_CONFIG(action);
diff --git a/src/widgets/kernel/qwidgetaction_p.h b/src/widgets/kernel/qwidgetaction_p.h
index 0e633a65e4..4b118c45c5 100644
--- a/src/widgets/kernel/qwidgetaction_p.h
+++ b/src/widgets/kernel/qwidgetaction_p.h
@@ -52,13 +52,13 @@
//
#include <QtWidgets/private/qtwidgetsglobal_p.h>
-#include "private/qaction_p.h"
+#include "private/qaction_widgets_p.h"
QT_REQUIRE_CONFIG(action);
QT_BEGIN_NAMESPACE
-class QWidgetActionPrivate : public QActionPrivate
+class QWidgetActionPrivate : public QtWidgetsActionPrivate
{
Q_DECLARE_PUBLIC(QWidgetAction)
public:
diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp
index 356092074c..3d05392a8f 100644
--- a/src/widgets/styles/qstyleoption.cpp
+++ b/src/widgets/styles/qstyleoption.cpp
@@ -1776,7 +1776,7 @@ QStyleOptionMenuItem::QStyleOptionMenuItem(int version)
\value Exclusive The item is an exclusive check item (like a radio button).
\value NonExclusive The item is a non-exclusive check item (like a check box).
- \sa checkType, QGuiAction::checkable, QGuiAction::checked, QGuiActionGroup::exclusionPolicy
+ \sa checkType, QAction::checkable, QAction::checked, QActionGroup::exclusionPolicy
*/
/*!
diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp
index ee52139913..e4ee5770f1 100644
--- a/src/widgets/util/qsystemtrayicon.cpp
+++ b/src/widgets/util/qsystemtrayicon.cpp
@@ -736,6 +736,7 @@ void QSystemTrayIconPrivate::addPlatformMenu(QMenu *menu) const
// be higher than 3 levels.
const auto actions = menu->actions();
for (QAction *action : actions) {
+ QVector<QWidget*> associatedWidgets = action->associatedWidgets();
if (action->menu())
addPlatformMenu(action->menu());
}
diff --git a/src/widgets/util/qundostack_p.h b/src/widgets/util/qundostack_p.h
index c44cdd6603..efe0ceeef8 100644
--- a/src/widgets/util/qundostack_p.h
+++ b/src/widgets/util/qundostack_p.h
@@ -45,7 +45,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qstring.h>
#if QT_CONFIG(action)
-# include <QtWidgets/qaction.h>
+# include <QtGui/qaction.h>
#endif
#include "qundostack.h"
diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp
index 28c4f59d0d..560eeab433 100644
--- a/src/widgets/widgets/qdialogbuttonbox.cpp
+++ b/src/widgets/widgets/qdialogbuttonbox.cpp
@@ -47,7 +47,7 @@
#include <private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformdialoghelper.h>
#include <QtGui/qpa/qplatformtheme.h>
-#include <QtWidgets/qaction.h>
+#include <QtGui/qaction.h>
#include "qdialogbuttonbox.h"
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 29e0ae3b39..b61b46df25 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -548,7 +548,7 @@ void QLineEditPrivate::positionSideWidgets()
}
#if QT_CONFIG(action)
-QLineEditPrivate::SideWidgetLocation QLineEditPrivate::findSideWidget(const QGuiAction *a) const
+QLineEditPrivate::SideWidgetLocation QLineEditPrivate::findSideWidget(const QAction *a) const
{
int i = 0;
for (const auto &e : leadingSideWidgets) {
@@ -635,7 +635,7 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE
return w;
}
-void QLineEditPrivate::removeAction(QGuiAction *action)
+void QLineEditPrivate::removeAction(QAction *action)
{
Q_Q(QLineEdit);
const auto location = findSideWidget(action);
diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h
index 9fe571b4bb..049f7a3bdf 100644
--- a/src/widgets/widgets/qlineedit_p.h
+++ b/src/widgets/widgets/qlineedit_p.h
@@ -240,7 +240,7 @@ public:
#if QT_CONFIG(action)
QWidget *addAction(QAction *newAction, QAction *before, QLineEdit::ActionPosition, int flags = 0);
- void removeAction(QGuiAction *action);
+ void removeAction(QAction *action);
#endif
SideWidgetParameters sideWidgetParameters() const;
QIcon clearButtonIcon() const;
@@ -264,7 +264,7 @@ private:
friend class QTypeInfo<SideWidgetLocation>;
#if QT_CONFIG(action)
- SideWidgetLocation findSideWidget(const QGuiAction *a) const;
+ SideWidgetLocation findSideWidget(const QAction *a) const;
#endif
SideWidgetEntryList leadingSideWidgets;
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 23292062cb..e26f797501 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -41,6 +41,7 @@
#include <QtWidgets/private/qtwidgetsglobal_p.h>
+#include "qactiongroup.h"
#include "qdebug.h"
#include "qstyle.h"
#include "qevent.h"
@@ -198,7 +199,8 @@ void QMenuPrivate::init()
#endif
q->setAttribute(Qt::WA_X11NetWmWindowTypePopupMenu);
defaultMenuAction = menuAction = new QAction(q);
- menuAction->d_func()->menu = q;
+ menuAction->setMenu(q); // this calls setOverrideMenuAction
+ setOverrideMenuAction(nullptr);
QObject::connect(menuAction, &QAction::changed, [this] {
if (!tornPopup.isNull())
tornPopup->updateWindowTitle();
@@ -2244,7 +2246,7 @@ void QMenu::clear()
for(int i = 0; i < acts.size(); i++) {
removeAction(acts[i]);
- if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty())
+ if (acts[i]->parent() == this && acts[i]->d_func()->associatedObjects.isEmpty())
delete acts[i];
}
}
diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h
index 35d5a865ff..6ae73cf9fe 100644
--- a/src/widgets/widgets/qmenu.h
+++ b/src/widgets/widgets/qmenu.h
@@ -44,7 +44,7 @@
#include <QtWidgets/qwidget.h>
#include <QtCore/qstring.h>
#include <QtGui/qicon.h>
-#include <QtWidgets/qaction.h>
+#include <QtGui/qaction.h>
#if defined(Q_OS_MACOS) || defined(Q_CLANG_QDOC)
Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu);
@@ -282,7 +282,7 @@ private:
friend class QMenuBarPrivate;
friend class QTornOffMenu;
friend class QComboBox;
- friend class QAction;
+ friend class QtWidgetsActionPrivate;
friend class QToolButtonPrivate;
friend void qt_mac_emit_menuSignals(QMenu *menu, bool show);
friend void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action);
diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp
index f35c02f2fb..bb376e9613 100644
--- a/src/widgets/widgets/qtoolbar.cpp
+++ b/src/widgets/widgets/qtoolbar.cpp
@@ -1073,11 +1073,12 @@ static bool waitForPopup(QToolBar *tb, QWidget *popup)
if (menu == nullptr)
return false;
- QAction *action = menu->menuAction();
- QList<QWidget*> widgets = action->associatedWidgets();
- for (int i = 0; i < widgets.count(); ++i) {
- if (waitForPopup(tb, widgets.at(i)))
- return true;
+ const QAction *action = menu->menuAction();
+ for (auto object : action->associatedObjects()) {
+ if (QWidget *widget = qobject_cast<QWidget*>(object)) {
+ if (waitForPopup(tb, widget))
+ return true;
+ }
}
return false;
diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h
index 6aaf59cafd..220b30abbe 100644
--- a/src/widgets/widgets/qtoolbar.h
+++ b/src/widgets/widgets/qtoolbar.h
@@ -41,7 +41,7 @@
#define QDYNAMICTOOLBAR_H
#include <QtWidgets/qtwidgetsglobal.h>
-#include <QtWidgets/qaction.h>
+#include <QtGui/qaction.h>
#include <QtWidgets/qwidget.h>
QT_REQUIRE_CONFIG(toolbar);
diff --git a/src/widgets/widgets/qtoolbar_p.h b/src/widgets/widgets/qtoolbar_p.h
index 8cb5850903..e1b786cab7 100644
--- a/src/widgets/widgets/qtoolbar_p.h
+++ b/src/widgets/widgets/qtoolbar_p.h
@@ -53,7 +53,7 @@
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include "qtoolbar.h"
-#include "QtWidgets/qaction.h"
+#include "QtGui/qaction.h"
#include "private/qwidget_p.h"
#include <QtCore/qbasictimer.h>
diff --git a/src/widgets/widgets/qtoolbarlayout.cpp b/src/widgets/widgets/qtoolbarlayout.cpp
index 93aded6876..8ddf27c878 100644
--- a/src/widgets/widgets/qtoolbarlayout.cpp
+++ b/src/widgets/widgets/qtoolbarlayout.cpp
@@ -207,7 +207,7 @@ void QToolBarLayout::insertAction(int index, QAction *action)
}
}
-int QToolBarLayout::indexOf(const QGuiAction *action) const
+int QToolBarLayout::indexOf(const QAction *action) const
{
for (int i = 0; i < items.count(); ++i) {
if (items.at(i)->action == action)
diff --git a/src/widgets/widgets/qtoolbarlayout_p.h b/src/widgets/widgets/qtoolbarlayout_p.h
index 1a406a3d29..13763840e2 100644
--- a/src/widgets/widgets/qtoolbarlayout_p.h
+++ b/src/widgets/widgets/qtoolbarlayout_p.h
@@ -96,7 +96,7 @@ public:
QSize sizeHint() const override;
void insertAction(int index, QAction *action);
- int indexOf(const QGuiAction *action) const;
+ int indexOf(const QAction *action) const;
using QLayout::indexOf; // bring back the hidden members
bool layoutActions(const QSize &size);
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro
index 106e9050b8..3619e31ded 100644
--- a/tests/auto/gui/kernel/kernel.pro
+++ b/tests/auto/gui/kernel/kernel.pro
@@ -1,11 +1,11 @@
TEMPLATE=subdirs
SUBDIRS=\
+ qaction \
+ qactiongroup \
qbackingstore \
qclipboard \
qcursor \
qdrag \
- qguiaction \
- qguiactiongroup \
qevent \
qfileopenevent \
qguieventdispatcher \
@@ -46,8 +46,8 @@ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop
qguieventloop
!qtConfig(action): SUBDIRS -= \
- qguiaction \
- qguiactiongroup
+ qaction \
+ qactiongroup
!qtConfig(highdpiscaling): SUBDIRS -= qhighdpiscaling
diff --git a/tests/auto/gui/kernel/qguiaction/.gitignore b/tests/auto/gui/kernel/qaction/.gitignore
index bf81f5bf2c..bf81f5bf2c 100644
--- a/tests/auto/gui/kernel/qguiaction/.gitignore
+++ b/tests/auto/gui/kernel/qaction/.gitignore
diff --git a/tests/auto/gui/kernel/qaction/CMakeLists.txt b/tests/auto/gui/kernel/qaction/CMakeLists.txt
new file mode 100644
index 0000000000..c14444c123
--- /dev/null
+++ b/tests/auto/gui/kernel/qaction/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Generated from qaction.pro.
+
+#####################################################################
+## tst_qaction Test:
+#####################################################################
+
+add_qt_test(tst_qaction
+ SOURCES
+ tst_qaction.cpp
+ PUBLIC_LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+)
diff --git a/tests/auto/gui/kernel/qguiaction/qguiaction.pro b/tests/auto/gui/kernel/qaction/qaction.pro
index 2a39636119..fae8d826f4 100644
--- a/tests/auto/gui/kernel/qguiaction/qguiaction.pro
+++ b/tests/auto/gui/kernel/qaction/qaction.pro
@@ -1,4 +1,4 @@
CONFIG += testcase
-TARGET = tst_qguiaction
+TARGET = tst_qaction
QT += gui-private core-private testlib
-SOURCES += tst_qguiaction.cpp
+SOURCES += tst_qaction.cpp
diff --git a/tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp b/tests/auto/gui/kernel/qaction/tst_qaction.cpp
index cc607c644f..a34c763021 100644
--- a/tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp
+++ b/tests/auto/gui/kernel/qaction/tst_qaction.cpp
@@ -30,18 +30,18 @@
#include <qguiapplication.h>
#include <qevent.h>
-#include <qguiaction.h>
-#include <qguiactiongroup.h>
+#include <qaction.h>
+#include <qactiongroup.h>
#include <qpa/qplatformtheme.h>
#include <private/qguiapplication_p.h>
-class tst_QGuiAction : public QObject
+class tst_QAction : public QObject
{
Q_OBJECT
public:
- tst_QGuiAction();
+ tst_QAction();
private slots:
void cleanup();
@@ -63,35 +63,33 @@ private:
const int m_keyboardScheme;
};
-tst_QGuiAction::tst_QGuiAction()
+tst_QAction::tst_QAction()
: m_keyboardScheme(QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt())
{
}
-void tst_QGuiAction::cleanup()
+void tst_QAction::cleanup()
{
QVERIFY(QGuiApplication::topLevelWindows().isEmpty());
}
// Testing get/set functions
-void tst_QGuiAction::getSetCheck()
+void tst_QAction::getSetCheck()
{
- QGuiAction obj1(nullptr);
- // QActionGroup * QAction::actionGroup()
- // void QAction::setActionGroup(QActionGroup *)
- auto var1 = new QGuiActionGroup(nullptr);
+ QAction obj1(nullptr);
+ auto var1 = new QActionGroup(nullptr);
obj1.setActionGroup(var1);
- QCOMPARE(var1, obj1.guiActionGroup());
+ QCOMPARE(var1, obj1.actionGroup());
obj1.setActionGroup(nullptr);
- QCOMPARE(obj1.guiActionGroup(), nullptr);
+ QCOMPARE(obj1.actionGroup(), nullptr);
delete var1;
- QCOMPARE(obj1.priority(), QGuiAction::NormalPriority);
- obj1.setPriority(QGuiAction::LowPriority);
- QCOMPARE(obj1.priority(), QGuiAction::LowPriority);
+ QCOMPARE(obj1.priority(), QAction::NormalPriority);
+ obj1.setPriority(QAction::LowPriority);
+ QCOMPARE(obj1.priority(), QAction::LowPriority);
}
-void tst_QGuiAction::setText_data()
+void tst_QAction::setText_data()
{
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("iconText");
@@ -103,11 +101,11 @@ void tst_QGuiAction::setText_data()
QTest::newRow("Mnemonic and ellipsis") << "O&pen File ..." << "Open File" << "Open File";
}
-void tst_QGuiAction::setText()
+void tst_QAction::setText()
{
QFETCH(QString, text);
- QGuiAction action(nullptr);
+ QAction action(nullptr);
action.setText(text);
QCOMPARE(action.text(), text);
@@ -116,11 +114,11 @@ void tst_QGuiAction::setText()
QCOMPARE(action.iconText(), iconText);
}
-void tst_QGuiAction::setIconText()
+void tst_QAction::setIconText()
{
QFETCH(QString, iconText);
- QGuiAction action(nullptr);
+ QAction action(nullptr);
action.setIconText(iconText);
QCOMPARE(action.iconText(), iconText);
@@ -131,9 +129,9 @@ void tst_QGuiAction::setIconText()
#if QT_CONFIG(shortcut)
//basic testing of standard keys
-void tst_QGuiAction::setStandardKeys()
+void tst_QAction::setStandardKeys()
{
- QGuiAction act(nullptr);
+ QAction act(nullptr);
act.setShortcut(QKeySequence("CTRL+L"));
QList<QKeySequence> list;
act.setShortcuts(list);
@@ -158,9 +156,9 @@ void tst_QGuiAction::setStandardKeys()
QCOMPARE(act.shortcuts(), expected);
}
-void tst_QGuiAction::task200823_tooltip()
+void tst_QAction::task200823_tooltip()
{
- const QScopedPointer<QGuiAction> action(new QGuiAction("foo", nullptr));
+ const QScopedPointer<QAction> action(new QAction("foo", nullptr));
QString shortcut("ctrl+o");
action->setShortcut(shortcut);
@@ -173,11 +171,11 @@ void tst_QGuiAction::task200823_tooltip()
#endif // QT_CONFIG(shortcut)
-void tst_QGuiAction::task229128TriggeredSignalWithoutActiongroup()
+void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
{
// test without a group
- const QScopedPointer<QGuiAction> actionWithoutGroup(new QGuiAction("Test", nullptr));
- QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QGuiAction::triggered));
+ const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr));
+ QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QAction::triggered));
QCOMPARE(spyWithoutGroup.count(), 0);
actionWithoutGroup->trigger();
// signal should be emitted
@@ -193,10 +191,10 @@ void tst_QGuiAction::task229128TriggeredSignalWithoutActiongroup()
QCOMPARE(spyWithoutGroup.count(), 1);
}
-void tst_QGuiAction::setData() // QTBUG-62006
+void tst_QAction::setData() // QTBUG-62006
{
- QGuiAction act(nullptr);
- QSignalSpy spy(&act, &QGuiAction::changed);
+ QAction act(nullptr);
+ QSignalSpy spy(&act, &QAction::changed);
QCOMPARE(act.data(), QVariant());
QCOMPARE(spy.count(), 0);
act.setData(QVariant());
@@ -208,10 +206,10 @@ void tst_QGuiAction::setData() // QTBUG-62006
QCOMPARE(spy.count(), 1);
}
-void tst_QGuiAction::setEnabledSetVisible()
+void tst_QAction::setEnabledSetVisible()
{
- QGuiAction action(nullptr);
- QSignalSpy spy(&action, &QGuiAction::enabledChanged);
+ QAction action(nullptr);
+ QSignalSpy spy(&action, &QAction::enabledChanged);
QVERIFY(action.isEnabled());
QVERIFY(action.isVisible());
QCOMPARE(spy.count(), 0);
@@ -232,12 +230,12 @@ void tst_QGuiAction::setEnabledSetVisible()
QCOMPARE(spy.count(), 2);
}
-void tst_QGuiAction::setCheckabledSetChecked()
+void tst_QAction::setCheckabledSetChecked()
{
- QGuiAction action(nullptr);
- QSignalSpy changedSpy(&action, &QGuiAction::changed);
- QSignalSpy checkedSpy(&action, &QGuiAction::toggled);
- QSignalSpy checkableSpy(&action, &QGuiAction::checkableChanged);
+ QAction action(nullptr);
+ QSignalSpy changedSpy(&action, &QAction::changed);
+ QSignalSpy checkedSpy(&action, &QAction::toggled);
+ QSignalSpy checkableSpy(&action, &QAction::checkableChanged);
QVERIFY(!action.isCheckable());
QVERIFY(!action.isChecked());
QCOMPARE(changedSpy.count(), 0);
@@ -273,5 +271,5 @@ void tst_QGuiAction::setCheckabledSetChecked()
QCOMPARE(checkableSpy.count(), 3);
}
-QTEST_MAIN(tst_QGuiAction)
-#include "tst_qguiaction.moc"
+QTEST_MAIN(tst_QAction)
+#include "tst_qaction.moc"
diff --git a/tests/auto/gui/kernel/qguiactiongroup/.gitignore b/tests/auto/gui/kernel/qactiongroup/.gitignore
index daba003e96..daba003e96 100644
--- a/tests/auto/gui/kernel/qguiactiongroup/.gitignore
+++ b/tests/auto/gui/kernel/qactiongroup/.gitignore
diff --git a/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt
new file mode 100644
index 0000000000..6ef659ebc1
--- /dev/null
+++ b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Generated from qactiongroup.pro.
+
+#####################################################################
+## tst_qactiongroup Test:
+#####################################################################
+
+add_qt_test(tst_qactiongroup
+ SOURCES
+ tst_qactiongroup.cpp
+ PUBLIC_LIBRARIES
+ Qt::Gui
+)
diff --git a/tests/auto/gui/kernel/qguiactiongroup/qguiactiongroup.pro b/tests/auto/gui/kernel/qactiongroup/qactiongroup.pro
index 7fd64e70f1..81ceb10429 100644
--- a/tests/auto/gui/kernel/qguiactiongroup/qguiactiongroup.pro
+++ b/tests/auto/gui/kernel/qactiongroup/qactiongroup.pro
@@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qactiongroup
QT += testlib
-SOURCES += tst_qguiactiongroup.cpp
+SOURCES += tst_qactiongroup.cpp
diff --git a/tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp
index 1ac14280fb..c5a3db7b62 100644
--- a/tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp
+++ b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp
@@ -28,10 +28,10 @@
#include <QtTest/QtTest>
-#include <qguiaction.h>
-#include <qguiactiongroup.h>
+#include <qaction.h>
+#include <qactiongroup.h>
-class tst_QGuiActionGroup : public QObject
+class tst_QActionGroup : public QObject
{
Q_OBJECT
@@ -45,13 +45,13 @@ private slots:
void unCheckCurrentAction();
};
-void tst_QGuiActionGroup::enabledPropagation()
+void tst_QActionGroup::enabledPropagation()
{
- QGuiActionGroup testActionGroup(nullptr);
+ QActionGroup testActionGroup(nullptr);
- auto childAction = new QGuiAction( &testActionGroup );
- auto anotherChildAction = new QGuiAction( &testActionGroup );
- auto freeAction = new QGuiAction(nullptr);
+ auto childAction = new QAction( &testActionGroup );
+ auto anotherChildAction = new QAction( &testActionGroup );
+ auto freeAction = new QAction(nullptr);
QVERIFY( testActionGroup.isEnabled() );
QVERIFY( childAction->isEnabled() );
@@ -72,7 +72,7 @@ void tst_QGuiActionGroup::enabledPropagation()
QVERIFY( !anotherChildAction->isEnabled() );
testActionGroup.setEnabled( false );
- auto lastChildAction = new QGuiAction(&testActionGroup);
+ auto lastChildAction = new QAction(&testActionGroup);
QVERIFY(!lastChildAction->isEnabled());
testActionGroup.setEnabled( true );
@@ -84,13 +84,13 @@ void tst_QGuiActionGroup::enabledPropagation()
delete freeAction;
}
-void tst_QGuiActionGroup::visiblePropagation()
+void tst_QActionGroup::visiblePropagation()
{
- QGuiActionGroup testActionGroup(nullptr);
+ QActionGroup testActionGroup(nullptr);
- auto childAction = new QGuiAction( &testActionGroup );
- auto anotherChildAction = new QGuiAction( &testActionGroup );
- auto freeAction = new QGuiAction(nullptr);
+ auto childAction = new QAction( &testActionGroup );
+ auto anotherChildAction = new QAction( &testActionGroup );
+ auto freeAction = new QAction(nullptr);
QVERIFY( testActionGroup.isVisible() );
QVERIFY( childAction->isVisible() );
@@ -109,7 +109,7 @@ void tst_QGuiActionGroup::visiblePropagation()
QVERIFY( !anotherChildAction->isVisible() );
testActionGroup.setVisible( false );
- auto lastChildAction = new QGuiAction(&testActionGroup);
+ auto lastChildAction = new QAction(&testActionGroup);
QVERIFY(!lastChildAction->isVisible());
testActionGroup.setVisible( true );
@@ -121,17 +121,17 @@ void tst_QGuiActionGroup::visiblePropagation()
delete freeAction;
}
-void tst_QGuiActionGroup::exclusive()
+void tst_QActionGroup::exclusive()
{
- QGuiActionGroup group(nullptr);
+ QActionGroup group(nullptr);
group.setExclusive(false);
QVERIFY( !group.isExclusive() );
- auto actOne = new QGuiAction(&group);
+ auto actOne = new QAction(&group);
actOne->setCheckable( true );
- auto actTwo = new QGuiAction(&group);
+ auto actTwo = new QAction(&group);
actTwo->setCheckable( true );
- auto actThree = new QGuiAction(&group);
+ auto actThree = new QAction(&group);
actThree->setCheckable( true );
group.setExclusive( true );
@@ -150,17 +150,17 @@ void tst_QGuiActionGroup::exclusive()
QVERIFY( !actThree->isChecked() );
}
-void tst_QGuiActionGroup::exclusiveOptional()
+void tst_QActionGroup::exclusiveOptional()
{
- QGuiActionGroup group(0);
+ QActionGroup group(0);
group.setExclusive(true);
QVERIFY( group.isExclusive() );
- auto actOne = new QGuiAction(&group);
+ auto actOne = new QAction(&group);
actOne->setCheckable( true );
- auto actTwo = new QGuiAction(&group);
+ auto actTwo = new QAction(&group);
actTwo->setCheckable( true );
- auto actThree = new QGuiAction(&group);
+ auto actThree = new QAction(&group);
actThree->setCheckable( true );
QVERIFY( !actOne->isChecked() );
@@ -177,7 +177,7 @@ void tst_QGuiActionGroup::exclusiveOptional()
QVERIFY( !actTwo->isChecked() );
QVERIFY( !actThree->isChecked() );
- group.setExclusionPolicy(QGuiActionGroup::ExclusionPolicy::ExclusiveOptional);
+ group.setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional);
QVERIFY( group.isExclusive() );
actOne->trigger();
@@ -196,25 +196,25 @@ void tst_QGuiActionGroup::exclusiveOptional()
QVERIFY( !actThree->isChecked() );
}
-void tst_QGuiActionGroup::testActionInTwoQActionGroup()
+void tst_QActionGroup::testActionInTwoQActionGroup()
{
- QGuiAction action1("Action 1", this);
+ QAction action1("Action 1", this);
- QGuiActionGroup group1(this);
- QGuiActionGroup group2(this);
+ QActionGroup group1(this);
+ QActionGroup group2(this);
group1.addAction(&action1);
group2.addAction(&action1);
- QCOMPARE(action1.guiActionGroup(), &group2);
- QCOMPARE(group2.guiActions().constFirst(), &action1);
- QCOMPARE(group1.guiActions().isEmpty(), true);
+ QCOMPARE(action1.actionGroup(), &group2);
+ QCOMPARE(group2.actions().constFirst(), &action1);
+ QCOMPARE(group1.actions().isEmpty(), true);
}
-void tst_QGuiActionGroup::unCheckCurrentAction()
+void tst_QActionGroup::unCheckCurrentAction()
{
- QGuiActionGroup group(nullptr);
- QGuiAction action1(&group) ,action2(&group);
+ QActionGroup group(nullptr);
+ QAction action1(&group) ,action2(&group);
action1.setCheckable(true);
action2.setCheckable(true);
QVERIFY(!action1.isChecked());
@@ -222,14 +222,14 @@ void tst_QGuiActionGroup::unCheckCurrentAction()
action1.setChecked(true);
QVERIFY(action1.isChecked());
QVERIFY(!action2.isChecked());
- auto current = group.checkedGuiAction();
+ auto current = group.checkedAction();
QCOMPARE(current, &action1);
current->setChecked(false);
QVERIFY(!action1.isChecked());
QVERIFY(!action2.isChecked());
- QVERIFY(!group.checkedGuiAction());
+ QVERIFY(!group.checkedAction());
}
-QTEST_MAIN(tst_QGuiActionGroup)
-#include "tst_qguiactiongroup.moc"
+QTEST_MAIN(tst_QActionGroup)
+#include "tst_qactiongroup.moc"
diff --git a/tests/auto/tools/uic/baseline/browserwidget.ui.h b/tests/auto/tools/uic/baseline/browserwidget.ui.h
index 7dcfb290f7..07142c5ea1 100644
--- a/tests/auto/tools/uic/baseline/browserwidget.ui.h
+++ b/tests/auto/tools/uic/baseline/browserwidget.ui.h
@@ -10,7 +10,7 @@
#define BROWSERWIDGET_H
#include <QtCore/QVariant>
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
diff --git a/tests/auto/tools/uic/baseline/chatmainwindow.ui.h b/tests/auto/tools/uic/baseline/chatmainwindow.ui.h
index 220d44300b..43f83059d4 100644
--- a/tests/auto/tools/uic/baseline/chatmainwindow.ui.h
+++ b/tests/auto/tools/uic/baseline/chatmainwindow.ui.h
@@ -10,7 +10,7 @@
#define CHATMAINWINDOW_H
#include <QtCore/QVariant>
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
diff --git a/tests/auto/tools/uic/baseline/default.ui.h b/tests/auto/tools/uic/baseline/default.ui.h
index fbbe81d0b8..bc9ad75858 100644
--- a/tests/auto/tools/uic/baseline/default.ui.h
+++ b/tests/auto/tools/uic/baseline/default.ui.h
@@ -10,7 +10,7 @@
#define DEFAULT_H
#include <QtCore/QVariant>
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
diff --git a/tests/auto/tools/uic/baseline/mainwindow.ui.h b/tests/auto/tools/uic/baseline/mainwindow.ui.h
index df61d57ceb..1f375dd313 100644
--- a/tests/auto/tools/uic/baseline/mainwindow.ui.h
+++ b/tests/auto/tools/uic/baseline/mainwindow.ui.h
@@ -10,7 +10,7 @@
#define MAINWINDOW_H
#include <QtCore/QVariant>
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
diff --git a/tests/auto/tools/uic/baseline/pagefold.ui.h b/tests/auto/tools/uic/baseline/pagefold.ui.h
index a0594b7ec7..cc5f96982b 100644
--- a/tests/auto/tools/uic/baseline/pagefold.ui.h
+++ b/tests/auto/tools/uic/baseline/pagefold.ui.h
@@ -10,7 +10,7 @@
#define PAGEFOLD_H
#include <QtCore/QVariant>
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
diff --git a/tests/auto/tools/uic/baseline/qttrid.ui.h b/tests/auto/tools/uic/baseline/qttrid.ui.h
index 890ffc7789..cb5a4cb2e8 100644
--- a/tests/auto/tools/uic/baseline/qttrid.ui.h
+++ b/tests/auto/tools/uic/baseline/qttrid.ui.h
@@ -10,8 +10,8 @@
#define QTTRID_H
#include <QtCore/QVariant>
+#include <QtGui/QAction>
#include <QtGui/QIcon>
-#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGridLayout>
diff --git a/tests/auto/tools/uic/baseline/remotecontrol.ui.h b/tests/auto/tools/uic/baseline/remotecontrol.ui.h
index 5b7c6c42c2..c5b72be860 100644
--- a/tests/auto/tools/uic/baseline/remotecontrol.ui.h
+++ b/tests/auto/tools/uic/baseline/remotecontrol.ui.h
@@ -10,8 +10,8 @@
#define REMOTECONTROL_H
#include <QtCore/QVariant>
+#include <QtGui/QAction>
#include <QtGui/QIcon>
-#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGridLayout>
diff --git a/tests/auto/tools/uic/baseline/trpreviewtool.ui.h b/tests/auto/tools/uic/baseline/trpreviewtool.ui.h
index 612d7ad427..3e1e7afbd3 100644
--- a/tests/auto/tools/uic/baseline/trpreviewtool.ui.h
+++ b/tests/auto/tools/uic/baseline/trpreviewtool.ui.h
@@ -40,7 +40,7 @@
#define TRPREVIEWTOOL_H
#include <QtCore/QVariant>
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDockWidget>
#include <QtWidgets/QListView>
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
index cf8539da68..b4c259a1ef 100644
--- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
+++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
@@ -33,6 +33,7 @@
#include <qapplication.h>
#include <qevent.h>
#include <qaction.h>
+#include <qactiongroup.h>
#include <qmenu.h>
#include <qpa/qplatformtheme.h>
#include <qpa/qplatformintegration.h>
@@ -68,7 +69,7 @@ private slots:
private:
QEvent::Type m_lastEventType;
const int m_keyboardScheme;
- QGuiAction *m_lastAction;
+ QAction *m_lastAction;
};
tst_QAction::tst_QAction()
diff --git a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp
index d3b07ba26a..539ff9c67f 100644
--- a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp
+++ b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp
@@ -31,6 +31,7 @@
#include <qmainwindow.h>
#include <qmenu.h>
#include <qaction.h>
+#include <qactiongroup.h>
class tst_QActionGroup : public QObject
{
diff --git a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
index 6a2c8893d2..58a90dd572 100644
--- a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
+++ b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
@@ -30,7 +30,7 @@
#include <QtWidgets/QStyle>
#include <QtWidgets/QLayout>
#include <QtWidgets/QDialog>
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <qdialogbuttonbox.h>
#include <limits.h>
diff --git a/tests/manual/cocoa/menurama/main.cpp b/tests/manual/cocoa/menurama/main.cpp
index e39c01ea4d..4da4511884 100644
--- a/tests/manual/cocoa/menurama/main.cpp
+++ b/tests/manual/cocoa/menurama/main.cpp
@@ -29,7 +29,7 @@
#include "mainwindow.h"
#include "menuramaapplication.h"
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QMenu>
int main(int argc, char *argv[])
diff --git a/tests/manual/foreignwindows/main.cpp b/tests/manual/foreignwindows/main.cpp
index 5e882b6d9c..843f4e39ef 100644
--- a/tests/manual/foreignwindows/main.cpp
+++ b/tests/manual/foreignwindows/main.cpp
@@ -26,7 +26,7 @@
**
****************************************************************************/
-#include <QtWidgets/QAction>
+#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QMainWindow>