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>
This commit is contained in:
Volker Hilsheimer 2020-03-18 17:02:11 +01:00
parent e3d0184065
commit bcaff2b06f
72 changed files with 861 additions and 1220 deletions

View File

@ -50,7 +50,7 @@
#include "colorswatch.h"
#include <QAction>
#include <QActionGroup>
#include <QtEvents>
#include <QFrame>
#include <QMainWindow>

View File

@ -52,7 +52,7 @@
#include "colorswatch.h"
#include "toolbar.h"
#include <QAction>
#include <QActionGroup>
#include <QLayout>
#include <QMenu>
#include <QMenuBar>

View File

@ -52,6 +52,7 @@
#include <QRandomGenerator>
#include <QActionGroup>
#include <QMainWindow>
#include <QMenu>
#include <QPainter>

View File

@ -48,7 +48,7 @@
**
****************************************************************************/
#include <QAction>
#include <QActionGroup>
#include <QApplication>
#include <QClipboard>
#include <QColorDialog>

View File

@ -53,6 +53,7 @@
#include "iconsizespinbox.h"
#include "imagedelegate.h"
#include <QActionGroup>
#include <QApplication>
#include <QButtonGroup>
#include <QCheckBox>

View File

@ -51,6 +51,7 @@
#include "mainwindow.h"
#include "tabletcanvas.h"
#include <QActionGroup>
#include <QApplication>
#include <QColorDialog>
#include <QDir>

View File

@ -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

View File

@ -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) {

File diff suppressed because it is too large Load Diff

View File

@ -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);
explicit QAction(QObject *parent = nullptr);
explicit QAction(const QString &text, QObject *parent = nullptr);
explicit QAction(const QIcon &icon, const QString &text, QObject *parent = nullptr);
~QGuiAction();
~QAction();
void setActionGroup(QGuiActionGroup *group);
QGuiActionGroup *guiActionGroup() const;
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(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

View File

@ -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();
};

View File

@ -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);
@ -187,21 +185,49 @@ QGuiAction *QGuiActionGroup::addAction(QGuiAction* 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);
}
/*!
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;
}

View File

@ -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

View File

@ -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

View File

@ -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)
{}

View File

@ -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)

View File

@ -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();

View File

@ -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>

View File

@ -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)

View File

@ -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
)

View File

@ -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);
}
}
}

View File

@ -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>

View File

@ -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);

View File

@ -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>

View File

@ -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
}

View File

@ -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

View File

@ -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();
return new QtWidgetsActionPrivate;
}
QActionGroup *actionGroup() const;
QtWidgetsActionPrivate::~QtWidgetsActionPrivate() = default;
// 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)
else if (QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget*>(object))
graphicsWidget->removeAction(q);
#endif
}
}
QShortcutMap::ContextMatcher QtWidgetsActionPrivate::contextMatcher() const
{
return qWidgetShortcutContextMatcher;
}
#if QT_CONFIG(menu)
QMenu *menu() const;
void setMenu(QMenu *menu);
#endif
QObject *QtWidgetsActionPrivate::menu() const
{
return m_menu;
}
bool showStatusText(QWidget *widget = nullptr);
QWidget *parentWidget() const;
QList<QWidget *> associatedWidgets() const;
#if QT_CONFIG(graphicsview)
QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
#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
};
#ifndef QT_NO_DEBUG_STREAM
Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QAction *);
#endif
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

View File

@ -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_REQUIRE_CONFIG(action);
QT_BEGIN_NAMESPACE
#ifndef QT_NO_ACTION
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();
}
QPointer<QMenu> m_menu;
bool showStatusText(QWidget *w, const QString &str);
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

View File

@ -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

View File

@ -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

View File

@ -90,6 +90,7 @@
#include <private/qthread_p.h>
#include <private/qfont_p.h>
#include <private/qaction_p.h>
#include <stdlib.h>

View File

@ -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);

View File

@ -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)
else if (auto graphicsWidget = qobject_cast<QGraphicsWidget*>(object)) {
if (correctGraphicsWidgetContext(context, graphicsWidget, active_window))
return true;
}
#endif
}
#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";
#endif
for (auto graphicsWidget : graphicsWidgets) {
if (correctGraphicsWidgetContext(context, graphicsWidget, active_window))
return true;
}
#endif
return false;
}
#endif // QT_CONFIG(action)

View File

@ -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);

View File

@ -38,6 +38,7 @@
****************************************************************************/
#include "qwidgetaction.h"
#include "qwidget.h"
#include "qdebug.h"
#include "qwidgetaction_p.h"

View File

@ -41,7 +41,7 @@
#define QWIDGETACTION_H
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtWidgets/qaction.h>
#include <QtGui/qaction.h>
QT_REQUIRE_CONFIG(action);

View File

@ -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:

View File

@ -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
*/
/*!

View File

@ -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());
}

View File

@ -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"

View File

@ -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"

View File

@ -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);

View File

@ -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;

View File

@ -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];
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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>

View File

@ -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)

View File

@ -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);

View File

@ -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

View File

@ -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
)

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1,12 @@
# Generated from qactiongroup.pro.
#####################################################################
## tst_qactiongroup Test:
#####################################################################
add_qt_test(tst_qactiongroup
SOURCES
tst_qactiongroup.cpp
PUBLIC_LIBRARIES
Qt::Gui
)

View File

@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qactiongroup
QT += testlib
SOURCES += tst_qguiactiongroup.cpp
SOURCES += tst_qactiongroup.cpp

View File

@ -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"

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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()

View File

@ -31,6 +31,7 @@
#include <qmainwindow.h>
#include <qmenu.h>
#include <qaction.h>
#include <qactiongroup.h>
class tst_QActionGroup : public QObject
{

View File

@ -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>

View File

@ -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[])

View File

@ -26,7 +26,7 @@
**
****************************************************************************/
#include <QtWidgets/QAction>
#include <QtGui/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QMainWindow>