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 <Friedemann.Kleint@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Mitch Curtis 2023-04-26 16:25:26 +08:00
parent 4ff074a67e
commit 2cd7e34fa0

View File

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