From f72777b969bd74a1472ce8f028da01a82200d656 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Sat, 5 May 2018 14:56:15 +0200 Subject: [PATCH] QShortcutMap: print ambiguous shortcuts when DEBUG_QSHORTCUTMAP is defined This is useful to see why shortcuts (in Qt Widgets and Qt Quick) are not behaving as expected. For example: The following shortcuts are about to be activated ambiguously: - QKeySequence("Esc") (belonging to QQuickShortcut(0x7fcd4c8e6a70, name = "exploreViewBackOrCloseShortcut")) - QKeySequence("Esc") (belonging to QQuickPopupItem(0x7fcd4c8e5110)) Change-Id: Id20a3017d69cfe417c2286dccf46b3d5ff0b31b2 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qshortcutmap.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index 6c19eab287..fa1eb6f6bf 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -648,10 +648,16 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e) // Find next const QShortcutEntry *current = 0, *next = 0; int i = 0, enabledShortcuts = 0; +#if defined(DEBUG_QSHORTCUTMAP) + QVector ambiguousShortcuts; +#endif while(i < d->identicals.size()) { current = d->identicals.at(i); if (current->enabled || !next){ ++enabledShortcuts; +#if defined(DEBUG_QSHORTCUTMAP) + ambiguousShortcuts.append(current); +#endif if (enabledShortcuts > d->ambigCount + 1) break; next = current; @@ -665,6 +671,13 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e) return; // Dispatch next enabled #if defined(DEBUG_QSHORTCUTMAP) + if (ambiguousShortcuts.size() > 1) { + qDebug() << "The following shortcuts are about to be activated ambiguously:"; + for (const QShortcutEntry *entry : qAsConst(ambiguousShortcuts)) { + qDebug().nospace() << "- " << entry->keyseq << " (belonging to " << entry->owner << ")"; + } + } + qDebug().nospace() << "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\"" << next->keyseq.toString() << "\", " << next->id << ", "