QWindowsKeyMapper: replace one magic constant with a symbolic one
authorMarc Mutz <marc.mutz@kdab.com>
Wed, 10 Oct 2012 15:52:21 +0000 (17:52 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Oct 2012 15:31:31 +0000 (17:31 +0200)
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 <Friedemann.Kleint@digia.com>
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
src/plugins/platforms/windows/qwindowskeymapper.cpp

index b57a27a..fff7b84 100644 (file)
@@ -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_<foo>, or unicode character
+    quint32 qtKey[NumMods]; // Can by any Qt::Key_<foo>, 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<<i);
         }
@@ -1135,7 +1136,7 @@ QList<int> 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))