diff --git a/src/UI/UI_button.cpp b/src/UI/UI_button.cpp index bbbf106..bb3f8a6 100644 --- a/src/UI/UI_button.cpp +++ b/src/UI/UI_button.cpp @@ -1,12 +1,11 @@ #include "UI_button.hpp" -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_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) { from_json(j); } diff --git a/src/UI/UI_button.hpp b/src/UI/UI_button.hpp index 465c02e..12c4742 100644 --- a/src/UI/UI_button.hpp +++ b/src/UI/UI_button.hpp @@ -8,8 +8,8 @@ class UI_button : public UI_item { Q_OBJECT public: - UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject* parrent = nullptr); - UI_button(const json &j, QObject* parrent = nullptr); + UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent = nullptr); + UI_button(const json &j, QObject *parrent = nullptr); void from_json(const json &j) override; json to_json() const override; diff --git a/src/UI/UI_checkbox.cpp b/src/UI/UI_checkbox.cpp index e4b19cc..33480a7 100644 --- a/src/UI/UI_checkbox.cpp +++ b/src/UI/UI_checkbox.cpp @@ -1,11 +1,11 @@ #include "UI_checkbox.hpp" -UI_checkbox::UI_checkbox(QObject* parrent) : UI_x_boxes(UI_CHECKBOX_TYPE, parrent), m_selected() +UI_checkbox::UI_checkbox(QObject *parrent) : UI_x_boxes(UI_CHECKBOX_TYPE, parrent), m_selected() { } UI_checkbox::UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, - std::vector options, QObject* parrent) + std::vector options, QObject *parrent) : UI_x_boxes(id, UI_CHECKBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected() { for (size_t i = 0; i < m_options.size(); i++) @@ -14,7 +14,7 @@ UI_checkbox::UI_checkbox(std::string id, std::string text, Color fg_color, Color } } -UI_checkbox::UI_checkbox(const json &j, QObject* parrent) : UI_x_boxes(UI_CHECKBOX_TYPE, parrent), m_selected() +UI_checkbox::UI_checkbox(const json &j, QObject *parrent) : UI_x_boxes(UI_CHECKBOX_TYPE, parrent), m_selected() { from_json(j); } diff --git a/src/UI/UI_checkbox.hpp b/src/UI/UI_checkbox.hpp index 00d5fef..30778aa 100644 --- a/src/UI/UI_checkbox.hpp +++ b/src/UI/UI_checkbox.hpp @@ -9,9 +9,10 @@ class UI_checkbox : public UI_x_boxes { Q_OBJECT public: - UI_checkbox(QObject* parrent = nullptr); - UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector options, QObject* parrent = nullptr); - UI_checkbox(const json &j, QObject* parrent = nullptr); + UI_checkbox(QObject *parrent = nullptr); + UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector options, + QObject *parrent = nullptr); + UI_checkbox(const json &j, QObject *parrent = nullptr); void toggle_selected(size_t selected); void toggle_selected(std::string selected); diff --git a/src/UI/UI_combobox.cpp b/src/UI/UI_combobox.cpp index e7895cd..87ee693 100644 --- a/src/UI/UI_combobox.cpp +++ b/src/UI/UI_combobox.cpp @@ -1,16 +1,16 @@ #include "UI_combobox.hpp" -UI_combobox::UI_combobox(QObject* parrent) : UI_x_boxes(UI_COMBOBOX_TYPE, parrent) +UI_combobox::UI_combobox(QObject *parrent) : UI_x_boxes(UI_COMBOBOX_TYPE, parrent) { } UI_combobox::UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color, - std::vector options, size_t selected, QObject* parrent) + std::vector options, size_t selected, QObject *parrent) : UI_x_boxes(id, UI_COMBOBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected(selected) { } -UI_combobox::UI_combobox(const json &j, QObject* parrent) : UI_x_boxes(UI_COMBOBOX_TYPE, parrent) +UI_combobox::UI_combobox(const json &j, QObject *parrent) : UI_x_boxes(UI_COMBOBOX_TYPE, parrent) { from_json(j); } diff --git a/src/UI/UI_combobox.hpp b/src/UI/UI_combobox.hpp index 263124c..b795db1 100644 --- a/src/UI/UI_combobox.hpp +++ b/src/UI/UI_combobox.hpp @@ -10,10 +10,10 @@ class UI_combobox : public UI_x_boxes { Q_OBJECT public: - UI_combobox(QObject* parrent = nullptr); + UI_combobox(QObject *parrent = nullptr); UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector options, - size_t selected = 0, QObject* parrent = nullptr); - UI_combobox(const json &j, QObject* parrent = nullptr); + size_t selected = 0, QObject *parrent = nullptr); + UI_combobox(const json &j, QObject *parrent = nullptr); void set_selected(size_t selected); void set_selected(std::string selected) override; @@ -24,6 +24,7 @@ class UI_combobox : public UI_x_boxes json to_json() const override; signals: void on_change(std::string id, std::string selected); + private: size_t m_selected; }; diff --git a/src/UI/UI_dial.cpp b/src/UI/UI_dial.cpp index 43afd91..76b8147 100644 --- a/src/UI/UI_dial.cpp +++ b/src/UI/UI_dial.cpp @@ -1,11 +1,12 @@ #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_dial::UI_dial(const json &j, QObject* parrent) : UI_item(UI_DIAL_TYPE, parrent) +UI_dial::UI_dial(const json &j, QObject *parrent) : UI_item(UI_DIAL_TYPE, parrent) { from_json(j); } diff --git a/src/UI/UI_dial.hpp b/src/UI/UI_dial.hpp index 4efa557..6c3a2a6 100644 --- a/src/UI/UI_dial.hpp +++ b/src/UI/UI_dial.hpp @@ -7,8 +7,9 @@ class UI_dial : public UI_item { Q_OBJECT 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(const json &j, 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); void set_value(double value) override; double value() const; diff --git a/src/UI/UI_item.cpp b/src/UI/UI_item.cpp index 24a37e2..7bddad0 100644 --- a/src/UI/UI_item.cpp +++ b/src/UI/UI_item.cpp @@ -1,21 +1,19 @@ #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) - : 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), - enabled(true), visible(true) +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), enabled(true), visible(true) { } -UI_item::UI_item(std::string type, QObject* parrent) - : QObject(parrent), - m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black), m_bg_color(Color::White), - enabled(true), visible(true) +UI_item::UI_item(std::string type, QObject *parrent) + : QObject(parrent), m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black), + m_bg_color(Color::White), enabled(true), visible(true) { } -UI_item::UI_item(const json &j, QObject* parrent) : - QObject(parrent) +UI_item::UI_item(const json &j, QObject *parrent) : QObject(parrent) { from_json(j); } diff --git a/src/UI/UI_item.hpp b/src/UI/UI_item.hpp index e40b845..e8c9dee 100644 --- a/src/UI/UI_item.hpp +++ b/src/UI/UI_item.hpp @@ -15,9 +15,10 @@ class UI_item : public QObject { Q_OBJECT public: - 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(const json &j, 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(const json &j, QObject *parrent = nullptr); ~UI_item(); std::string id() const; diff --git a/src/UI/UI_label.cpp b/src/UI/UI_label.cpp index b4368e7..2d86e4a 100644 --- a/src/UI/UI_label.cpp +++ b/src/UI/UI_label.cpp @@ -1,11 +1,11 @@ #include "UI_label.hpp" -UI_label::UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject* parrent) +UI_label::UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent) : UI_item(id, UI_LABEL_TYPE, text, 12, fg_color, bg_color, parrent) { } -UI_label::UI_label(const json &j, QObject* parrent) : UI_item(UI_LABEL_TYPE, parrent) +UI_label::UI_label(const json &j, QObject *parrent) : UI_item(UI_LABEL_TYPE, parrent) { from_json(j); } diff --git a/src/UI/UI_label.hpp b/src/UI/UI_label.hpp index f6b8a6d..9a1a8cd 100644 --- a/src/UI/UI_label.hpp +++ b/src/UI/UI_label.hpp @@ -8,8 +8,8 @@ class UI_label : public UI_item { Q_OBJECT public: - UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject* parrent = nullptr); - UI_label(const json &j, QObject* parrent = nullptr); + UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent = nullptr); + UI_label(const json &j, QObject *parrent = nullptr); void from_json(const json &j) override; json to_json() const override; diff --git a/src/UI/UI_led.cpp b/src/UI/UI_led.cpp index 6f4f0c4..9fbedde 100644 --- a/src/UI/UI_led.cpp +++ b/src/UI/UI_led.cpp @@ -1,11 +1,11 @@ #include "UI_led.hpp" -UI_led::UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color, QObject* parrent) +UI_led::UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color, QObject *parrent) : UI_item(id, UI_LED_TYPE, text, 12, fg_color, bg_color, parrent), m_led_color(led_color) { } -UI_led::UI_led(const json &j, QObject* parrent) : UI_item(UI_LED_TYPE, parrent) +UI_led::UI_led(const json &j, QObject *parrent) : UI_item(UI_LED_TYPE, parrent) { from_json(j); } diff --git a/src/UI/UI_led.hpp b/src/UI/UI_led.hpp index 79cdc0f..6250545 100644 --- a/src/UI/UI_led.hpp +++ b/src/UI/UI_led.hpp @@ -8,8 +8,9 @@ class UI_led : public UI_item { Q_OBJECT public: - 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(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); Color led_color() const; void set_led_color(Color led_color); diff --git a/src/UI/UI_slider.cpp b/src/UI/UI_slider.cpp index 886cf32..593185b 100644 --- a/src/UI/UI_slider.cpp +++ b/src/UI/UI_slider.cpp @@ -1,13 +1,12 @@ #include "UI_slider.hpp" UI_slider::UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, - 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_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) { from_json(j); } diff --git a/src/UI/UI_slider.hpp b/src/UI/UI_slider.hpp index 2bc0bde..1ccb6e7 100644 --- a/src/UI/UI_slider.hpp +++ b/src/UI/UI_slider.hpp @@ -7,8 +7,9 @@ class UI_slider : public UI_item { Q_OBJECT 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(const json &j, 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); void set_value(double value) override; double value() const; diff --git a/src/UI/UI_textbox.cpp b/src/UI/UI_textbox.cpp index 2e092ba..0a10fb3 100644 --- a/src/UI/UI_textbox.cpp +++ b/src/UI/UI_textbox.cpp @@ -1,11 +1,11 @@ #include "UI_textbox.hpp" -UI_textbox::UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject* parrent) +UI_textbox::UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject *parrent) : UI_item(id, UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color, parrent), m_hint(hint) { } -UI_textbox::UI_textbox(const json &j, QObject* parrent) : UI_item(UI_TEXTBOX_TYPE, parrent) +UI_textbox::UI_textbox(const json &j, QObject *parrent) : UI_item(UI_TEXTBOX_TYPE, parrent) { from_json(j); } diff --git a/src/UI/UI_textbox.hpp b/src/UI/UI_textbox.hpp index 2a51c40..0f90534 100644 --- a/src/UI/UI_textbox.hpp +++ b/src/UI/UI_textbox.hpp @@ -8,8 +8,8 @@ class UI_textbox : public UI_item { Q_OBJECT public: - UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject* parrent = nullptr); - UI_textbox(const json &j, QObject* parrent = nullptr); + UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject *parrent = nullptr); + UI_textbox(const json &j, QObject *parrent = nullptr); void set_text(std::string text) override; diff --git a/src/UI/UI_thermo.cpp b/src/UI/UI_thermo.cpp index 0f461ab..fb35569 100644 --- a/src/UI/UI_thermo.cpp +++ b/src/UI/UI_thermo.cpp @@ -1,12 +1,12 @@ #include "UI_thermo.hpp" UI_thermo::UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, - double value, QObject* parrent) + double value, QObject *parrent) : UI_item(id, UI_THERMO_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value) { } -UI_thermo::UI_thermo(const json &j, QObject* parrent) : UI_item(UI_THERMO_TYPE, parrent) +UI_thermo::UI_thermo(const json &j, QObject *parrent) : UI_item(UI_THERMO_TYPE, parrent) { from_json(j); } diff --git a/src/UI/UI_thermo.hpp b/src/UI/UI_thermo.hpp index 34c57a5..dc5a1d5 100644 --- a/src/UI/UI_thermo.hpp +++ b/src/UI/UI_thermo.hpp @@ -8,8 +8,9 @@ class UI_thermo : public UI_item { Q_OBJECT 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(const json &j, 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); void set_value(double value) override; double value() const; diff --git a/src/UI/UI_x_boxes.cpp b/src/UI/UI_x_boxes.cpp index 150a3c0..89d544e 100644 --- a/src/UI/UI_x_boxes.cpp +++ b/src/UI/UI_x_boxes.cpp @@ -1,11 +1,11 @@ #include "UI_x_boxes.hpp" -UI_x_boxes::UI_x_boxes(std::string type, QObject* parrent) : UI_item(type, parrent), m_options() +UI_x_boxes::UI_x_boxes(std::string type, QObject *parrent) : UI_item(type, parrent), m_options() { } UI_x_boxes::UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color, - std::vector options, QObject* parrent) + std::vector options, QObject *parrent) : UI_item(id, type, text, 12, fg_color, bg_color, parrent), m_options(options) { } diff --git a/src/UI/UI_x_boxes.hpp b/src/UI/UI_x_boxes.hpp index 90562c6..18d8f91 100644 --- a/src/UI/UI_x_boxes.hpp +++ b/src/UI/UI_x_boxes.hpp @@ -6,9 +6,9 @@ class UI_x_boxes : public UI_item { Q_OBJECT public: - UI_x_boxes(std::string type, QObject* parrent = nullptr); + UI_x_boxes(std::string type, QObject *parrent = nullptr); UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color, - std::vector options, QObject* parrent = nullptr); + std::vector options, QObject *parrent = nullptr); void from_json(const json &j) override; json to_json() const override; diff --git a/tools/main.cpp b/tools/main.cpp index 5887b20..6135648 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include #include "spdlog/async.h" #include "spdlog/sinks/rotating_file_sink.h" @@ -32,7 +32,8 @@ int main(int argc, char *argv[]) parser.setApplicationDescription("QtWebSockets example: echoserver"); parser.addHelpOption(); - QCommandLineOption portOption(QStringList() << "p" << "port", + QCommandLineOption portOption(QStringList() << "p" + << "port", QCoreApplication::translate("main", "Port for echoserver [default: 9002]."), QCoreApplication::translate("main", "port"), QLatin1String("9002")); parser.addOption(portOption); diff --git a/tools/message_parser.cpp b/tools/message_parser.cpp index 376f2b6..656058e 100644 --- a/tools/message_parser.cpp +++ b/tools/message_parser.cpp @@ -32,8 +32,7 @@ json Simulators::command_parser(json command) case Command::get_UI_element: spdlog::info("Command {}: {}", type, std::string(command.at("id"))); j["response"]["type"] = type; - j["response"]["UI_item"] = - invoke_active_simulator()->get_UI_item(command.at("id"))->to_json(); + j["response"]["UI_item"] = invoke_active_simulator()->get_UI_item(command.at("id"))->to_json(); break; case Command::get_UI_elements: spdlog::info("Command {}", type); @@ -88,9 +87,7 @@ void Simulators::event_handler(json event) } case Event::value_changed: { spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), (double)(event["value"])); - invoke_active_simulator() - ->get_UI_item(std::string(event.at("id"))) - ->set_value((double)event.at("value")); + invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_value((double)event.at("value")); break; } case Event::text_changed: { diff --git a/tools/simulator_base.cpp b/tools/simulator_base.cpp index 294725f..1678199 100644 --- a/tools/simulator_base.cpp +++ b/tools/simulator_base.cpp @@ -1,9 +1,9 @@ #include "simulator_base.hpp" -Simulator_base::Simulator_base(std::string name, std::chrono::milliseconds interval, QObject* parrent) +Simulator_base::Simulator_base(std::string name, std::chrono::milliseconds interval, QObject *parrent) : QObject(parrent), m_name(name), m_timer(new QTimer(this)), m_interval(interval) { - connect(m_timer, &QTimer::timeout, this, [this]{timer();}); + connect(m_timer, &QTimer::timeout, this, [this] { timer(); }); } std::string Simulator_base::name() const @@ -33,7 +33,7 @@ void Simulator_base::add_UI_item(UI_item *item) { throw std::runtime_error("UI item id " + item->id() + " is not unique"); } - connect(item, &UI_item::value_changed, this, [this]{emit sim_changed();}); + connect(item, &UI_item::value_changed, this, [this] { emit sim_changed(); }); m_UI_items_map[item->id()] = item; m_UI_items.push_back(item); } diff --git a/tools/simulator_base.hpp b/tools/simulator_base.hpp index 8190200..2062041 100644 --- a/tools/simulator_base.hpp +++ b/tools/simulator_base.hpp @@ -14,7 +14,8 @@ class Simulator_base : public QObject * @param name The name of the simulator * @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 @@ -89,6 +90,6 @@ class Simulator_base : public QObject std::string m_name; std::vector m_UI_items; std::map m_UI_items_map; - QTimer* m_timer; + QTimer *m_timer; std::chrono::milliseconds m_interval; }; diff --git a/tools/simulators.cpp b/tools/simulators.cpp index 7aff4e8..80fdf88 100644 --- a/tools/simulators.cpp +++ b/tools/simulators.cpp @@ -1,12 +1,10 @@ #include "simulators.hpp" #include "can_debugger.hpp" #include "test_sim.hpp" -#include #include +#include -Simulators::Simulators(uint16_t port, QObject* parrent) : - QObject(parrent), - m_server(new Websocket(port, this)) +Simulators::Simulators(uint16_t port, QObject *parrent) : QObject(parrent), m_server(new Websocket(port, this)) { qDebug() << port; INSERT_SIMULATOR(Test_Sim); @@ -16,7 +14,7 @@ Simulators::Simulators(uint16_t port, QObject* parrent) : void Simulators::setup_connections() { - connect(m_server, &Websocket::on_message, this, [this](QWebSocket* conn, QString message){ + connect(m_server, &Websocket::on_message, this, [this](QWebSocket *conn, QString message) { QString response = message_parser(message); if (response.isEmpty() || response == "{}") return; @@ -80,7 +78,8 @@ void Simulators::switch_simulator(std::string name) disconnect(m_simulators.at(m_current_simulator).get()); } 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(); } diff --git a/tools/simulators.hpp b/tools/simulators.hpp index a367e04..4c7337c 100644 --- a/tools/simulators.hpp +++ b/tools/simulators.hpp @@ -3,8 +3,8 @@ #include #include -#include "websocket.hpp" #include "simulator_base.hpp" +#include "websocket.hpp" #define INSERT_SIMULATOR(type) m_simulators.insert(std::make_pair(type().name(), std::make_unique())); @@ -44,7 +44,7 @@ class Simulators : public QObject Simulator_base *invoke_active_simulator(); json changed_UI_items(); - //parsing of websocket messages + // parsing of websocket messages QString message_parser(QString message); json command_parser(json command); void event_handler(json event); diff --git a/tools/websocket.cpp b/tools/websocket.cpp index d430918..0831292 100644 --- a/tools/websocket.cpp +++ b/tools/websocket.cpp @@ -1,17 +1,16 @@ #include "websocket.hpp" -#include "QtWebSockets/qwebsocketserver.h" #include "QtWebSockets/qwebsocket.h" +#include "QtWebSockets/qwebsocketserver.h" #include -Websocket::Websocket(uint16_t port, QObject *parent) : - QObject(parent), - m_pWebSocketServer(new QWebSocketServer(QStringLiteral("sim_us Server"), - QWebSocketServer::NonSecureMode, this)) +Websocket::Websocket(uint16_t port, QObject *parent) + : QObject(parent), + m_pWebSocketServer(new QWebSocketServer(QStringLiteral("sim_us Server"), QWebSocketServer::NonSecureMode, this)) { - if (m_pWebSocketServer->listen(QHostAddress::Any, port)) { + if (m_pWebSocketServer->listen(QHostAddress::Any, port)) + { spdlog::debug("Echoserver listening on port {}", port); - connect(m_pWebSocketServer, &QWebSocketServer::newConnection, - this, &Websocket::onNewConnection); + connect(m_pWebSocketServer, &QWebSocketServer::newConnection, this, &Websocket::onNewConnection); connect(m_pWebSocketServer, &QWebSocketServer::closed, this, &Websocket::closed); } } @@ -24,12 +23,13 @@ Websocket::~Websocket() void Websocket::broadcast(QString message) { - foreach (QWebSocket* conn, m_clients) { + foreach (QWebSocket *conn, m_clients) + { conn->sendTextMessage(message); } } -void Websocket::send(QWebSocket* conn, QString message) +void Websocket::send(QWebSocket *conn, QString message) { conn->sendTextMessage(message); spdlog::trace("sending message: {}", message.toStdString()); @@ -66,7 +66,8 @@ void Websocket::socketDisconnected() { QWebSocket *pClient = qobject_cast(sender()); spdlog::debug("socket Disconnected"); - if (pClient) { + if (pClient) + { m_clients.removeAll(pClient); pClient->deleteLater(); } diff --git a/tools/websocket.hpp b/tools/websocket.hpp index 0d0118f..879878d 100644 --- a/tools/websocket.hpp +++ b/tools/websocket.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include #include +#include +#include QT_FORWARD_DECLARE_CLASS(QWebSocketServer) QT_FORWARD_DECLARE_CLASS(QWebSocket) @@ -16,9 +16,9 @@ class Websocket : public QObject ~Websocket(); void broadcast(QString message); - void send(QWebSocket* conn, QString message); + void send(QWebSocket *conn, QString message); signals: - void on_message(QWebSocket* conn, QString message); + void on_message(QWebSocket *conn, QString message); void closed(); private slots: