From fb21212f1eeddb9e2f13b7d5b0b4f48147f05412 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 10 Oct 2012 17:52:21 +0200 Subject: [PATCH] QWindowsKeyMapper: replace one magic constant with a symbolic one Replace occurrences of a literal 9 that mean 'number of modifier key combinations' with the new symbolic constant NumMods. Change-Id: I1e78a1a3c00b81095450ec0557e30751da44c39a Reviewed-by: Friedemann Kleint Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowskeymapper.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index b57a27a..fff7b84 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -436,6 +436,7 @@ static const Qt::KeyboardModifiers ModsTbl[] = { Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier, // 7 Qt::NoModifier, // Fall-back to raw Key_* }; +static const size_t NumMods = sizeof ModsTbl / sizeof *ModsTbl; /** Remap return or action key to select key for windows mobile. @@ -535,7 +536,7 @@ static inline bool isModifierKey(int code) struct KeyboardLayoutItem { bool dirty; quint8 deadkeys; - quint32 qtKey[9]; // Can by any Qt::Key_, or unicode character + quint32 qtKey[NumMods]; // Can by any Qt::Key_, or unicode character }; void QWindowsKeyMapper::deleteLayouts() @@ -666,8 +667,8 @@ void QWindowsKeyMapper::updatePossibleKeyCodes(unsigned char *kbdBuffer, quint32 if (QWindowsContext::verboseEvents > 1) { qDebug("updatePossibleKeyCodes for virtual key = 0x%02x!", vk_key); - for (int i = 0; i < 9; ++i) { - qDebug(" [%d] (%d,0x%02x,'%c') %s", i, + for (size_t i = 0; i < NumMods; ++i) { + qDebug(" [%d] (%d,0x%02x,'%c') %s", int(i), keyLayout[vk_key]->qtKey[i], keyLayout[vk_key]->qtKey[i], keyLayout[vk_key]->qtKey[i] ? keyLayout[vk_key]->qtKey[i] : 0x03, @@ -679,7 +680,7 @@ void QWindowsKeyMapper::updatePossibleKeyCodes(unsigned char *kbdBuffer, quint32 bool QWindowsKeyMapper::isADeadKey(unsigned int vk_key, unsigned int modifiers) { if (keyLayout && (vk_key < 256) && keyLayout[vk_key]) { - for (register int i = 0; i < 9; ++i) { + for (register size_t i = 0; i < NumMods; ++i) { if (uint(ModsTbl[i]) == modifiers) return bool(keyLayout[vk_key]->deadkeys & 1< QWindowsKeyMapper::possibleKeys(const QKeyEvent *e) const } result << int(baseKey + keyMods); // The base key is _always_ valid, of course - for (int i = 1; i < 9; ++i) { + for (int i = 1; i < NumMods; ++i) { Qt::KeyboardModifiers neededMods = ModsTbl[i]; quint32 key = kbItem->qtKey[i]; if (key && key != baseKey && ((keyMods & neededMods) == neededMods)) -- 2.7.4