Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qaction_widgets.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qaction.h"
5
6#include <private/qapplication_p.h>
7#include <private/qwidget_p.h>
8#include "qaction_widgets_p.h"
9#if QT_CONFIG(menu)
10#include <private/qmenu_p.h>
11#endif
12#if QT_CONFIG(graphicsview)
13#include "qgraphicswidget.h"
14#endif
15
16
18
23
25
26// we can't do this in the destructor, as it would only be called by ~QObject
28{
29 Q_Q(QAction);
30 const auto objects = associatedObjects;
31 const auto end = objects.crend();
32 for (auto it = objects.crbegin(); it != end; ++it) {
33 QObject *object = *it;
34 if (QWidget *widget = qobject_cast<QWidget*>(object))
36#if QT_CONFIG(graphicsview)
37 else if (QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget*>(object))
38 graphicsWidget->removeAction(q);
39#endif
40 }
41}
42
43#if QT_CONFIG(shortcut)
44QShortcutMap::ContextMatcher QtWidgetsActionPrivate::contextMatcher() const
45{
47}
48#endif
49
50#if QT_CONFIG(menu)
52{
53 return m_menu;
54}
55
57{
58 Q_Q(QAction);
59 QMenu *theMenu = qobject_cast<QMenu*>(menu);
60 Q_ASSERT_X(!menu || theMenu, "QAction::setMenu",
61 "QAction::setMenu expects a QMenu* in widget applications");
62 if (m_menu)
63 m_menu->d_func()->setOverrideMenuAction(nullptr); //we reset the default action of any previous menu
64 m_menu = theMenu;
65 if (m_menu)
66 m_menu->d_func()->setOverrideMenuAction(q);
68}
69#endif // QT_CONFIG(menu)
70
virtual void setMenu(QObject *menu)
Definition qaction.cpp:130
virtual QObject * menu() const
Definition qaction.cpp:134
void sendDataChanged()
Definition qaction.cpp:71
QObjectList associatedObjects
Definition qaction_p.h:67
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
QActionPrivate * createActionPrivate() const override
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
const_reverse_iterator crend() const noexcept
Definition qlist.h:639
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtCore
Definition qobject.h:103
bool(* ContextMatcher)(QObject *object, Qt::ShortcutContext context)
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3186
QOpenGLWidget * widget
[1]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
QMenu menu
[5]