mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
client
move sims from {} based insert to define based insert as in the server
This commit is contained in:
+11
-12
@@ -8,14 +8,15 @@
|
|||||||
|
|
||||||
MainWindow::MainWindow(QUrl ws_url, QWidget *parent)
|
MainWindow::MainWindow(QUrl ws_url, QWidget *parent)
|
||||||
: QMainWindow(parent), ui(new Ui::MainWindow), m_web_socket(new Web_socket_wrapper(ws_url)),
|
: QMainWindow(parent), ui(new Ui::MainWindow), m_web_socket(new Web_socket_wrapper(ws_url)),
|
||||||
m_error_dialog(new NetworkError(this)), m_sims{{"Cable Tester", new Cable_Tester(m_web_socket, this)},
|
m_error_dialog(new NetworkError(this))
|
||||||
{"Can Debugger", new Can_Debugger(m_web_socket, this)},
|
|
||||||
{"Scope Mux Tester", new Scope_Mux_Tester(m_web_socket, this)},
|
|
||||||
{"CVS I10", new CVS_I10(m_web_socket, this)},
|
|
||||||
{"Test Sim", new Test_Sim(m_web_socket, this)}}
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowTitle("Simulator Selector");
|
this->setWindowTitle("Simulator Selector");
|
||||||
|
INSERT_SIMULATOR(Cable_Tester);
|
||||||
|
INSERT_SIMULATOR(Can_Debugger);
|
||||||
|
INSERT_SIMULATOR(Scope_Mux_Tester);
|
||||||
|
INSERT_SIMULATOR(CVS_I10);
|
||||||
|
INSERT_SIMULATOR(Test_Sim);
|
||||||
|
|
||||||
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
||||||
ui->connection->setText("Connected to " + ws_url.toString());
|
ui->connection->setText("Connected to " + ws_url.toString());
|
||||||
@@ -29,16 +30,14 @@ MainWindow::MainWindow(QUrl ws_url, QWidget *parent)
|
|||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
delete m_web_socket;
|
|
||||||
delete m_error_dialog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setup_cb(void)
|
void MainWindow::setup_cb(void)
|
||||||
{
|
{
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json &j) { on_cmd_cb(j); });
|
connect(m_web_socket.get(), &Web_socket_wrapper::on_command_cb, this, [=, this](json &j) { on_cmd_cb(j); });
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_connected, this,
|
connect(m_web_socket.get(), &Web_socket_wrapper::on_connected, this,
|
||||||
[=, this] { m_web_socket->send_command(Web_socket_wrapper::Command::get_simulators); });
|
[=, this] { m_web_socket->send_command(Web_socket_wrapper::Command::get_simulators); });
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this] {
|
connect(m_web_socket.get(), &Web_socket_wrapper::on_closed, this, [=, this] {
|
||||||
m_error_dialog->open();
|
m_error_dialog->open();
|
||||||
ui->connection->setText("Could not connect to the server");
|
ui->connection->setText("Could not connect to the server");
|
||||||
});
|
});
|
||||||
@@ -53,7 +52,7 @@ void MainWindow::showEvent(QShowEvent *event)
|
|||||||
void MainWindow::hideEvent(QHideEvent *event)
|
void MainWindow::hideEvent(QHideEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::hideEvent(event);
|
QWidget::hideEvent(event);
|
||||||
disconnect(m_web_socket, nullptr, nullptr, nullptr);
|
disconnect(m_web_socket.get(), nullptr, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::defaultSim(QString name)
|
void MainWindow::defaultSim(QString name)
|
||||||
@@ -82,7 +81,7 @@ void MainWindow::open_sim(QString sim_name)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_selected_sim = m_sims.at(sim_name);
|
m_selected_sim = m_sims.at(sim_name).get();
|
||||||
this->m_selected_sim_name = sim_name;
|
this->m_selected_sim_name = sim_name;
|
||||||
}
|
}
|
||||||
catch (const std::out_of_range &ex)
|
catch (const std::out_of_range &ex)
|
||||||
|
|||||||
+6
-3
@@ -7,6 +7,9 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#define INSERT_SIMULATOR(type) \
|
||||||
|
m_sims.insert(std::make_pair(type().sim_name(), std::make_unique<type>(m_web_socket.get(), this)))
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@@ -40,10 +43,10 @@ class MainWindow : public QMainWindow
|
|||||||
QString m_selected_sim_name;
|
QString m_selected_sim_name;
|
||||||
QMainWindow *m_selected_sim;
|
QMainWindow *m_selected_sim;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Web_socket_wrapper *m_web_socket;
|
std::unique_ptr<Web_socket_wrapper> m_web_socket;
|
||||||
NetworkError *m_error_dialog;
|
std::unique_ptr<NetworkError> m_error_dialog;
|
||||||
|
|
||||||
std::map<QString, Simulator_base *> m_sims;
|
std::map<QString, std::unique_ptr<Simulator_base>> m_sims;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "simulator_base.h"
|
#include "simulator_base.h"
|
||||||
#include "can_transceive.h"
|
#include "can_transceive.h"
|
||||||
|
|
||||||
Simulator_base::Simulator_base(Web_socket_wrapper *web_socket, QWidget *parent)
|
Simulator_base::Simulator_base(QString sim_name, Web_socket_wrapper *web_socket, QWidget *parent)
|
||||||
: QMainWindow{parent}, m_error_dialog(new NetworkError(this)), m_timer_update(new QTimer()),
|
: QMainWindow{parent}, m_error_dialog(new NetworkError(this)), m_timer_update(new QTimer()),
|
||||||
m_web_socket(web_socket)
|
m_web_socket(web_socket), m_sim_name(sim_name)
|
||||||
{
|
{
|
||||||
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
||||||
m_ui_lookup.reserve(40);
|
m_ui_lookup.reserve(40);
|
||||||
@@ -14,6 +14,11 @@ QWidget *Simulator_base::id_to_ui(size_t id)
|
|||||||
return m_ui_lookup.at(id);
|
return m_ui_lookup.at(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Simulator_base::sim_name() const
|
||||||
|
{
|
||||||
|
return m_sim_name;
|
||||||
|
}
|
||||||
|
|
||||||
void Simulator_base::showEvent(QShowEvent *event)
|
void Simulator_base::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::showEvent(event);
|
QWidget::showEvent(event);
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ class Simulator_base : public QMainWindow
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Simulator_base(Web_socket_wrapper *api, QWidget *parent = nullptr);
|
explicit Simulator_base(QString sim_name, Web_socket_wrapper *api, QWidget *parent = nullptr);
|
||||||
void sim_update(void);
|
void sim_update(void);
|
||||||
|
QString sim_name() const;
|
||||||
QWidget *id_to_ui(size_t id);
|
QWidget *id_to_ui(size_t id);
|
||||||
virtual QLabel *id_to_label(size_t name)
|
virtual QLabel *id_to_label(size_t name)
|
||||||
{
|
{
|
||||||
@@ -60,6 +61,7 @@ class Simulator_base : public QMainWindow
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Web_socket_wrapper *m_web_socket;
|
Web_socket_wrapper *m_web_socket;
|
||||||
|
QString m_sim_name;
|
||||||
|
|
||||||
QTimer *m_timer_update;
|
QTimer *m_timer_update;
|
||||||
uint32_t m_refresh_rate;
|
uint32_t m_refresh_rate;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "ui_can_debugger.h"
|
#include "ui_can_debugger.h"
|
||||||
|
|
||||||
Can_Debugger::Can_Debugger(Web_socket_wrapper *web_socket, QWidget *parent)
|
Can_Debugger::Can_Debugger(Web_socket_wrapper *web_socket, QWidget *parent)
|
||||||
: Simulator_base(web_socket, parent), ui(new Ui::Can_Debugger)
|
: Simulator_base("Can Debugger", web_socket, parent), ui(new Ui::Can_Debugger)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowTitle("CAN Debugger");
|
this->setWindowTitle("CAN Debugger");
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Can_Debugger : public Simulator_base
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Can_Debugger(Web_socket_wrapper *web_socket, QWidget *parent = nullptr);
|
explicit Can_Debugger(Web_socket_wrapper *web_socket = nullptr, QWidget *parent = nullptr);
|
||||||
~Can_Debugger();
|
~Can_Debugger();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "ui_test.h"
|
#include "ui_test.h"
|
||||||
|
|
||||||
Test_Sim::Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent)
|
Test_Sim::Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent)
|
||||||
: Simulator_base(web_socket, parent), ui(new Ui::Test_Sim)
|
: Simulator_base("Test Sim", web_socket, parent), ui(new Ui::Test_Sim)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowTitle("Test Sim");
|
this->setWindowTitle("Test Sim");
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class Test_Sim : public Simulator_base
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent = nullptr);
|
explicit Test_Sim(Web_socket_wrapper *web_socket = nullptr, QWidget *parent = nullptr);
|
||||||
~Test_Sim();
|
~Test_Sim();
|
||||||
|
|
||||||
QLabel *id_to_label(size_t name) override;
|
QLabel *id_to_label(size_t name) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user