Improve QShortcutMap debug output
Replace the macro with a logging category so that it's not necessary to patch Qt to get output about e.g. ambiguous shortcuts. Change-Id: I4d365aac5a5c0da8629447d93d3bc90c9c3076c2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
20891777bb
commit
fc5dc8c16a
@ -45,6 +45,7 @@
|
|||||||
#include "qvector.h"
|
#include "qvector.h"
|
||||||
#include "qcoreapplication.h"
|
#include "qcoreapplication.h"
|
||||||
#include <private/qkeymapper_p.h>
|
#include <private/qkeymapper_p.h>
|
||||||
|
#include <QtCore/qloggingcategory.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -52,8 +53,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
// To enable verbose output uncomment below
|
Q_LOGGING_CATEGORY(lcShortcutMap, "qt.gui.shortcutmap")
|
||||||
//#define DEBUG_QSHORTCUTMAP
|
|
||||||
|
|
||||||
/* \internal
|
/* \internal
|
||||||
Entry data for QShortcutMap
|
Entry data for QShortcutMap
|
||||||
@ -165,11 +165,9 @@ int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::Short
|
|||||||
QShortcutEntry newEntry(owner, key, context, --(d->currentId), true, matcher);
|
QShortcutEntry newEntry(owner, key, context, --(d->currentId), true, matcher);
|
||||||
const auto it = std::upper_bound(d->sequences.begin(), d->sequences.end(), newEntry);
|
const auto it = std::upper_bound(d->sequences.begin(), d->sequences.end(), newEntry);
|
||||||
d->sequences.insert(it, newEntry); // Insert sorted
|
d->sequences.insert(it, newEntry); // Insert sorted
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap).nospace()
|
||||||
qDebug().nospace()
|
|
||||||
<< "QShortcutMap::addShortcut(" << owner << ", "
|
<< "QShortcutMap::addShortcut(" << owner << ", "
|
||||||
<< key << ", " << context << ") = " << d->currentId;
|
<< key << ", " << context << ") = " << d->currentId;
|
||||||
#endif
|
|
||||||
return d->currentId;
|
return d->currentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,11 +210,9 @@ int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key
|
|||||||
return itemsRemoved;
|
return itemsRemoved;
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap).nospace()
|
||||||
qDebug().nospace()
|
|
||||||
<< "QShortcutMap::removeShortcut(" << id << ", " << owner << ", "
|
<< "QShortcutMap::removeShortcut(" << id << ", " << owner << ", "
|
||||||
<< key << ") = " << itemsRemoved;
|
<< key << ") = " << itemsRemoved;
|
||||||
#endif
|
|
||||||
return itemsRemoved;
|
return itemsRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,11 +246,9 @@ int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const
|
|||||||
return itemsChanged;
|
return itemsChanged;
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap).nospace()
|
||||||
qDebug().nospace()
|
|
||||||
<< "QShortcutMap::setShortcutEnabled(" << enable << ", " << id << ", "
|
<< "QShortcutMap::setShortcutEnabled(" << enable << ", " << id << ", "
|
||||||
<< owner << ", " << key << ") = " << itemsChanged;
|
<< owner << ", " << key << ") = " << itemsChanged;
|
||||||
#endif
|
|
||||||
return itemsChanged;
|
return itemsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,11 +282,9 @@ int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const Q
|
|||||||
return itemsChanged;
|
return itemsChanged;
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap).nospace()
|
||||||
qDebug().nospace()
|
|
||||||
<< "QShortcutMap::setShortcutAutoRepeat(" << on << ", " << id << ", "
|
<< "QShortcutMap::setShortcutAutoRepeat(" << on << ", " << id << ", "
|
||||||
<< owner << ", " << key << ") = " << itemsChanged;
|
<< owner << ", " << key << ") = " << itemsChanged;
|
||||||
#endif
|
|
||||||
return itemsChanged;
|
return itemsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,9 +387,7 @@ QKeySequence::SequenceMatch QShortcutMap::nextState(QKeyEvent *e)
|
|||||||
clearSequence(d->currentSequences);
|
clearSequence(d->currentSequences);
|
||||||
d->currentState = result;
|
d->currentState = result;
|
||||||
|
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap).nospace() << "QShortcutMap::nextState(" << e << ") = " << result;
|
||||||
qDebug().nospace() << "QShortcutMap::nextState(" << e << ") = " << result;
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,9 +426,7 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
|
|||||||
return QKeySequence::NoMatch;
|
return QKeySequence::NoMatch;
|
||||||
|
|
||||||
createNewSequences(e, d->newEntries, ignoredModifiers);
|
createNewSequences(e, d->newEntries, ignoredModifiers);
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap) << "Possible shortcut key sequences:" << d->newEntries;
|
||||||
qDebug() << "Possible shortcut key sequences:" << d->newEntries;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Should never happen
|
// Should never happen
|
||||||
if (d->newEntries == d->currentSequences) {
|
if (d->newEntries == d->currentSequences) {
|
||||||
@ -491,15 +479,11 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
|
|||||||
// previous list. If this match is equal or better than the last match, append to the list
|
// previous list. If this match is equal or better than the last match, append to the list
|
||||||
if (oneKSResult > result) {
|
if (oneKSResult > result) {
|
||||||
okEntries.clear();
|
okEntries.clear();
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap) << "Found better match (" << d->newEntries << "), clearing key sequence list";
|
||||||
qDebug() << "Found better match (" << d->newEntries << "), clearing key sequence list";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if (oneKSResult && oneKSResult >= result) {
|
if (oneKSResult && oneKSResult >= result) {
|
||||||
okEntries << d->newEntries.at(i);
|
okEntries << d->newEntries.at(i);
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap) << "Added ok key sequence" << d->newEntries;
|
||||||
qDebug() << "Added ok key sequence" << d->newEntries;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,9 +499,7 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
|
|||||||
}
|
}
|
||||||
if (result != QKeySequence::NoMatch)
|
if (result != QKeySequence::NoMatch)
|
||||||
d->currentSequences = okEntries;
|
d->currentSequences = okEntries;
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
qCDebug(lcShortcutMap) << "Returning shortcut match == " << result;
|
||||||
qDebug() << "Returning shortcut match == " << result;
|
|
||||||
#endif
|
|
||||||
return QKeySequence::SequenceMatch(result);
|
return QKeySequence::SequenceMatch(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,19 +522,16 @@ void QShortcutMap::createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl,
|
|||||||
{
|
{
|
||||||
Q_D(QShortcutMap);
|
Q_D(QShortcutMap);
|
||||||
QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
|
QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
if (lcShortcutMap().isDebugEnabled()) {
|
||||||
{
|
qCDebug(lcShortcutMap).nospace() << __FUNCTION__ << '(' << e << ", ignoredModifiers="
|
||||||
QDebug debug = qDebug().nospace();
|
|
||||||
debug << __FUNCTION__ << '(' << e << ", ignoredModifiers="
|
|
||||||
<< Qt::KeyboardModifiers(ignoredModifiers) << "), possibleKeys=(";
|
<< Qt::KeyboardModifiers(ignoredModifiers) << "), possibleKeys=(";
|
||||||
for (int i = 0, size = possibleKeys.size(); i < size; ++i) {
|
for (int i = 0, size = possibleKeys.size(); i < size; ++i) {
|
||||||
if (i)
|
if (i)
|
||||||
debug << ", ";
|
qCDebug(lcShortcutMap).nospace() << ", ";
|
||||||
debug << QKeySequence(possibleKeys.at(i));
|
qCDebug(lcShortcutMap).nospace() << QKeySequence(possibleKeys.at(i));
|
||||||
}
|
}
|
||||||
debug << ')';
|
qCDebug(lcShortcutMap).nospace() << ')';
|
||||||
}
|
}
|
||||||
#endif // DEBUG_QSHORTCUTMAP
|
|
||||||
int pkTotal = possibleKeys.count();
|
int pkTotal = possibleKeys.count();
|
||||||
if (!pkTotal)
|
if (!pkTotal)
|
||||||
return;
|
return;
|
||||||
@ -661,16 +640,13 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
|
|||||||
// Find next
|
// Find next
|
||||||
const QShortcutEntry *current = 0, *next = 0;
|
const QShortcutEntry *current = 0, *next = 0;
|
||||||
int i = 0, enabledShortcuts = 0;
|
int i = 0, enabledShortcuts = 0;
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
|
||||||
QVector<const QShortcutEntry*> ambiguousShortcuts;
|
QVector<const QShortcutEntry*> ambiguousShortcuts;
|
||||||
#endif
|
|
||||||
while(i < d->identicals.size()) {
|
while(i < d->identicals.size()) {
|
||||||
current = d->identicals.at(i);
|
current = d->identicals.at(i);
|
||||||
if (current->enabled || !next){
|
if (current->enabled || !next){
|
||||||
++enabledShortcuts;
|
++enabledShortcuts;
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
if (lcShortcutMap().isDebugEnabled())
|
||||||
ambiguousShortcuts.append(current);
|
ambiguousShortcuts.append(current);
|
||||||
#endif
|
|
||||||
if (enabledShortcuts > d->ambigCount + 1)
|
if (enabledShortcuts > d->ambigCount + 1)
|
||||||
break;
|
break;
|
||||||
next = current;
|
next = current;
|
||||||
@ -683,19 +659,18 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
|
|||||||
if (!next || (e->isAutoRepeat() && !next->autorepeat))
|
if (!next || (e->isAutoRepeat() && !next->autorepeat))
|
||||||
return;
|
return;
|
||||||
// Dispatch next enabled
|
// Dispatch next enabled
|
||||||
#if defined(DEBUG_QSHORTCUTMAP)
|
if (lcShortcutMap().isDebugEnabled()) {
|
||||||
if (ambiguousShortcuts.size() > 1) {
|
if (ambiguousShortcuts.size() > 1) {
|
||||||
qDebug() << "The following shortcuts are about to be activated ambiguously:";
|
qCDebug(lcShortcutMap) << "The following shortcuts are about to be activated ambiguously:";
|
||||||
for (const QShortcutEntry *entry : qAsConst(ambiguousShortcuts)) {
|
for (const QShortcutEntry *entry : qAsConst(ambiguousShortcuts))
|
||||||
qDebug().nospace() << "- " << entry->keyseq << " (belonging to " << entry->owner << ")";
|
qCDebug(lcShortcutMap).nospace() << "- " << entry->keyseq << " (belonging to " << entry->owner << ")";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
qDebug().nospace()
|
qCDebug(lcShortcutMap).nospace()
|
||||||
<< "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\""
|
<< "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\""
|
||||||
<< next->keyseq.toString() << "\", " << next->id << ", "
|
<< next->keyseq.toString() << "\", " << next->id << ", "
|
||||||
<< (bool)(enabledShortcuts>1) << ") to object(" << next->owner << ')';
|
<< static_cast<bool>(enabledShortcuts>1) << ") to object(" << next->owner << ')';
|
||||||
#endif
|
}
|
||||||
QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1);
|
QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1);
|
||||||
QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se);
|
QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user