mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
Lint
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent)
|
UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent)
|
||||||
: UI_item(id, UI_BUTTON_TYPE, text, 12, fg_color, bg_color, parrent)
|
: UI_item(id, UI_BUTTON_TYPE, text, 12, fg_color, bg_color, parrent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_button::UI_button(const json &j, QObject *parrent) : UI_item(UI_BUTTON_TYPE, parrent)
|
UI_button::UI_button(const json &j, QObject *parrent) : UI_item(UI_BUTTON_TYPE, parrent)
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ class UI_checkbox : public UI_x_boxes
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_checkbox(QObject *parrent = nullptr);
|
UI_checkbox(QObject *parrent = nullptr);
|
||||||
UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options, QObject* parrent = nullptr);
|
UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
|
||||||
|
QObject *parrent = nullptr);
|
||||||
UI_checkbox(const json &j, QObject *parrent = nullptr);
|
UI_checkbox(const json &j, QObject *parrent = nullptr);
|
||||||
|
|
||||||
void toggle_selected(size_t selected);
|
void toggle_selected(size_t selected);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class UI_combobox : public UI_x_boxes
|
|||||||
json to_json() const override;
|
json to_json() const override;
|
||||||
signals:
|
signals:
|
||||||
void on_change(std::string id, std::string selected);
|
void on_change(std::string id, std::string selected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_selected;
|
size_t m_selected;
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
#include "UI_dial.hpp"
|
#include "UI_dial.hpp"
|
||||||
|
|
||||||
UI_dial::UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent)
|
UI_dial::UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
|
QObject *parrent)
|
||||||
: UI_item(id, UI_DIAL_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
|
: UI_item(id, UI_DIAL_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -7,7 +7,8 @@ class UI_dial : public UI_item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent = nullptr);
|
UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
|
QObject *parrent = nullptr);
|
||||||
UI_dial(const json &j, QObject *parrent = nullptr);
|
UI_dial(const json &j, QObject *parrent = nullptr);
|
||||||
|
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
|||||||
+7
-9
@@ -1,21 +1,19 @@
|
|||||||
#include "UI_item.hpp"
|
#include "UI_item.hpp"
|
||||||
|
|
||||||
UI_item::UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color, QObject* parrent)
|
UI_item::UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color,
|
||||||
: QObject(parrent),
|
QObject *parrent)
|
||||||
m_id(id), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color), m_bg_color(bg_color),
|
: QObject(parrent), m_id(id), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color),
|
||||||
enabled(true), visible(true)
|
m_bg_color(bg_color), enabled(true), visible(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_item::UI_item(std::string type, QObject *parrent)
|
UI_item::UI_item(std::string type, QObject *parrent)
|
||||||
: QObject(parrent),
|
: QObject(parrent), m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black),
|
||||||
m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black), m_bg_color(Color::White),
|
m_bg_color(Color::White), enabled(true), visible(true)
|
||||||
enabled(true), visible(true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_item::UI_item(const json &j, QObject* parrent) :
|
UI_item::UI_item(const json &j, QObject *parrent) : QObject(parrent)
|
||||||
QObject(parrent)
|
|
||||||
{
|
{
|
||||||
from_json(j);
|
from_json(j);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -16,7 +16,8 @@ class UI_item : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit UI_item(std::string type, QObject *parrent = nullptr);
|
explicit UI_item(std::string type, QObject *parrent = nullptr);
|
||||||
explicit UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color, QObject* parrent = nullptr);
|
explicit UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color,
|
||||||
|
Color bg_color, QObject *parrent = nullptr);
|
||||||
explicit UI_item(const json &j, QObject *parrent = nullptr);
|
explicit UI_item(const json &j, QObject *parrent = nullptr);
|
||||||
~UI_item();
|
~UI_item();
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -8,7 +8,8 @@ class UI_led : public UI_item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color, QObject* parrent = nullptr);
|
UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color,
|
||||||
|
QObject *parrent = nullptr);
|
||||||
UI_led(const json &j, QObject *parrent = nullptr);
|
UI_led(const json &j, QObject *parrent = nullptr);
|
||||||
|
|
||||||
Color led_color() const;
|
Color led_color() const;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ UI_slider::UI_slider(std::string id, std::string text, Color fg_color, Color bg_
|
|||||||
double value, QObject *parrent)
|
double value, QObject *parrent)
|
||||||
: UI_item(id, UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
|
: UI_item(id, UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_slider::UI_slider(const json &j, QObject *parrent) : UI_item(UI_SLIDER_TYPE, parrent)
|
UI_slider::UI_slider(const json &j, QObject *parrent) : UI_item(UI_SLIDER_TYPE, parrent)
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ class UI_slider : public UI_item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent = nullptr);
|
UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
|
QObject *parrent = nullptr);
|
||||||
UI_slider(const json &j, QObject *parrent = nullptr);
|
UI_slider(const json &j, QObject *parrent = nullptr);
|
||||||
|
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class UI_thermo : public UI_item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent = nullptr);
|
UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
|
QObject *parrent = nullptr);
|
||||||
UI_thermo(const json &j, QObject *parrent = nullptr);
|
UI_thermo(const json &j, QObject *parrent = nullptr);
|
||||||
|
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
|||||||
+4
-3
@@ -1,6 +1,6 @@
|
|||||||
#include <QtCore/QCoreApplication>
|
|
||||||
#include <QtCore/QCommandLineParser>
|
|
||||||
#include <QtCore/QCommandLineOption>
|
#include <QtCore/QCommandLineOption>
|
||||||
|
#include <QtCore/QCommandLineParser>
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
#include "spdlog/async.h"
|
#include "spdlog/async.h"
|
||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
@@ -32,7 +32,8 @@ int main(int argc, char *argv[])
|
|||||||
parser.setApplicationDescription("QtWebSockets example: echoserver");
|
parser.setApplicationDescription("QtWebSockets example: echoserver");
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
|
|
||||||
QCommandLineOption portOption(QStringList() << "p" << "port",
|
QCommandLineOption portOption(QStringList() << "p"
|
||||||
|
<< "port",
|
||||||
QCoreApplication::translate("main", "Port for echoserver [default: 9002]."),
|
QCoreApplication::translate("main", "Port for echoserver [default: 9002]."),
|
||||||
QCoreApplication::translate("main", "port"), QLatin1String("9002"));
|
QCoreApplication::translate("main", "port"), QLatin1String("9002"));
|
||||||
parser.addOption(portOption);
|
parser.addOption(portOption);
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ json Simulators::command_parser(json command)
|
|||||||
case Command::get_UI_element:
|
case Command::get_UI_element:
|
||||||
spdlog::info("Command {}: {}", type, std::string(command.at("id")));
|
spdlog::info("Command {}: {}", type, std::string(command.at("id")));
|
||||||
j["response"]["type"] = type;
|
j["response"]["type"] = type;
|
||||||
j["response"]["UI_item"] =
|
j["response"]["UI_item"] = invoke_active_simulator()->get_UI_item(command.at("id"))->to_json();
|
||||||
invoke_active_simulator()->get_UI_item(command.at("id"))->to_json();
|
|
||||||
break;
|
break;
|
||||||
case Command::get_UI_elements:
|
case Command::get_UI_elements:
|
||||||
spdlog::info("Command {}", type);
|
spdlog::info("Command {}", type);
|
||||||
@@ -88,9 +87,7 @@ void Simulators::event_handler(json event)
|
|||||||
}
|
}
|
||||||
case Event::value_changed: {
|
case Event::value_changed: {
|
||||||
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), (double)(event["value"]));
|
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), (double)(event["value"]));
|
||||||
invoke_active_simulator()
|
invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_value((double)event.at("value"));
|
||||||
->get_UI_item(std::string(event.at("id")))
|
|
||||||
->set_value((double)event.at("value"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Event::text_changed: {
|
case Event::text_changed: {
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class Simulator_base : public QObject
|
|||||||
* @param name The name of the simulator
|
* @param name The name of the simulator
|
||||||
* @param interval The interval of the timer (default is 100ms)
|
* @param interval The interval of the timer (default is 100ms)
|
||||||
*/
|
*/
|
||||||
Simulator_base(std::string name, std::chrono::milliseconds interval = std::chrono::milliseconds(100), QObject* parrent = nullptr);
|
Simulator_base(std::string name, std::chrono::milliseconds interval = std::chrono::milliseconds(100),
|
||||||
|
QObject *parrent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the name of the simulator
|
* @brief Returns the name of the simulator
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
#include "simulators.hpp"
|
#include "simulators.hpp"
|
||||||
#include "can_debugger.hpp"
|
#include "can_debugger.hpp"
|
||||||
#include "test_sim.hpp"
|
#include "test_sim.hpp"
|
||||||
#include <unordered_set>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
Simulators::Simulators(uint16_t port, QObject* parrent) :
|
Simulators::Simulators(uint16_t port, QObject *parrent) : QObject(parrent), m_server(new Websocket(port, this))
|
||||||
QObject(parrent),
|
|
||||||
m_server(new Websocket(port, this))
|
|
||||||
{
|
{
|
||||||
qDebug() << port;
|
qDebug() << port;
|
||||||
INSERT_SIMULATOR(Test_Sim);
|
INSERT_SIMULATOR(Test_Sim);
|
||||||
@@ -80,7 +78,8 @@ void Simulators::switch_simulator(std::string name)
|
|||||||
disconnect(m_simulators.at(m_current_simulator).get());
|
disconnect(m_simulators.at(m_current_simulator).get());
|
||||||
}
|
}
|
||||||
this->m_current_simulator = name;
|
this->m_current_simulator = name;
|
||||||
connect(m_simulators.at(m_current_simulator).get(), &Simulator_base::sim_changed, this, [this]{m_server->broadcast(QString::fromStdString(changed_UI_items().dump()));});
|
connect(m_simulators.at(m_current_simulator).get(), &Simulator_base::sim_changed, this,
|
||||||
|
[this] { m_server->broadcast(QString::fromStdString(changed_UI_items().dump())); });
|
||||||
this->run();
|
this->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "websocket.hpp"
|
|
||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
|
#include "websocket.hpp"
|
||||||
|
|
||||||
#define INSERT_SIMULATOR(type) m_simulators.insert(std::make_pair(type().name(), std::make_unique<type>()));
|
#define INSERT_SIMULATOR(type) m_simulators.insert(std::make_pair(type().name(), std::make_unique<type>()));
|
||||||
|
|
||||||
|
|||||||
+11
-10
@@ -1,17 +1,16 @@
|
|||||||
#include "websocket.hpp"
|
#include "websocket.hpp"
|
||||||
#include "QtWebSockets/qwebsocketserver.h"
|
|
||||||
#include "QtWebSockets/qwebsocket.h"
|
#include "QtWebSockets/qwebsocket.h"
|
||||||
|
#include "QtWebSockets/qwebsocketserver.h"
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
Websocket::Websocket(uint16_t port, QObject *parent) :
|
Websocket::Websocket(uint16_t port, QObject *parent)
|
||||||
QObject(parent),
|
: QObject(parent),
|
||||||
m_pWebSocketServer(new QWebSocketServer(QStringLiteral("sim_us Server"),
|
m_pWebSocketServer(new QWebSocketServer(QStringLiteral("sim_us Server"), QWebSocketServer::NonSecureMode, this))
|
||||||
QWebSocketServer::NonSecureMode, this))
|
{
|
||||||
|
if (m_pWebSocketServer->listen(QHostAddress::Any, port))
|
||||||
{
|
{
|
||||||
if (m_pWebSocketServer->listen(QHostAddress::Any, port)) {
|
|
||||||
spdlog::debug("Echoserver listening on port {}", port);
|
spdlog::debug("Echoserver listening on port {}", port);
|
||||||
connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
|
connect(m_pWebSocketServer, &QWebSocketServer::newConnection, this, &Websocket::onNewConnection);
|
||||||
this, &Websocket::onNewConnection);
|
|
||||||
connect(m_pWebSocketServer, &QWebSocketServer::closed, this, &Websocket::closed);
|
connect(m_pWebSocketServer, &QWebSocketServer::closed, this, &Websocket::closed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +23,8 @@ Websocket::~Websocket()
|
|||||||
|
|
||||||
void Websocket::broadcast(QString message)
|
void Websocket::broadcast(QString message)
|
||||||
{
|
{
|
||||||
foreach (QWebSocket* conn, m_clients) {
|
foreach (QWebSocket *conn, m_clients)
|
||||||
|
{
|
||||||
conn->sendTextMessage(message);
|
conn->sendTextMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,8 @@ void Websocket::socketDisconnected()
|
|||||||
{
|
{
|
||||||
QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
|
QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
|
||||||
spdlog::debug("socket Disconnected");
|
spdlog::debug("socket Disconnected");
|
||||||
if (pClient) {
|
if (pClient)
|
||||||
|
{
|
||||||
m_clients.removeAll(pClient);
|
m_clients.removeAll(pClient);
|
||||||
pClient->deleteLater();
|
pClient->deleteLater();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
|
||||||
#include <QtCore/QList>
|
|
||||||
#include <QtCore/QByteArray>
|
#include <QtCore/QByteArray>
|
||||||
|
#include <QtCore/QList>
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
||||||
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
||||||
|
|||||||
Reference in New Issue
Block a user