summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qshortcut.cpp
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/qshortcut.cpp
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/qshortcut.cpp')
-rw-r--r--src/widgets/kernel/qshortcut.cpp27
1 files changed, 12 insertions, 15 deletions
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)