Skip to content

Commit

Permalink
Reorganized Device and loadDevice code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola02nb committed Sep 19, 2024
1 parent 0f59ec5 commit 47f8bff
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/DataTypes/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/DataTypes/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Device
Device(const QJsonObject &jsonObj, QString jsonData);

// Status
bool connected = false;
QString status;

// Basic info
QString device;
Expand Down
6 changes: 4 additions & 2 deletions src/UI/loaddevicewindow.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "loaddevicewindow.h"
#include "ui_loaddevicewindow.h"

LoaddeviceWindow::LoaddeviceWindow(const QStringList &devices, QWidget *parent)
LoaddeviceWindow::LoaddeviceWindow(const QList<Device *> &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()
Expand Down
4 changes: 3 additions & 1 deletion src/UI/loaddevicewindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef LOADDEVICEWINDOW_H
#define LOADDEVICEWINDOW_H

#include "device.h"

#include <QDialog>

namespace Ui {
Expand All @@ -12,7 +14,7 @@ class LoaddeviceWindow : public QDialog
Q_OBJECT

public:
explicit LoaddeviceWindow(const QStringList &devices, QWidget *parent = nullptr);
explicit LoaddeviceWindow(const QList<Device *> &devices, QWidget *parent = nullptr);
~LoaddeviceWindow();

int getDeviceIndex();
Expand Down
11 changes: 2 additions & 9 deletions src/UI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 47f8bff

Please sign in to comment.