Improve and expand QShortcutMap debug output

- Replace vague symbols with descriptive words.
- Use qScopeGuard() to ensure that removeShortcut prints the number of
  removed shortcuts for all execution paths.

Change-Id: I4d36366445756b41b1dc40bbb1e987dce669a723
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Mitch Curtis 2021-02-02 15:45:34 +01:00
parent fccd419dd6
commit b1d750d59b

View File

@ -47,6 +47,7 @@
#include "qwindow.h"
#include <private/qkeymapper_p.h>
#include <QtCore/qloggingcategory.h>
#include <QtCore/qscopeguard.h>
#include <algorithm>
@ -166,7 +167,7 @@ int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::Short
d->sequences.insert(it, newEntry); // Insert sorted
qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::addShortcut(" << owner << ", "
<< key << ", " << context << ") = " << d->currentId;
<< key << ", " << context << ") added shortcut with ID " << d->currentId;
return d->currentId;
}
@ -187,6 +188,12 @@ int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key
bool allKeys = key.isEmpty();
bool allIds = id == 0;
auto debug = qScopeGuard([&](){
qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::removeShortcut(" << id << ", " << owner << ", "
<< key << ") removed " << itemsRemoved << " shortcuts(s)";
});
// Special case, remove everything
if (allOwners && allKeys && allIds) {
itemsRemoved = d->sequences.size();
@ -209,9 +216,6 @@ int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key
return itemsRemoved;
--i;
}
qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::removeShortcut(" << id << ", " << owner << ", "
<< key << ") = " << itemsRemoved;
return itemsRemoved;
}