From 8ea6345e9f810bf5c4328f31faa1295707039ae9 Mon Sep 17 00:00:00 2001 From: Kiara Navarro Date: Thu, 14 Jul 2022 07:48:25 -0500 Subject: [PATCH] app: refactor enable connect to Instead of enabling multiple times "connect to" by iterating over device list, let's use a flag that determine when at least one device was found. In that way, the enabling method is executed once. --- Software/PC_Application/appwindow.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Software/PC_Application/appwindow.cpp b/Software/PC_Application/appwindow.cpp index e964080..be71773 100644 --- a/Software/PC_Application/appwindow.cpp +++ b/Software/PC_Application/appwindow.cpp @@ -932,6 +932,7 @@ int AppWindow::UpdateDeviceList() devices.insert(device->serial()); } int available = 0; + bool found = false; if(devices.size()) { for(auto d : devices) { if(!parser.value("device").isEmpty() && parser.value("device") != d) { @@ -947,13 +948,11 @@ int AppWindow::UpdateDeviceList() connect(connectAction, &QAction::triggered, [this, d]() { ConnectToDevice(d); }); - ui->menuConnect_to->setEnabled(true); + found = true; available++; } - } else { - // no devices available, disable connection option - ui->menuConnect_to->setEnabled(false); } + ui->menuConnect_to->setEnabled(found); qDebug() << "Updated device list, found" << available; return available; }