mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
client
move to QMessageBox from networkerror
This commit is contained in:
@@ -16,9 +16,6 @@ set(PROJECT_SOURCES
|
|||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
mainwindow.hpp
|
mainwindow.hpp
|
||||||
mainwindow.ui
|
mainwindow.ui
|
||||||
networkerror.cpp
|
|
||||||
networkerror.hpp
|
|
||||||
networkerror.ui
|
|
||||||
simulator_base.cpp
|
simulator_base.cpp
|
||||||
simulator_base.hpp
|
simulator_base.hpp
|
||||||
web_socket_wrapper.cpp
|
web_socket_wrapper.cpp
|
||||||
|
|||||||
+11
-5
@@ -2,14 +2,15 @@
|
|||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QLibrary>
|
#include <QLibrary>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <magic_enum/magic_enum.hpp>
|
#include <magic_enum/magic_enum.hpp>
|
||||||
|
|
||||||
typedef Simulator_base *(*Get_UI)(Web_socket_wrapper *, QWidget *);
|
typedef Simulator_base *(*Get_UI)(Web_socket_wrapper *, QWidget *);
|
||||||
|
|
||||||
MainWindow::MainWindow(QUrl ws_url, QString sim, QWidget *parent)
|
MainWindow::MainWindow(QUrl ws_url, QString sim, QWidget *parent)
|
||||||
: QMainWindow(parent), ui(new Ui::MainWindow), m_web_socket(new Web_socket_wrapper(ws_url)),
|
: QMainWindow(parent), ui(new Ui::MainWindow), m_error(new QMessageBox()),
|
||||||
m_error_dialog(new NetworkError(this))
|
m_web_socket(new Web_socket_wrapper(ws_url))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
QLibrary lib;
|
QLibrary lib;
|
||||||
@@ -30,17 +31,22 @@ MainWindow::MainWindow(QUrl ws_url, QString sim, QWidget *parent)
|
|||||||
m_sims.insert(std::make_pair(widget->name(), widget));
|
m_sims.insert(std::make_pair(widget->name(), widget));
|
||||||
lib.unload();
|
lib.unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert debug sims here
|
// Insert debug sims here
|
||||||
// INSERT_SIMULATOR(SIM_NAME);
|
// INSERT_SIMULATOR(SIM_NAME);
|
||||||
|
|
||||||
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
m_error->setIcon(QMessageBox::Critical);
|
||||||
|
m_error->setWindowTitle("Critical");
|
||||||
|
m_error->setText("Connection timed out\nCheck if the server is running");
|
||||||
|
QPushButton *exit_app = m_error->addButton("Exit Application", QMessageBox::AcceptRole);
|
||||||
|
m_error->addButton("Close", QMessageBox::RejectRole);
|
||||||
|
connect(exit_app, &QPushButton::clicked, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
||||||
ui->connection->setText("Connected to " + ws_url.toString());
|
ui->connection->setText("Connected to " + ws_url.toString());
|
||||||
// Default sim
|
// Default sim
|
||||||
if (!sim.isEmpty())
|
if (!sim.isEmpty())
|
||||||
default_sim(sim);
|
default_sim(sim);
|
||||||
|
|
||||||
connect(ui->pushButton, &QPushButton::clicked, this, [=, this] { open_sim(ui->comboBox->currentText()); });
|
connect(ui->pushButton, &QPushButton::clicked, this, [=, this] { open_sim(ui->comboBox->currentText()); });
|
||||||
connect(this, &MainWindow::quit, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -54,7 +60,7 @@ void MainWindow::setup_cb(void)
|
|||||||
connect(m_web_socket.get(), &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.get(), &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->open();
|
||||||
ui->connection->setText("Could not connect to the server");
|
ui->connection->setText("Could not connect to the server");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "networkerror.hpp"
|
|
||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
#include "web_socket_wrapper.hpp"
|
#include "web_socket_wrapper.hpp"
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
@@ -8,6 +7,8 @@
|
|||||||
#define INSERT_SIMULATOR(type) \
|
#define INSERT_SIMULATOR(type) \
|
||||||
m_sims.insert(std::make_pair(type().sim_name(), std::make_unique<type>(m_web_socket.get(), this)))
|
m_sims.insert(std::make_pair(type().sim_name(), std::make_unique<type>(m_web_socket.get(), this)))
|
||||||
|
|
||||||
|
Q_FORWARD_DECLARE_OBJC_CLASS(QMessageBox);
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@@ -28,9 +29,6 @@ class MainWindow : public QMainWindow
|
|||||||
void open_sim(QString sim_name);
|
void open_sim(QString sim_name);
|
||||||
void setup_cb(void);
|
void setup_cb(void);
|
||||||
|
|
||||||
signals:
|
|
||||||
void quit(void);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
void hideEvent(QHideEvent *event);
|
void hideEvent(QHideEvent *event);
|
||||||
@@ -40,9 +38,8 @@ class MainWindow : public QMainWindow
|
|||||||
bool m_default_sim = false;
|
bool m_default_sim = false;
|
||||||
QString m_selected_sim_name;
|
QString m_selected_sim_name;
|
||||||
QMainWindow *m_selected_sim;
|
QMainWindow *m_selected_sim;
|
||||||
|
QMessageBox *m_error;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
std::unique_ptr<Web_socket_wrapper> m_web_socket;
|
std::unique_ptr<Web_socket_wrapper> m_web_socket;
|
||||||
std::unique_ptr<NetworkError> m_error_dialog;
|
|
||||||
|
|
||||||
std::map<QString, std::unique_ptr<Simulator_base>> m_sims;
|
std::map<QString, std::unique_ptr<Simulator_base>> m_sims;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#include "networkerror.hpp"
|
|
||||||
#include "ui_networkerror.h"
|
|
||||||
|
|
||||||
NetworkError::NetworkError(QWidget *parent) : QDialog(parent), ui(new Ui::NetworkError)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
|
||||||
connect(ui->exit, &QPushButton::clicked, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
|
||||||
connect(ui->close, &QPushButton::clicked, this, [=, this] { this->close(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkError::set_error(QString error)
|
|
||||||
{
|
|
||||||
ui->Error->setText(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkError::~NetworkError()
|
|
||||||
{
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <QDialog>
|
|
||||||
|
|
||||||
namespace Ui
|
|
||||||
{
|
|
||||||
class NetworkError;
|
|
||||||
}
|
|
||||||
|
|
||||||
class NetworkError : public QDialog
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit NetworkError(QWidget *parent = nullptr);
|
|
||||||
void set_error(QString error);
|
|
||||||
~NetworkError();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::NetworkError *ui;
|
|
||||||
};
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>NetworkError</class>
|
|
||||||
<widget class="QDialog" name="NetworkError">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>400</width>
|
|
||||||
<height>300</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Error</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="title">
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<pointsize>16</pointsize>
|
|
||||||
<bold>true</bold>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Oops, an error occured</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="Error">
|
|
||||||
<property name="text">
|
|
||||||
<string>Error...</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="close">
|
|
||||||
<property name="text">
|
|
||||||
<string>Close</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="exit">
|
|
||||||
<property name="text">
|
|
||||||
<string>Exit Application</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
||||||
@@ -2,22 +2,28 @@
|
|||||||
#include "can_transceive.hpp"
|
#include "can_transceive.hpp"
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
#include "led.hpp"
|
#include "led.hpp"
|
||||||
#include "networkerror.hpp"
|
|
||||||
#include "plot_wrapper.hpp"
|
#include "plot_wrapper.hpp"
|
||||||
#include "web_socket_wrapper.hpp"
|
#include "web_socket_wrapper.hpp"
|
||||||
|
#include <QMessageBox>
|
||||||
#include <magic_enum/magic_enum.hpp>
|
#include <magic_enum/magic_enum.hpp>
|
||||||
|
|
||||||
Simulator_base::Simulator_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
|
Simulator_base::Simulator_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
|
||||||
: QMainWindow{parent}, m_error_dialog(new NetworkError(this)), m_timer_update(new QTimer()),
|
: QMainWindow{parent}, m_timer_update(new QTimer()), m_error(new QMessageBox(this)), m_web_socket(web_socket),
|
||||||
m_web_socket(web_socket), m_name(name)
|
m_name(name)
|
||||||
{
|
{
|
||||||
if (windowTitle() != m_name)
|
if (windowTitle() != m_name)
|
||||||
{
|
{
|
||||||
setWindowTitle(m_name);
|
setWindowTitle(m_name);
|
||||||
}
|
}
|
||||||
this->setWindowState(Qt::WindowMaximized);
|
this->setWindowState(Qt::WindowMaximized);
|
||||||
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
|
||||||
m_ui_lookup.reserve(40);
|
m_ui_lookup.reserve(40);
|
||||||
|
|
||||||
|
m_error->setIcon(QMessageBox::Critical);
|
||||||
|
m_error->setWindowTitle("Critical");
|
||||||
|
m_error->setText("Connection timed out\nCheck if the server is running");
|
||||||
|
QPushButton *exit_app = m_error->addButton("Exit Application", QMessageBox::AcceptRole);
|
||||||
|
m_error->addButton("Close", QMessageBox::RejectRole);
|
||||||
|
connect(exit_app, &QPushButton::clicked, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *Simulator_base::id_to_ui(size_t id)
|
QWidget *Simulator_base::id_to_ui(size_t id)
|
||||||
@@ -38,7 +44,7 @@ void Simulator_base::showEvent(QShowEvent *event)
|
|||||||
|
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json &j) { on_cmd_cb(j); });
|
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json &j) { on_cmd_cb(j); });
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_event_cb, this, [=, this](json &j) { on_event_cb(j); });
|
connect(m_web_socket, &Web_socket_wrapper::on_event_cb, this, [=, this](json &j) { on_event_cb(j); });
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this] { m_error_dialog->open(); });
|
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this] { m_error->open(); });
|
||||||
|
|
||||||
m_web_socket->inhibit_events(true);
|
m_web_socket->inhibit_events(true);
|
||||||
m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements);
|
m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements);
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
Q_FORWARD_DECLARE_OBJC_CLASS(Web_socket_wrapper);
|
Q_FORWARD_DECLARE_OBJC_CLASS(Web_socket_wrapper);
|
||||||
Q_FORWARD_DECLARE_OBJC_CLASS(QTimer);
|
Q_FORWARD_DECLARE_OBJC_CLASS(QTimer);
|
||||||
Q_FORWARD_DECLARE_OBJC_CLASS(NetworkError);
|
|
||||||
Q_FORWARD_DECLARE_OBJC_CLASS(QLabel);
|
Q_FORWARD_DECLARE_OBJC_CLASS(QLabel);
|
||||||
|
Q_FORWARD_DECLARE_OBJC_CLASS(QMessageBox);
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class Simulator_base : public QMainWindow
|
|||||||
|
|
||||||
QTimer *m_timer_update;
|
QTimer *m_timer_update;
|
||||||
uint32_t m_refresh_rate;
|
uint32_t m_refresh_rate;
|
||||||
NetworkError *m_error_dialog;
|
QMessageBox *m_error;
|
||||||
bool m_open = false;
|
bool m_open = false;
|
||||||
bool m_first_load = true;
|
bool m_first_load = true;
|
||||||
std::vector<QWidget *> m_ui_lookup;
|
std::vector<QWidget *> m_ui_lookup;
|
||||||
|
|||||||
Reference in New Issue
Block a user