summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
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 /src/widgets/kernel
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>
Diffstat (limited to 'src/widgets/kernel')
-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
13 files changed, 96 insertions, 743 deletions
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: