From 47f8bffdd6129445a74bdb19d1b50680e46539fa Mon Sep 17 00:00:00 2001 From: nicola02nb <61830443+nicola02nb@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:52:03 +0200 Subject: [PATCH] Reorganized Device and loadDevice code --- src/DataTypes/device.cpp | 2 +- src/DataTypes/device.h | 2 +- src/UI/loaddevicewindow.cpp | 6 ++++-- src/UI/loaddevicewindow.h | 4 +++- src/UI/mainwindow.cpp | 11 ++--------- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/DataTypes/device.cpp b/src/DataTypes/device.cpp index 4267997..57c2a93 100644 --- a/src/DataTypes/device.cpp +++ b/src/DataTypes/device.cpp @@ -29,7 +29,7 @@ Device::Device() {} Device::Device(const QJsonObject &jsonObj, QString jsonData) { - connected = jsonObj["status"].toString() == "success"; + status = jsonObj["status"].toString(); device = jsonObj["device"].toString(); vendor = jsonObj["vendor"].toString(); diff --git a/src/DataTypes/device.h b/src/DataTypes/device.h index 4f3a6fb..dc02931 100644 --- a/src/DataTypes/device.h +++ b/src/DataTypes/device.h @@ -41,7 +41,7 @@ class Device Device(const QJsonObject &jsonObj, QString jsonData); // Status - bool connected = false; + QString status; // Basic info QString device; diff --git a/src/UI/loaddevicewindow.cpp b/src/UI/loaddevicewindow.cpp index b783da7..b9cbce1 100644 --- a/src/UI/loaddevicewindow.cpp +++ b/src/UI/loaddevicewindow.cpp @@ -1,14 +1,16 @@ #include "loaddevicewindow.h" #include "ui_loaddevicewindow.h" -LoaddeviceWindow::LoaddeviceWindow(const QStringList &devices, QWidget *parent) +LoaddeviceWindow::LoaddeviceWindow(const QList &devices, QWidget *parent) : QDialog(parent) , ui(new Ui::loaddevicewindow) { setModal(true); ui->setupUi(this); - ui->devicelistComboBox->addItems(devices); + for (Device *device : devices) { + ui->devicelistComboBox->addItem(device->device); + } } int LoaddeviceWindow::getDeviceIndex() diff --git a/src/UI/loaddevicewindow.h b/src/UI/loaddevicewindow.h index 1ee5781..26bdef7 100644 --- a/src/UI/loaddevicewindow.h +++ b/src/UI/loaddevicewindow.h @@ -1,6 +1,8 @@ #ifndef LOADDEVICEWINDOW_H #define LOADDEVICEWINDOW_H +#include "device.h" + #include namespace Ui { @@ -12,7 +14,7 @@ class LoaddeviceWindow : public QDialog Q_OBJECT public: - explicit LoaddeviceWindow(const QStringList &devices, QWidget *parent = nullptr); + explicit LoaddeviceWindow(const QList &devices, QWidget *parent = nullptr); ~LoaddeviceWindow(); int getDeviceIndex(); diff --git a/src/UI/mainwindow.cpp b/src/UI/mainwindow.cpp index d3b5563..23353a5 100644 --- a/src/UI/mainwindow.cpp +++ b/src/UI/mainwindow.cpp @@ -688,17 +688,10 @@ void MainWindow::selectDevice() { this->loadDevices(); - QStringList devices = QStringList(); - for (Device *device : connectedDevices) { - if (device->connected) { - devices << device->device; - } - } - - LoaddeviceWindow *loadDevWindow = new LoaddeviceWindow(devices, this); + LoaddeviceWindow *loadDevWindow = new LoaddeviceWindow(connectedDevices, this); if (loadDevWindow->exec() == QDialog::Accepted) { int index = loadDevWindow->getDeviceIndex(); - if (index >= 0 && index < devices.length()) { + if (index >= 0 && index < connectedDevices.length()) { if (index == 0) { ui->tabWidget->setDisabled(false); } else {