From 2cd7e34fa09c034f8a538b94299c275599620745 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 26 Apr 2023 16:25:26 +0800 Subject: [PATCH] Add more shortcutmap categorized logging output Show more detail about the checks made against each entry to show why a shortcut might not get delivered. Specifically, it's useful to know if the contextMatcher returned true. In the case of Qt Quick Controls, it can return false if the Shortcut is blocked by a modal popup, or a popup with a CloseOnEscape policy. With this patch, combining qt.gui.shortcutmap with qt.quick.controls.shortcutcontext.matcher makes it possible to see which popup blocks a shortcut. With only the former enabled, it's already quite useful: qt.gui.shortcutmap: Possible shortcut key sequences: QList(QKeySequence("Ctrl+N")) qt.gui.shortcutmap: - checking entry 0 QKeySequence("Ctrl+N") qt.gui.shortcutmap: - matches returned 2 for QKeySequence("Ctrl+N") QKeySequence("Ctrl+N") - correctContext()? false qt.gui.shortcutmap: - matches returned 0 for QKeySequence("Ctrl+N") QKeySequence("Ctrl+O") - correctContext()? false qt.gui.shortcutmap: Found better match ( QList(QKeySequence("Ctrl+N")) ), clearing key sequence list qt.gui.shortcutmap: Added ok key sequence QList(QKeySequence("Ctrl+N")) qt.gui.shortcutmap: Returning shortcut match == 0 qt.gui.shortcutmap: QShortcutMap::nextState(QKeyEvent(ShortcutOverride, Key_N, ControlModifier, text="N")) = 0 Change-Id: I6e96c94a8b62823553837eda3ef2764ca21775c4 Reviewed-by: Friedemann Kleint Reviewed-by: Volker Hilsheimer --- src/gui/kernel/qshortcutmap.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index ed03f00542..1849419372 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -410,6 +410,7 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier int result = QKeySequence::NoMatch; for (int i = d->newEntries.size()-1; i >= 0 ; --i) { QShortcutEntry entry(d->newEntries.at(i)); // needed for searching + qCDebug(lcShortcutMap) << "- checking entry" << entry.id << entry.keyseq; const auto itEnd = d->sequences.constEnd(); auto it = std::lower_bound(d->sequences.constBegin(), itEnd, entry); @@ -420,6 +421,8 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier break; tempRes = matches(entry.keyseq, (*it).keyseq); oneKSResult = qMax(oneKSResult, tempRes); + qCDebug(lcShortcutMap) << " - matches returned" << tempRes << "for" << entry.keyseq << it->keyseq + << "- correctContext()?" << it->correctContext(); if (tempRes != QKeySequence::NoMatch && (*it).correctContext()) { if (tempRes == QKeySequence::ExactMatch) { if ((*it).enabled)