Skip to content

Commit

Permalink
QShortcutMap: print ambiguous shortcuts when DEBUG_QSHORTCUTMAP is de…
Browse files Browse the repository at this point in the history
…fined

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 <[email protected]>
  • Loading branch information
mitchcurtis committed May 7, 2018
1 parent 64836ec commit f72777b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/gui/kernel/qshortcutmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const QShortcutEntry*> 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;
Expand All @@ -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 << ", "
Expand Down

0 comments on commit f72777b

Please sign in to comment.