Frontend: Optimize control conflict handling a bit
authorWuzzy <Wuzzy2@mail.ru>
Tue, 07 May 2019 20:23:51 +0200
changeset 14906 089f0c10ca95
parent 14905 505c8d101be3
child 14907 2dcc64515346
Frontend: Optimize control conflict handling a bit
QTfrontend/ui/widget/keybinder.cpp
QTfrontend/ui/widget/keybinder.h
--- a/QTfrontend/ui/widget/keybinder.cpp	Tue May 07 19:39:08 2019 +0200
+++ b/QTfrontend/ui/widget/keybinder.cpp	Tue May 07 20:23:51 2019 +0200
@@ -314,7 +314,6 @@
 // check if the given key is bound multiple times
 bool KeyBinder::checkConflictsWith(int compareTo, bool updateState)
 {
-    // TODO: Make conflict check more efficient
     for(int i=0; i<BINDS_NUMBER; i++)
     {
         if(i == compareTo)
@@ -331,33 +330,33 @@
                 p_hasConflicts = true;
                 conflictLabel->setHidden(false);
             }
-            QTableWidgetItem* item = bindComboBoxCellMappings->value(CBBind[i]);
-            item->setIcon(*conflictIcon);
-            item->setBackground(QBrush(QColor(0xE3, 0x1A, 0x1A)));
-            item->setForeground(QBrush(Qt::white));
-            item = bindComboBoxCellMappings->value(CBBind[compareTo]);
-            item->setIcon(*conflictIcon);
-            item->setBackground(QBrush(QColor(0xE3, 0x1A, 0x1A)));
-            item->setForeground(QBrush(Qt::white));
+            QTableWidgetItem* conflictItem = bindComboBoxCellMappings->value(CBBind[i]);
+            conflictItem->setIcon(*conflictIcon);
+            conflictItem->setBackground(QBrush(QColor(0xE3, 0x1A, 0x1A)));
+            conflictItem->setForeground(QBrush(Qt::white));
+            conflictItems.append(conflictItem);
+            conflictItem = bindComboBoxCellMappings->value(CBBind[compareTo]);
+            conflictItem->setIcon(*conflictIcon);
+            conflictItem->setBackground(QBrush(QColor(0xE3, 0x1A, 0x1A)));
+            conflictItem->setForeground(QBrush(Qt::white));
+            conflictItems.append(conflictItem);
             return true;
         }
-        else
-        {
-            QTableWidgetItem* item = bindComboBoxCellMappings->value(CBBind[i]);
-            item->setIcon(*dropDownIcon);
-            item->setBackground(QBrush(Qt::transparent));
-            item->setForeground(QBrush(QColor("#F6CB1C")));
-            item = bindComboBoxCellMappings->value(CBBind[compareTo]);
-            item->setIcon(*dropDownIcon);
-            item->setBackground(QBrush(Qt::transparent));
-            item->setForeground(QBrush(QColor("#F6CB1C")));
-        }
     }
     if(updateState)
     {
         p_hasConflicts = false;
         conflictLabel->setHidden(true);
     }
+    for (int c=0; c < conflictItems.size(); c++)
+    {
+        QTableWidgetItem* conflictItem = conflictItems[c];
+        conflictItem->setIcon(*dropDownIcon);
+        conflictItem->setBackground(QBrush(Qt::transparent));
+        conflictItem->setForeground(QBrush(QColor("#F6CB1C")));
+        conflictItem = NULL;
+    }
+    conflictItems.clear();
     return false;
 }
 
--- a/QTfrontend/ui/widget/keybinder.h	Tue May 07 19:39:08 2019 +0200
+++ b/QTfrontend/ui/widget/keybinder.h	Tue May 07 20:23:51 2019 +0200
@@ -60,6 +60,7 @@
         QIcon * conflictIcon;
         QString defaultText;
         bool enableSignal;
+        QList<QTableWidgetItem*> conflictItems;
         bool p_hasConflicts;
 
     signals: