From cb41ac2aa2835a685a2a978c65a2f1364122e84b Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Mon, 18 May 2026 16:41:07 +0200 Subject: [PATCH] Update UI --- UI/CMakeLists.txt | 13 +--- UI/enum/ui_enum.hpp | 25 ------ UI/ui_button.cpp | 41 +++++++--- UI/ui_button.hpp | 23 +++--- UI/ui_can.cpp | 94 ++++++----------------- UI/ui_can.hpp | 20 +---- UI/ui_checkbox.cpp | 69 +++++++++++------ UI/ui_checkbox.hpp | 36 ++++----- UI/ui_combobox.cpp | 54 ++++--------- UI/ui_combobox.hpp | 35 +++------ UI/ui_dial.cpp | 62 +++++---------- UI/ui_dial.hpp | 55 +------------ UI/ui_double_spinbox.cpp | 46 ++++------- UI/ui_double_spinbox.hpp | 19 ----- UI/ui_hex_spinbox.cpp | 46 ++++------- UI/ui_hex_spinbox.hpp | 19 ----- UI/ui_item.cpp | 159 ++++++++------------------------------ UI/ui_item.hpp | 162 ++++----------------------------------- UI/ui_label.cpp | 46 +++++++++-- UI/ui_label.hpp | 29 ++++--- UI/ui_led.cpp | 52 +++++++++---- UI/ui_led.hpp | 33 ++++---- UI/ui_plot.cpp | 99 ++++++++++++++---------- UI/ui_plot.hpp | 58 +++++++------- UI/ui_slider.cpp | 62 +++++---------- UI/ui_slider.hpp | 48 +----------- UI/ui_spinbox.cpp | 46 ++++------- UI/ui_spinbox.hpp | 19 ----- UI/ui_stacked_widget.cpp | 38 ++++----- UI/ui_stacked_widget.hpp | 24 +----- UI/ui_status_bar.cpp | 39 ++++------ UI/ui_status_bar.hpp | 25 +----- UI/ui_tab_widget.cpp | 90 ++++++++-------------- UI/ui_tab_widget.hpp | 35 ++------- UI/ui_table.cpp | 154 +++++++++++++++++++------------------ UI/ui_table.hpp | 56 ++++---------- UI/ui_textbox.cpp | 64 ++++++++++------ UI/ui_textbox.hpp | 36 ++++----- UI/ui_thermo.cpp | 130 ++++++++++++------------------- UI/ui_thermo.hpp | 48 +----------- 40 files changed, 773 insertions(+), 1436 deletions(-) delete mode 100644 UI/enum/ui_enum.hpp diff --git a/UI/CMakeLists.txt b/UI/CMakeLists.txt index b31d794..1fc73f8 100644 --- a/UI/CMakeLists.txt +++ b/UI/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) -if(NOT EMSCRIPTEN) + add_library(UI STATIC) find_package(Qt6 REQUIRED COMPONENTS Core SerialBus) @@ -33,17 +33,8 @@ target_include_directories(UI target_link_libraries(UI PUBLIC Color - nlohmann_json::nlohmann_json magic_enum::magic_enum Qt::Core Qt::SerialBus - UI_enum -) -endif() - -add_library(UI_enum INTERFACE) - -target_include_directories(UI_enum - INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/enum + proto-ui ) \ No newline at end of file diff --git a/UI/enum/ui_enum.hpp b/UI/enum/ui_enum.hpp deleted file mode 100644 index 976207a..0000000 --- a/UI/enum/ui_enum.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -enum class UI_enum -{ - ui_button, - ui_can, - ui_checkbox, - ui_combobox, - ui_dial, - ui_double_spinbox, - ui_hex_spinbox, - ui_label, - ui_led, - ui_plot, - ui_slider, - ui_spinbox, - ui_stacked_widget, - ui_status_bar, - ui_tab_widget, - ui_table, - ui_textbox, - ui_thermo, - end, - begin = 0 -}; diff --git a/UI/ui_button.cpp b/UI/ui_button.cpp index bcc1b98..8ab4474 100644 --- a/UI/ui_button.cpp +++ b/UI/ui_button.cpp @@ -1,24 +1,47 @@ #include "ui_button.hpp" -#include "ui_enum.hpp" -UI_button::UI_button(std::string text, Color fg_color, Color bg_color, QObject *parent) - : UI_item(UI_enum::ui_button, text, fg_color, bg_color, parent) +UI_button::UI_button(QString text, Color fg_color, Color bg_color, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_button, parent) { + m_ui_item.setLabel(UI_label_m()); + m_ui_item.label().setText(text); + m_ui_item.label().mutColor().setFgColor(fg_color.color()); + m_ui_item.label().mutColor().setBgColor(bg_color.color()); } -UI_button::UI_button(QObject *parent) : UI_item(UI_enum::ui_button, parent) +UI_button::UI_button(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_button, parent) { + m_ui_item.setLabel(UI_label_m()); } -void UI_button::from_json(const json &j) +void UI_button::set_text(QString text) { - UI_item::from_json(j); + m_ui_item.label().setText(text); } -json UI_button::to_json(size_t id) const +QString UI_button::text() const { - json j = UI_item::to_json(id); - return j; + return m_ui_item.label().text(); +} + +void UI_button::set_fg_color(Color color) +{ + m_ui_item.label().mutColor().setFgColor(color.color()); +} + +Color UI_button::fg_color() const +{ + return Color(m_ui_item.label().color().fgColor()); +} + +void UI_button::set_bg_color(Color color) +{ + m_ui_item.label().mutColor().setBgColor(color.color()); +} + +Color UI_button::bg_color() const +{ + return Color(m_ui_item.label().color().bgColor()); } void UI_button::click() diff --git a/UI/ui_button.hpp b/UI/ui_button.hpp index 6b03a11..2244adc 100644 --- a/UI/ui_button.hpp +++ b/UI/ui_button.hpp @@ -17,7 +17,7 @@ class UI_button : public UI_item * @param bg_color The background color of the button * @param parent The parent QObject */ - UI_button(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + UI_button(QString text, Color fg_color, Color bg_color, QObject *parent = nullptr); /** * @brief Construct a UI button object * @@ -26,18 +26,21 @@ class UI_button : public UI_item UI_button(QObject *parent = nullptr); /** - * @brief Deserialize the button from JSON - * - * @param j The JSON object + * @brief set_text + * @param text The text field of the button */ - void from_json(const json &j) override; + void set_text(QString text) override; + /** - * @brief Serialize the button to JSON - * - * @param id The id of the button - * @return json The JSON representation of the button + * @brief text + * @return The text field of the button */ - json to_json(size_t id) const override; + QString text() const; + + void set_fg_color(Color fg_color); + Color fg_color() const; + void set_bg_color(Color bg_color); + Color bg_color() const; /** * @brief Handle a click event on the button diff --git a/UI/ui_can.cpp b/UI/ui_can.cpp index 4946612..6075e87 100644 --- a/UI/ui_can.cpp +++ b/UI/ui_can.cpp @@ -1,53 +1,49 @@ #include "ui_can.hpp" -template T ByteArrayToStdArray(const QByteArray &byteArray) -{ - T stdArray; - - for (unsigned int i = 0; i < stdArray.size() && i < (unsigned int)byteArray.size(); i++) - { - stdArray[i] = (unsigned char)byteArray.at(i); - } - - return stdArray; -} - UI_can::UI_can(Color fg_color, Color bg_color, QObject *parent) - : UI_item(UI_enum::ui_can, "", fg_color, bg_color, parent) + : UI_item(UI_typeGadget::UI_type::ui_can, parent) { - setup_item(false, true, true); + m_ui_item.can().mutColor().setFgColor(fg_color.color()); + m_ui_item.can().mutColor().setBgColor(bg_color.color()); } -UI_can::UI_can(QObject *parent) : UI_item(UI_enum::ui_can, parent) +UI_can::UI_can(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_can, parent) { - setup_item(false, true, true); } void UI_can::add_send_message(QCanBusFrame msg) { - CanFrame frame(msg.frameId(), (uint8_t)msg.payload().size(), - ByteArrayToStdArray>(msg.payload())); - m_can_send_messages.push_back(frame); + CAN_Frame_m frame;(msg.frameId(), msg.payload().size(), msg.payload()); + frame.setSid(msg.frameId()); + frame.setDlc(msg.payload().size()); + frame.setPayload(msg.payload()); + auto send_frames = m_ui_item.can().sendFrames(); + send_frames.append(frame); + m_ui_item.can().setSendFrames(send_frames); emit ui_changed(); } void UI_can::add_received_message(QCanBusFrame msg) { - CanFrame frame(msg.frameId(), (uint8_t)msg.payload().size(), - ByteArrayToStdArray>(msg.payload())); - m_can_received_messages.push_back(frame); + CAN_Frame_m frame;(msg.frameId(), msg.payload().size(), msg.payload()); + frame.setSid(msg.frameId()); + frame.setDlc(msg.payload().size()); + frame.setPayload(msg.payload()); + auto recv_frames = m_ui_item.can().recvFrames(); + recv_frames.append(frame); + m_ui_item.can().setRecvFrames(recv_frames); emit ui_changed(); } void UI_can::clear_send_buffer() { - m_can_send_messages.clear(); + m_ui_item.can().setSendFrames(QList()); emit ui_changed(); } void UI_can::clear_receive_buffer() { - m_can_received_messages.clear(); + m_ui_item.can().setSendFrames(QList()); emit ui_changed(); } @@ -57,56 +53,12 @@ void UI_can::clear() clear_receive_buffer(); } -void UI_can::from_json(const json &j) -{ - UI_item::from_json(j); - m_can_send_messages.clear(); - m_can_received_messages.clear(); - for (const auto &msg : j.at("send_msgs")) - { - CanFrame can_msg(msg.at("id"), msg.at("dlc"), msg.at("payload")); - m_can_send_messages.push_back(can_msg); - } - for (const auto &msg : j.at("rcvd_msgs")) - { - CanFrame can_msg(msg.at("id"), msg.at("dlc"), msg.at("payload")); - m_can_received_messages.push_back(can_msg); - } -} - -json UI_can::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - json can_send_messages = json::array(); - json can_received_messages = json::array(); - for (const auto &msg : m_can_send_messages) - { - json can_msg; - can_msg["id"] = (uint32_t)msg.m_SID; - can_msg["dlc"] = msg.m_DLC; - can_msg["payload"] = msg.m_payload; - - can_send_messages.push_back(can_msg); - } - j["send_msgs"] = can_send_messages; - for (const auto &msg : m_can_received_messages) - { - json can_msg; - can_msg["id"] = (uint32_t)msg.m_SID; - can_msg["dlc"] = msg.m_DLC; - can_msg["payload"] = msg.m_payload; - - can_received_messages.push_back(can_msg); - } - j["rcvd_msgs"] = can_received_messages; - return j; -} - -void UI_can::can_send(uint32_t id, uint8_t dlc, std::array payload) +void UI_can::can_send(uint32_t id, uint64_t dlc, QByteArray payload) { QCanBusFrame frame; + Q_UNUSED(dlc); frame.setFrameId(id); - frame.setPayload(QByteArray::fromRawData((const char *)(payload.data()), dlc)); + frame.setPayload(payload); emit send(frame); } diff --git a/UI/ui_can.hpp b/UI/ui_can.hpp index 89d10b8..eb1fac2 100644 --- a/UI/ui_can.hpp +++ b/UI/ui_can.hpp @@ -83,20 +83,6 @@ class UI_can : public UI_item */ void clear_receive_buffer(); - /** - * @brief Deserialize the CAN item from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the CAN item to JSON - * - * @param id The id of the CAN item - * @return json The JSON representation of the CAN item - */ - json to_json(size_t id) const override; - /** * @brief Handle a CAN send event * @@ -104,7 +90,7 @@ class UI_can : public UI_item * @param dlc The data length code * @param payload The data payload */ - void can_send(uint32_t id, uint8_t dlc, std::array payload) override; + void can_send(uint32_t id, uint64_t dlc, QByteArray payload) override; /** * @brief Clear the CAN item * @@ -116,8 +102,4 @@ class UI_can : public UI_item * @param msg The CAN message sent */ void send(QCanBusFrame msg); - - private: - std::vector m_can_send_messages; - std::vector m_can_received_messages; }; diff --git a/UI/ui_checkbox.cpp b/UI/ui_checkbox.cpp index 409104c..5278d0b 100644 --- a/UI/ui_checkbox.cpp +++ b/UI/ui_checkbox.cpp @@ -1,46 +1,65 @@ #include "ui_checkbox.hpp" -UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_enum::ui_checkbox, parent), m_checked() +UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_checkbox, parent) { + m_ui_item.setCheckbox(UI_checkbox_m()); } -UI_checkbox::UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent) - : UI_item(UI_enum::ui_checkbox, text, fg_color, bg_color, parent), m_checked(false) +UI_checkbox::UI_checkbox(QString text, Color fg_color, Color bg_color, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_checkbox, parent) { + m_ui_item.setCheckbox(UI_checkbox_m()); + m_ui_item.checkbox().setText(text); + m_ui_item.checkbox().setChecked(false); + m_ui_item.label().mutColor().setFgColor(fg_color.color()); + m_ui_item.label().mutColor().setBgColor(bg_color.color()); +} + +void UI_checkbox::set_text(QString text) +{ + m_ui_item.label().setText(text); +} + +QString UI_checkbox::text() const +{ + return m_ui_item.label().text(); +} + +void UI_checkbox::set_fg_color(Color color) +{ + m_ui_item.label().mutColor().setFgColor(color.color()); +} + +Color UI_checkbox::fg_color() const +{ + return Color(m_ui_item.label().color().fgColor()); +} + +void UI_checkbox::set_bg_color(Color color) +{ + m_ui_item.label().mutColor().setBgColor(color.color()); +} + +Color UI_checkbox::bg_color() const +{ + return Color(m_ui_item.label().color().bgColor()); } void UI_checkbox::click() { - m_checked = !m_checked; + m_ui_item.checkbox().setChecked(!m_ui_item.checkbox().checked()); emit ui_changed(); - emit changed(m_checked); + emit changed(m_ui_item.checkbox().checked()); } void UI_checkbox::set_state(bool state) { - m_checked = state; + m_ui_item.checkbox().setChecked(state); emit ui_changed(); - emit changed(m_checked); + emit changed(m_ui_item.checkbox().checked()); } bool UI_checkbox::state() const { - return m_checked; -} - -void UI_checkbox::from_json(const json &j) -{ - UI_item::from_json(j); - - if (j.contains("checked")) - { - m_checked = j["checked"]; - } -} - -json UI_checkbox::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["checked"] = m_checked; - return j; + return m_ui_item.checkbox().checked(); } diff --git a/UI/ui_checkbox.hpp b/UI/ui_checkbox.hpp index 6321a5a..6ac4ebc 100644 --- a/UI/ui_checkbox.hpp +++ b/UI/ui_checkbox.hpp @@ -23,7 +23,24 @@ class UI_checkbox : public UI_item * @param bg_color The background color * @param parent The parent QObject */ - UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + UI_checkbox(QString text, Color fg_color, Color bg_color, QObject *parent = nullptr); + + /** + * @brief set_text + * @param text The text field of the button + */ + void set_text(QString text) override; + + /** + * @brief text + * @return The text field of the button + */ + QString text() const; + + void set_fg_color(Color fg_color); + Color fg_color() const; + void set_bg_color(Color bg_color); + Color bg_color() const; /** * @brief Handle a click event on the checkbox @@ -44,20 +61,6 @@ class UI_checkbox : public UI_item */ bool state() const; - /** - * @brief Deserialize the checkbox from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the checkbox to JSON - * - * @param id The id of the checkbox - * @return json The JSON representation of the checkbox - */ - json to_json(size_t id) const override; - signals: /** * @brief Signal emitted when the checkbox state changes @@ -65,7 +68,4 @@ class UI_checkbox : public UI_item * @param checked The new state of the checkbox */ void changed(bool checked); - - private: - bool m_checked; }; diff --git a/UI/ui_combobox.cpp b/UI/ui_combobox.cpp index f14d324..0706af8 100644 --- a/UI/ui_combobox.cpp +++ b/UI/ui_combobox.cpp @@ -1,31 +1,33 @@ #include "ui_combobox.hpp" -UI_combobox::UI_combobox(QObject *parent) : UI_item(UI_enum::ui_combobox, parent), m_options() +UI_combobox::UI_combobox(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_combobox, parent) { - setup_item(false, true, true); + m_ui_item.setCombobox(UI_combobox_m()); } -UI_combobox::UI_combobox(Color fg_color, Color bg_color, std::vector options, size_t selected, +UI_combobox::UI_combobox(QList options, qsizetype selected, QObject *parent) - : UI_item(UI_enum::ui_combobox, "", fg_color, bg_color, parent), m_options(options), m_selected(selected) + : UI_item(UI_typeGadget::UI_type::ui_combobox, parent) { - setup_item(false, true, true); + m_ui_item.setCombobox(UI_combobox_m()); + m_ui_item.combobox().setOptions(options); + m_ui_item.combobox().setSelected(selected); } -void UI_combobox::set_selected(size_t selected) +void UI_combobox::set_selected(qsizetype selected) { - if (selected == m_selected) + if (selected == m_ui_item.combobox().selected()) return; - m_selected = std::move(selected); + m_ui_item.combobox().setSelected(selected); emit ui_changed(); emit changed(selected_text()); } -void UI_combobox::set_selected(std::string selected) +void UI_combobox::set_selected(QString selected) { - for (size_t i = 0; i < m_options.size(); i++) + for (qsizetype i = 0; i < m_ui_item.combobox().options().size(); i++) { - if (m_options[i] == selected) + if (m_ui_item.combobox().options().at(i) == selected) { set_selected(i); return; @@ -33,34 +35,12 @@ void UI_combobox::set_selected(std::string selected) } } -size_t UI_combobox::selected() const +qsizetype UI_combobox::selected() const { - return m_selected; + return m_ui_item.combobox().selected(); } -std::string UI_combobox::selected_text() const & +QString UI_combobox::selected_text() const & { - return m_options[m_selected]; -} - -void UI_combobox::from_json(const json &j) -{ - UI_item::from_json(j); - if (j.contains("options")) - { - this->m_options.clear(); - for (auto &option : j["options"]) - { - this->m_options.push_back(option); - } - } - m_selected = j.at("selected"); -} - -json UI_combobox::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["options"] = this->m_options; - j["selected"] = m_selected; - return j; + return m_ui_item.combobox().options().at(m_ui_item.combobox().selected()); } diff --git a/UI/ui_combobox.hpp b/UI/ui_combobox.hpp index 7912914..01584ef 100644 --- a/UI/ui_combobox.hpp +++ b/UI/ui_combobox.hpp @@ -24,56 +24,43 @@ class UI_combobox : public UI_item * @param selected The initially selected option * @param parent The parent QObject */ - UI_combobox(Color fg_color, Color bg_color, std::vector options, size_t selected = 0, + UI_combobox(QList options, qsizetype selected = 0, QObject *parent = nullptr); + void set_fg_color(Color fg_color); + Color fg_color() const; + void set_bg_color(Color bg_color); + Color bg_color() const; + /** * @brief Set the selected option by index * * @param selected The index of the option to select */ - void set_selected(size_t selected) override; + void set_selected(qsizetype selected) override; /** * @brief Set the selected option by text * * @param selected The text of the option to select */ - void set_selected(std::string selected); + void set_selected(QString selected); /** * @brief Get the index of the selected option * * @return size_t The index of the selected option */ - size_t selected() const; + qsizetype selected() const; /** * @brief Get the text of the selected option * * @return std::string The text of the selected option */ - std::string selected_text() const &; - - /** - * @brief Deserialize the combobox from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the combobox to JSON - * - * @param id The id of the combobox - * @return json The JSON representation of the combobox - */ - json to_json(size_t id) const override; + QString selected_text() const &; signals: /** * @brief Signal emitted when the selected option changes * * @param selected The text of the newly selected option */ - void changed(std::string selected); - - private: - std::vector m_options; - size_t m_selected; + void changed(QString selected); }; diff --git a/UI/ui_dial.cpp b/UI/ui_dial.cpp index 778c569..7fbbb57 100644 --- a/UI/ui_dial.cpp +++ b/UI/ui_dial.cpp @@ -1,78 +1,54 @@ #include "ui_dial.hpp" -UI_dial::UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, +UI_dial::UI_dial(QString text, QString unit, double min, double max, double value, QObject *parent) - : UI_item(UI_enum::ui_dial, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit) + : UI_item(UI_typeGadget::UI_type::ui_dial, parent) { + m_ui_item.setRange(UI_range_m()); + m_ui_item.range().setText(text); + m_ui_item.range().setUnit(unit); + m_ui_item.range().setMin(min); + m_ui_item.range().setMax(max); + m_ui_item.range().setValue(value); } -UI_dial::UI_dial(std::string text, std::string unit, double min, double max, double value, QObject *parent) - : UI_dial(text, unit, Color::Default, Color::Default, min, max, value, parent) -{ -} - -UI_dial::UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value, +UI_dial::UI_dial(QString text, double min, double max, double value, QObject *parent) - : UI_dial(text, "", fg_color, bg_color, min, max, value, parent) + : UI_dial(text, "", min, max, value, parent) { } -UI_dial::UI_dial(std::string text, double min, double max, double value, QObject *parent) - : UI_dial(text, "", Color::Default, Color::Default, min, max, value, parent) -{ -} - -UI_dial::UI_dial(QObject *parent) : UI_item(UI_enum::ui_dial, parent) +UI_dial::UI_dial(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_dial, parent) { } void UI_dial::set_value(double value) { - if (value < m_min || value > m_max) + if (value < m_ui_item.range().min() || value > m_ui_item.range().max()) return; - if (value == m_value) + if (value == m_ui_item.range().value()) return; - this->m_value = value; + m_ui_item.range().setValue(value); emit ui_changed(); } double UI_dial::value() const { - return m_value; + return m_ui_item.range().value(); } double UI_dial::min() const { - return m_min; + return m_ui_item.range().min(); } double UI_dial::max() const { - return m_max; + return m_ui_item.range().max(); } -std::string UI_dial::unit() const & +QString UI_dial::unit() const & { - return m_unit; -} - -void UI_dial::from_json(const json &j) -{ - UI_item::from_json(j); - - this->m_min = j.at("min"); - this->m_max = j.at("max"); - this->m_value = j.at("value"); - this->m_unit = j.at("unit"); -} - -json UI_dial::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["min"] = this->m_min; - j["max"] = this->m_max; - j["value"] = this->m_value; - j["unit"] = this->m_unit; - return j; + return m_ui_item.range().unit(); } diff --git a/UI/ui_dial.hpp b/UI/ui_dial.hpp index 1dd4c62..119d159 100644 --- a/UI/ui_dial.hpp +++ b/UI/ui_dial.hpp @@ -14,39 +14,12 @@ class UI_dial : public UI_item * * @param text The text to display * @param unit The unit of the dial - * @param fg_color The foreground color - * @param bg_color The background color * @param min The minimum value * @param max The maximum value * @param value The initial value * @param parent The parent QObject */ - UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, - QObject *parent = nullptr); - /** - * @brief Construct a UI dial object - * - * @param text The text to display - * @param unit The unit of the dial - * @param min The minimum value - * @param max The maximum value - * @param value The initial value - * @param parent The parent QObject - */ - UI_dial(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); - /** - * @brief Construct a UI dial object - * - * @param text The text to display - * @param fg_color The foreground color - * @param bg_color The background color - * @param min The minimum value - * @param max The maximum value - * @param value The initial value - * @param parent The parent QObject - */ - UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value, - QObject *parent = nullptr); + UI_dial(QString text, QString unit, double min, double max, double value, QObject *parent = nullptr); /** * @brief Construct a UI dial object * @@ -56,7 +29,7 @@ class UI_dial : public UI_item * @param value The initial value * @param parent The parent QObject */ - UI_dial(std::string text, double min, double max, double value, QObject *parent = nullptr); + UI_dial(QString text, double min, double max, double value, QObject *parent = nullptr); /** * @brief Construct a UI dial object * @@ -92,27 +65,7 @@ class UI_dial : public UI_item /** * @brief Get the unit of the dial * - * @return std::string The unit of the dial + * @return QString The unit of the dial */ - std::string unit() const &; - - /** - * @brief Deserialize the dial from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the dial to JSON - * - * @param id The id of the dial - * @return json The JSON representation of the dial - */ - json to_json(size_t id) const override; - - private: - double m_min; - double m_max; - double m_value; - std::string m_unit; + QString unit() const &; }; diff --git a/UI/ui_double_spinbox.cpp b/UI/ui_double_spinbox.cpp index a4c4e64..533259a 100644 --- a/UI/ui_double_spinbox.cpp +++ b/UI/ui_double_spinbox.cpp @@ -1,58 +1,40 @@ #include "ui_double_spinbox.hpp" -UI_double_spinbox::UI_double_spinbox(QObject *parent) : UI_item(UI_enum::ui_double_spinbox, parent) +UI_double_spinbox::UI_double_spinbox(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_double_spinbox, parent) { - setup_item(false, false, false); + m_ui_item.setSpinbox(UI_spinbox_m()); } UI_double_spinbox::UI_double_spinbox(double min, double max, double value, QObject *parent) - : UI_item(UI_enum::ui_double_spinbox, parent) + : UI_item(UI_typeGadget::UI_type::ui_double_spinbox, parent) { - setup_item(false, false, false); - m_min = min; - m_max = max; - m_value = value; + m_ui_item.setSpinbox(UI_spinbox_m()); + m_ui_item.spinbox().setMin(min); + m_ui_item.spinbox().setMax(max); + m_ui_item.spinbox().setValue(value); } void UI_double_spinbox::set_value(double value) { - if (value < m_min || value > m_max) + if (value < m_ui_item.spinbox().min() || value > m_ui_item.spinbox().max()) return; - if (value == m_value) + if (value == m_ui_item.spinbox().value()) return; - this->m_value = value; + m_ui_item.spinbox().setValue(value); emit ui_changed(); - emit changed(m_value); + emit changed(m_ui_item.spinbox().value()); } double UI_double_spinbox::value() const { - return m_value; + return m_ui_item.spinbox().value(); } double UI_double_spinbox::min() const { - return m_min; + return m_ui_item.spinbox().min(); } double UI_double_spinbox::max() const { - return m_max; -} - -void UI_double_spinbox::from_json(const json &j) -{ - UI_item::from_json(j); - - this->m_min = j.at("min"); - this->m_max = j.at("max"); - this->m_value = j.at("value"); -} - -json UI_double_spinbox::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["min"] = this->m_min; - j["max"] = this->m_max; - j["value"] = this->m_value; - return j; + return m_ui_item.spinbox().max(); } diff --git a/UI/ui_double_spinbox.hpp b/UI/ui_double_spinbox.hpp index dd96f60..2b80aa2 100644 --- a/UI/ui_double_spinbox.hpp +++ b/UI/ui_double_spinbox.hpp @@ -50,20 +50,6 @@ class UI_double_spinbox : public UI_item * @return double The maximum value */ double max() const; - - /** - * @brief Deserialize the double spinbox from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the double spinbox to JSON - * - * @param id The id of the double spinbox - * @return json The JSON representation of the double spinbox - */ - json to_json(size_t id) const override; signals: /** * @brief Signal emitted when the double spinbox value changes @@ -71,9 +57,4 @@ class UI_double_spinbox : public UI_item * @param value The new value */ void changed(double value); - - private: - double m_min; - double m_max; - double m_value; }; diff --git a/UI/ui_hex_spinbox.cpp b/UI/ui_hex_spinbox.cpp index 1ec194a..f6eb6a1 100644 --- a/UI/ui_hex_spinbox.cpp +++ b/UI/ui_hex_spinbox.cpp @@ -1,58 +1,40 @@ #include "ui_hex_spinbox.hpp" -UI_hex_spinbox::UI_hex_spinbox(QObject *parent) : UI_item(UI_enum::ui_hex_spinbox, parent) +UI_hex_spinbox::UI_hex_spinbox(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_hex_spinbox, parent) { - setup_item(false, false, false); + m_ui_item.setSpinbox(UI_spinbox_m()); } UI_hex_spinbox::UI_hex_spinbox(double min, double max, double value, QObject *parent) - : UI_item(UI_enum::ui_hex_spinbox, parent) + : UI_item(UI_typeGadget::UI_type::ui_hex_spinbox, parent) { - setup_item(false, false, false); - m_min = min; - m_max = max; - m_value = value; + m_ui_item.setSpinbox(UI_spinbox_m()); + m_ui_item.spinbox().setMin(min); + m_ui_item.spinbox().setMax(max); + m_ui_item.spinbox().setValue(value); } void UI_hex_spinbox::set_value(double value) { - if (value < m_min || value > m_max) + if (value < m_ui_item.spinbox().min() || value > m_ui_item.spinbox().max()) return; - if (value == m_value) + if (value == m_ui_item.spinbox().value()) return; - this->m_value = value; + m_ui_item.spinbox().setValue(value); emit ui_changed(); - emit changed(m_value); + emit changed(m_ui_item.spinbox().value()); } double UI_hex_spinbox::value() const { - return m_value; + return m_ui_item.spinbox().value(); } double UI_hex_spinbox::min() const { - return m_min; + return m_ui_item.spinbox().min(); } double UI_hex_spinbox::max() const { - return m_max; -} - -void UI_hex_spinbox::from_json(const json &j) -{ - UI_item::from_json(j); - - this->m_min = j.at("min"); - this->m_max = j.at("max"); - this->m_value = j.at("value"); -} - -json UI_hex_spinbox::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["min"] = this->m_min; - j["max"] = this->m_max; - j["value"] = this->m_value; - return j; + return m_ui_item.spinbox().max(); } diff --git a/UI/ui_hex_spinbox.hpp b/UI/ui_hex_spinbox.hpp index abee56e..6d162f0 100644 --- a/UI/ui_hex_spinbox.hpp +++ b/UI/ui_hex_spinbox.hpp @@ -50,20 +50,6 @@ class UI_hex_spinbox : public UI_item * @return double The maximum value */ double max() const; - - /** - * @brief Deserialize the hex spinbox from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the hex spinbox to JSON - * - * @param id The id of the hex spinbox - * @return json The JSON representation of the hex spinbox - */ - json to_json(size_t id) const override; signals: /** * @brief Signal emitted when the hex spinbox value changes @@ -71,9 +57,4 @@ class UI_hex_spinbox : public UI_item * @param value The new value */ void changed(double value); - - private: - double m_min; - double m_max; - double m_value; }; diff --git a/UI/ui_item.cpp b/UI/ui_item.cpp index fe742d5..6e3b586 100644 --- a/UI/ui_item.cpp +++ b/UI/ui_item.cpp @@ -1,172 +1,81 @@ #include "ui_item.hpp" -#include -UI_item::UI_item(UI_enum type, std::string text, Color fg_color, Color bg_color, QObject *parent) - : QObject(parent), m_id((size_t)-1), m_type(type), m_text(text), m_fg_color(fg_color), m_bg_color(bg_color), - m_enabled(true), m_visible(true) +UI_item::UI_item(UI_typeGadget::UI_type type, QObject *parent) + : QObject(parent) { + m_ui_item.setId_proto((size_t)-1); + m_ui_item.setType(type); + m_ui_item.setEnabled(true); + m_ui_item.setVisible(true); } -UI_item::UI_item(UI_enum type, QObject *parent) - : QObject(parent), m_id((size_t)-1), m_type(type), m_text(""), m_fg_color(Color::Default), - m_bg_color(Color::Default), m_enabled(true), m_visible(true) +void UI_item::set_id(size_t id) { -} - -std::string_view UI_item::type() const & -{ - return magic_enum::enum_name(m_type); -} - -bool UI_item::is_type(json j) -{ - if (!j.contains("type")) - { - return false; - } - return magic_enum::enum_cast((std::string)j.at("type")).value_or(UI_enum::end) == m_type; -} - -void UI_item::set_text(std::string text) -{ - if (this->m_text != text) - { - this->m_text = std::move(text); - emit ui_changed(); - } -} - -void UI_item::append_text(std::string text) -{ - m_text.append(text); - emit ui_changed(); -} - -std::string UI_item::text() const & -{ - return m_text; -} - -void UI_item::set_fg_color(Color fg_color) -{ - if (this->m_fg_color != fg_color) - { - this->m_fg_color = std::move(fg_color); - emit ui_changed(); - } -} - -Color UI_item::fg_color() const & -{ - return m_fg_color; -} - -void UI_item::set_bg_color(Color bg_color) -{ - if (this->m_bg_color != bg_color) - { - this->m_bg_color = std::move(bg_color); - emit ui_changed(); - } -} - -Color UI_item::bg_color() const & -{ - return m_bg_color; + m_ui_item.setId_proto(id); } void UI_item::set_enabled(bool enabled) { - if (this->m_enabled != enabled) + if (m_ui_item.enabled() != enabled) { - this->m_enabled = std::move(enabled); + m_ui_item.setEnabled(enabled); emit ui_changed(); } } bool UI_item::is_enabled() const { - return m_enabled; + return m_ui_item.enabled(); } void UI_item::set_visible(bool visible) { - if (this->m_visible != visible) + if (m_ui_item.visible() != visible) { - this->m_visible = std::move(visible); + m_ui_item.setVisible(visible); emit ui_changed(); } } bool UI_item::is_visible() const { - return m_visible; + return m_ui_item.visible(); } -void UI_item::from_json(const json &j) +UI_item_m UI_item::to_proto() const { - if (!is_type(j)) - return; - j.at("id").get_to(m_id); - if (j.contains("text")) - j.at("text").get_to(m_text); - std::string color; - if (j.contains("fg_color")) - { - j.at("fg_color").get_to(color); - m_fg_color = Color(color); - color.clear(); - } - if (j.contains("bg_color")) - { - j.at("bg_color").get_to(color); - m_bg_color = Color(color); - } - j.at("enabled").get_to(m_enabled); - j.at("visible").get_to(m_visible); + return m_ui_item; } -json UI_item::to_json(size_t id) const +void UI_item::from_proto(UI_item_m item) { - json j; - j["id"] = id; - j["type"] = type(); - if (m_text_enabled) - j["text"] = m_text; - if (m_fg_color_enabled) - j["fg_color"] = m_fg_color.to_hex(); - if (m_bg_color_enabled) - j["bg_color"] = m_bg_color.to_hex(); - j["enabled"] = m_enabled; - j["visible"] = m_visible; - return j; + m_ui_item = item; } void UI_item::click() {}; -void UI_item::set_selected(size_t selected) +void UI_item::set_selected(qsizetype selected) { - UNUSED(selected); -}; + Q_UNUSED(selected); +} + +void UI_item::set_text(QString text) +{ + Q_UNUSED(text); +} + void UI_item::set_value(double value) { - UNUSED(value); -}; + Q_UNUSED(value); +} -void UI_item::can_send(uint32_t id, uint8_t dlc, std::array payload) +void UI_item::can_send(uint32_t id, uint64_t dlc, QByteArray payload) { - UNUSED(id); - UNUSED(dlc); - UNUSED(payload); -}; + Q_UNUSED(id); + Q_UNUSED(dlc); + Q_UNUSED(payload); +} void UI_item::clear() { } - -void UI_item::setup_item(bool text, bool fg_color, bool bg_color) -{ - m_text_enabled = text; - m_fg_color_enabled = fg_color; - m_bg_color_enabled = bg_color; -} diff --git a/UI/ui_item.hpp b/UI/ui_item.hpp index a6e984b..f6a43f3 100644 --- a/UI/ui_item.hpp +++ b/UI/ui_item.hpp @@ -1,15 +1,13 @@ #pragma once #include "color.hpp" -#include "ui_enum.hpp" +#include +#include "m_ui_items.qpb.h" +#include #include -#include #include #include #include -using json = nlohmann::json; - -#define UNUSED(x) (void)(x) /** * @brief Base class representing a UI item @@ -25,77 +23,14 @@ class UI_item : public QObject * @param type The type of the UI item * @param parent The parent QObject */ - explicit UI_item(UI_enum type, QObject *parent = nullptr); - /** - * @brief Construct a new UI item object - * - * @param type The type of the UI item - * @param text The text of the UI item - * @param fg_color The foreground color of the UI item - * @param bg_color The background color of the UI item - * @param parent The parent QObject - */ - explicit UI_item(UI_enum type, std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + explicit UI_item(UI_typeGadget::UI_type type, QObject *parent = nullptr); /** - * @brief Get the type of the UI item + * @brief set_id Function for setting ID, DO NOT USE THIS IN A SIM YOURSELF * - * @return std::string The type of the UI item + * @param id */ - std::string_view type() const &; - /** - * @brief Check if the JSON object is of the correct type - * - * @param j The JSON object - * @return true If the JSON object is of the correct type - * @return false If the JSON object is not of the correct type - */ - bool is_type(json j); - - /** - * @brief Set the text of the UI item - * - * @param text The text to set - */ - virtual void set_text(std::string text); - /** - * @brief Append text to the UI item - * - * @param text The text to append - */ - void append_text(std::string text); - /** - * @brief Get the text of the UI item - * - * @return std::string The text of the UI item - */ - std::string text() const &; - - /** - * @brief Set the foreground color of the UI item - * - * @param fg_color The foreground color to set - */ - void set_fg_color(Color fg_color); - /** - * @brief Get the foreground color of the UI item - * - * @return Color The foreground color of the UI item - */ - Color fg_color() const &; - - /** - * @brief Set the background color of the UI item - * - * @param bg_color The background color to set - */ - void set_bg_color(Color bg_color); - /** - * @brief Get the background color of the UI item - * - * @return Color The background color of the UI item - */ - Color bg_color() const &; + void set_id(size_t id); /** * @brief Enable or disable the UI item @@ -125,20 +60,8 @@ class UI_item : public QObject */ bool is_visible() const; - /** - * @brief Deserialize the UI item from JSON - * - * @param j The JSON object - */ - virtual void from_json(const json &j); - - /** - * @brief Serialize the UI item to JSON - * - * @param id The id of the UI item - * @return json The JSON representation of the UI item - */ - virtual json to_json(size_t id) const; + UI_item_m to_proto() const; + void from_proto(UI_item_m item); /** * @brief Virtual method to handle click events @@ -150,7 +73,10 @@ class UI_item : public QObject * * @param selected The index of the option to select */ - virtual void set_selected(size_t selected); + virtual void set_selected(qsizetype selected); + + virtual void set_text(QString text); + /** * @brief Virtual method to set the value (for spinboxes) * @@ -164,7 +90,7 @@ class UI_item : public QObject * @param dlc The data length code * @param payload The payload data */ - virtual void can_send(uint32_t id, uint8_t dlc, std::array payload); + virtual void can_send(uint32_t id, uint64_t dlc, QByteArray payload); /** * @brief Virtual method to clear the UI item * @@ -179,63 +105,5 @@ class UI_item : public QObject void ui_changed(); protected: - /** - * @brief Setup the UI item properties - * - * @param text Enable text property - * @param fg_color Enable foreground color property - * @param bg_color Enable background color property - */ - void setup_item(bool text, bool fg_color, bool bg_color); - - /** - * @brief The id of the UI item - * - */ - size_t m_id; - /** - * @brief The type of the UI item - * - */ - UI_enum m_type; - /** - * @brief The text of the UI item - * - */ - std::string m_text; - /** - * @brief Whether the text property is enabled - * - */ - bool m_text_enabled = true; - /** - * @brief The foreground color of the UI item - * - */ - Color m_fg_color; - /** - * @brief Whether the foreground color property is enabled - * - */ - bool m_fg_color_enabled = true; - /** - * @brief The background color of the UI item - * - */ - Color m_bg_color; - /** - * @brief Whether the background color property is enabled - * - */ - bool m_bg_color_enabled = true; - /** - * @brief Whether the UI item is enabled - * - */ - bool m_enabled; - /** - * @brief Whether the UI item is visible - * - */ - bool m_visible; + UI_item_m m_ui_item; }; diff --git a/UI/ui_label.cpp b/UI/ui_label.cpp index 93b9a22..1edca0e 100644 --- a/UI/ui_label.cpp +++ b/UI/ui_label.cpp @@ -1,20 +1,52 @@ #include "ui_label.hpp" -UI_label::UI_label(std::string text, Color fg_color, Color bg_color, QObject *parent) - : UI_item(UI_enum::ui_label, text, fg_color, bg_color, parent) +UI_label::UI_label(QString text, Color fg_color, Color bg_color, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_label, parent) { + m_ui_item.setLabel(UI_label_m()); + m_ui_item.label().setText(text); + m_ui_item.label().mutColor().setFgColor(fg_color.color()); + m_ui_item.label().mutColor().setBgColor(bg_color.color()); } -UI_label::UI_label(QObject *parent) : UI_item(UI_enum::ui_label, parent) +UI_label::UI_label(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_label, parent) { + m_ui_item.setLabel(UI_label_m()); } -void UI_label::from_json(const json &j) +void UI_label::set_text(QString text) { - UI_item::from_json(j); + m_ui_item.label().setText(text); } -json UI_label::to_json(size_t id) const +void UI_label::append_text(QString text) { - return UI_item::to_json(id); + QString prev = m_ui_item.label().text(); + prev.append(text); + m_ui_item.label().setText(prev); } + +QString UI_label::text() const +{ + return m_ui_item.label().text(); +} + +void UI_label::set_fg_color(Color color) +{ + m_ui_item.label().mutColor().setFgColor(color.color()); +} + +Color UI_label::fg_color() const +{ + return Color(m_ui_item.label().color().fgColor()); +} + +void UI_label::set_bg_color(Color color) +{ + m_ui_item.label().mutColor().setBgColor(color.color()); +} + +Color UI_label::bg_color() const +{ + return Color(m_ui_item.label().color().bgColor()); +} \ No newline at end of file diff --git a/UI/ui_label.hpp b/UI/ui_label.hpp index 47567c7..6131fa9 100644 --- a/UI/ui_label.hpp +++ b/UI/ui_label.hpp @@ -18,7 +18,7 @@ class UI_label : public UI_item * @param bg_color The background color * @param parent The parent QObject */ - UI_label(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + UI_label(QString text, Color fg_color, Color bg_color, QObject *parent = nullptr); /** * @brief Construct a UI label object * @@ -27,16 +27,25 @@ class UI_label : public UI_item UI_label(QObject *parent = nullptr); /** - * @brief Deserialize the label from JSON - * - * @param j The JSON object + * @brief set_text + * @param text The text field of the button */ - void from_json(const json &j) override; + void set_text(QString text); + /** - * @brief Serialize the label to JSON - * - * @param id The id of the label - * @return json The JSON representation of the label + * @brief append_text Append + * @param text */ - json to_json(size_t id) const override; + void append_text(QString text); + + /** + * @brief text + * @return The text field of the button + */ + QString text() const; + + void set_fg_color(Color fg_color); + Color fg_color() const; + void set_bg_color(Color bg_color); + Color bg_color() const; }; diff --git a/UI/ui_led.cpp b/UI/ui_led.cpp index 3f52183..3ea3063 100644 --- a/UI/ui_led.cpp +++ b/UI/ui_led.cpp @@ -1,12 +1,47 @@ #include "ui_led.hpp" -UI_led::UI_led(QObject *parent) : UI_item(UI_enum::ui_led, "", Color::Default, Color::Default, parent) +UI_led::UI_led(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_led, parent) { + m_ui_item.setLabel(UI_label_m()); } -UI_led::UI_led(std::string text, Color fg_color, Color bg_color, QObject *parent) - : UI_item(UI_enum::ui_led, text, fg_color, bg_color, parent) +UI_led::UI_led(QString text, Color fg_color, Color bg_color, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_led, parent) { + m_ui_item.setLabel(UI_label_m()); + m_ui_item.label().setText(text); + m_ui_item.label().mutColor().setFgColor(fg_color.color()); + m_ui_item.label().mutColor().setBgColor(bg_color.color()); +} + +void UI_led::set_text(QString text) +{ + m_ui_item.label().setText(text); +} + +QString UI_led::text() const +{ + return m_ui_item.label().text(); +} + +void UI_led::set_fg_color(Color color) +{ + m_ui_item.label().mutColor().setFgColor(color.color()); +} + +Color UI_led::fg_color() const +{ + return Color(m_ui_item.label().color().fgColor()); +} + +void UI_led::set_bg_color(Color color) +{ + m_ui_item.label().mutColor().setBgColor(color.color()); +} + +Color UI_led::bg_color() const +{ + return Color(m_ui_item.label().color().bgColor()); } bool UI_led::set_led(bool state, Color on, Color off) @@ -14,14 +49,3 @@ bool UI_led::set_led(bool state, Color on, Color off) set_bg_color(state ? on : off); return state; } - -void UI_led::from_json(const json &j) -{ - UI_item::from_json(j); -} - -json UI_led::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - return j; -} diff --git a/UI/ui_led.hpp b/UI/ui_led.hpp index cc4f422..50f9d61 100644 --- a/UI/ui_led.hpp +++ b/UI/ui_led.hpp @@ -24,7 +24,24 @@ class UI_led : public UI_item * @param bg_color The background color * @param parent The parent QObject */ - UI_led(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + UI_led(QString text, Color fg_color, Color bg_color, QObject *parent = nullptr); + + /** + * @brief set_text + * @param text The text field of the button + */ + void set_text(QString text) override; + + /** + * @brief text + * @return The text field of the button + */ + QString text() const; + + void set_fg_color(Color fg_color); + Color fg_color() const; + void set_bg_color(Color bg_color); + Color bg_color() const; /** * @brief Set the state of the LED @@ -35,18 +52,4 @@ class UI_led : public UI_item * @return state */ bool set_led(bool state, Color on, Color off); - - /** - * @brief Deserialize the LED from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the LED to JSON - * - * @param id The id of the LED - * @return json The JSON representation of the LED - */ - json to_json(size_t id) const override; }; diff --git a/UI/ui_plot.cpp b/UI/ui_plot.cpp index a87da0b..e01fea9 100644 --- a/UI/ui_plot.cpp +++ b/UI/ui_plot.cpp @@ -1,88 +1,105 @@ #include "ui_plot.hpp" -UI_plot::UI_plot(QObject *parent) : UI_item{UI_enum::ui_plot, parent} +UI_plot::UI_plot(QObject *parent) : UI_item{UI_typeGadget::UI_type::ui_plot, parent} { + m_ui_item.setPlot(UI_plot_m()); } -UI_plot::UI_plot(std::string text, std::string x_label, std::string y_label, QObject *parent) - : UI_item(UI_enum::ui_plot, parent), m_x_label(x_label), m_y_label(y_label) +UI_plot::UI_plot(QString text, QString x_label, QString y_label, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_plot, parent) { - set_text(text); + m_ui_item.setPlot(UI_plot_m()); + m_ui_item.plot().setText(text); + m_ui_item.plot().setXLabel(x_label); + m_ui_item.plot().setYLabel(y_label); } -void UI_plot::set_x_label(std::string name) +void UI_plot::set_x_label(QString name) { - m_x_label = std::move(name); + m_ui_item.plot().setXLabel(name); emit ui_changed(); } -std::string UI_plot::x_label() const & +QString UI_plot::x_label() const & { - return m_x_label; + return m_ui_item.plot().xLabel(); } -void UI_plot::set_y_label(std::string name) +void UI_plot::set_y_label(QString name) { - m_y_label = std::move(name); + m_ui_item.plot().setYLabel(name); emit ui_changed(); } -std::string UI_plot::y_label() const & +QString UI_plot::y_label() const & { - return m_y_label; + return m_ui_item.plot().yLabel(); +} + +void UI_plot::set_fg_color(Color color) +{ + m_ui_item.plot().mutColor().setFgColor(color.color()); + + emit ui_changed(); +} + +Color UI_plot::fg_color() const& +{ + return Color(m_ui_item.plot().color().fgColor()); +} + +void UI_plot::set_bg_color(Color color) +{ + m_ui_item.plot().mutColor().setBgColor(color.color()); + + emit ui_changed(); +} + +Color UI_plot::bg_color() const +{ + return Color(m_ui_item.plot().color().bgColor()); } void UI_plot::add_value(double y) { - m_x_vals.push_back((double)m_x_vals.size()); - m_y_vals.push_back(y); + auto x_vals = m_ui_item.plot().xVals(); + auto y_vals = m_ui_item.plot().yVals(); + x_vals.push_back((double)x_vals.size()); + y_vals.push_back(y); + m_ui_item.plot().setXVals(x_vals); + m_ui_item.plot().setYVals(y_vals); emit ui_changed(); } void UI_plot::add_value(double x, double y) { - m_x_vals.push_back(x); - m_y_vals.push_back(y); + auto x_vals = m_ui_item.plot().xVals(); + auto y_vals = m_ui_item.plot().yVals(); + x_vals.push_back(x); + y_vals.push_back(y); + m_ui_item.plot().setXVals(x_vals); + m_ui_item.plot().setYVals(y_vals); emit ui_changed(); } -const std::vector &UI_plot::x_vals() const & +const QList &UI_plot::x_vals() const & { - return m_x_vals; + return m_ui_item.plot().xVals(); } -const std::vector &UI_plot::y_vals() const & +const QList &UI_plot::y_vals() const & { - return m_y_vals; + return m_ui_item.plot().yVals(); } void UI_plot::clean_vals() { - m_x_vals.clear(); - m_y_vals.clear(); + m_ui_item.plot().setXVals(QList()); + m_ui_item.plot().setYVals(QList()); emit ui_changed(); } - -void UI_plot::from_json(const json &j) -{ - UI_item::from_json(j); - this->m_x_label = j.at("x_label"); - this->m_y_label = j.at("y_label"); - this->m_x_vals = (std::vector)j.at("x_vals"); - this->m_y_vals = (std::vector)j.at("y_vals"); -} - -json UI_plot::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["x_label"] = m_x_label; - j["y_label"] = m_y_label; - j["x_vals"] = m_x_vals; - j["y_vals"] = m_y_vals; - return j; -} diff --git a/UI/ui_plot.hpp b/UI/ui_plot.hpp index f49f380..3727d62 100644 --- a/UI/ui_plot.hpp +++ b/UI/ui_plot.hpp @@ -23,33 +23,53 @@ class UI_plot : public UI_item * @param y_label The label for the y-axis * @param parent The parent QObject */ - UI_plot(std::string text, std::string x_label, std::string y_label, QObject *parent = nullptr); + UI_plot(QString text, QString x_label, QString y_label, QObject *parent = nullptr); /** * @brief Set the label for the x-axis * * @param name The name to set */ - void set_x_label(std::string name); + void set_x_label(QString name); /** * @brief Get the label for the x-axis * - * @return std::string The x-axis label + * @return QString The x-axis label */ - std::string x_label() const &; + QString x_label() const &; /** * @brief Set the label for the y-axis * * @param name The name to set */ - void set_y_label(std::string name); + void set_y_label(QString name); /** * @brief Get the label for the y-axis * - * @return std::string The y-axis label + * @return QString The y-axis label */ - std::string y_label() const &; + QString y_label() const &; + /** + * @brief set_fg_color Set the pen color + * @param color The color + */ + void set_fg_color(Color color); + /** + * @brief fg_color Get the pen color + * @return The color + */ + Color fg_color() const&; + /** + * @brief set_bg_color Set the background color + * @param color The color + */ + void set_bg_color(Color color); + /** + * @brief bg_color Get the background color + * @return The color + */ + Color bg_color() const; /** * @brief Add a value to the plot @@ -70,37 +90,17 @@ class UI_plot : public UI_item * * @return a list of x values and a list of y values */ - const std::vector &x_vals() const &; + const QList &x_vals() const &; /** * @brief Get the y values of the plot * This is only for testing purposes * * @return a list of y values */ - const std::vector &y_vals() const &; + const QList &y_vals() const &; /** * @brief Clear all values from the plot * */ void clean_vals(); - - /** - * @brief Deserialize the plot from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the plot to JSON - * - * @param id The id of the plot - * @return json The JSON representation of the plot - */ - json to_json(size_t id) const override; - - private: - std::vector m_x_vals; - std::vector m_y_vals; - std::string m_x_label; - std::string m_y_label; }; diff --git a/UI/ui_slider.cpp b/UI/ui_slider.cpp index 37e4a8c..de1b1e2 100644 --- a/UI/ui_slider.cpp +++ b/UI/ui_slider.cpp @@ -1,75 +1,51 @@ #include "ui_slider.hpp" -UI_slider::UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, +UI_slider::UI_slider(QString text, QString unit, double min, double max, double value, QObject *parent) - : UI_item(UI_enum::ui_slider, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), - m_unit(unit) + : UI_item(UI_typeGadget::UI_type::ui_slider, parent) { + m_ui_item.setRange(UI_range_m()); + m_ui_item.range().setText(text); + m_ui_item.range().setUnit(unit); + m_ui_item.range().setMax(max); + m_ui_item.range().setMin(min); + m_ui_item.range().setValue(value); } -UI_slider::UI_slider(std::string text, std::string unit, double min, double max, double value, QObject *parent) - : UI_slider(text, unit, Color::Default, Color::Default, min, max, value, parent) -{ -} - -UI_slider::UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value, +UI_slider::UI_slider(QString text, double min, double max, double value, QObject *parent) - : UI_slider(text, "", fg_color, bg_color, min, max, value, parent) + : UI_slider(text, "", min, max, value, parent) { } -UI_slider::UI_slider(std::string text, double min, double max, double value, QObject *parent) - : UI_slider(text, "", Color::Default, Color::Default, min, max, value, parent) -{ -} - -UI_slider::UI_slider(QObject *parent) : UI_item(UI_enum::ui_slider, parent) +UI_slider::UI_slider(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_slider, parent) { + m_ui_item.setRange(UI_range_m()); } void UI_slider::set_value(double value) { - if (value < m_min || value > m_max) + if (value < m_ui_item.range().min() || value > m_ui_item.range().max()) return; - if (value == m_value) + if (value == m_ui_item.range().value()) return; - this->m_value = value; + m_ui_item.range().setValue(value); emit ui_changed(); - emit changed(m_value); + emit changed(m_ui_item.range().value()); } double UI_slider::value() const { - return m_value; + return m_ui_item.range().value(); } double UI_slider::min() const { - return m_min; + return m_ui_item.range().min(); } double UI_slider::max() const { - return m_max; -} - -void UI_slider::from_json(const json &j) -{ - UI_item::from_json(j); - - this->m_min = j.at("min"); - this->m_max = j.at("max"); - this->m_value = j.at("value"); - this->m_unit = j.at("unit"); -} - -json UI_slider::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["min"] = this->m_min; - j["max"] = this->m_max; - j["value"] = this->m_value; - j["unit"] = this->m_unit; - return j; + return m_ui_item.range().max(); } diff --git a/UI/ui_slider.hpp b/UI/ui_slider.hpp index a41bb15..1f6e22e 100644 --- a/UI/ui_slider.hpp +++ b/UI/ui_slider.hpp @@ -14,26 +14,13 @@ class UI_slider : public UI_item * * @param text The text to display * @param unit The unit of the slider - * @param fg_color The foreground color - * @param bg_color The background color * @param min The minimum value * @param max The maximum value * @param value The initial value * @param parent The parent QObject */ - UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, + UI_slider(QString text, QString unit, double min, double max, double value, QObject *parent = nullptr); - /** - * @brief Construct a UI slider object - * - * @param text The text to display - * @param unit The unit of the slider - * @param min The minimum value - * @param max The maximum value - * @param value The initial value - * @param parent The parent QObject - */ - UI_slider(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); /** * @brief Construct a UI slider object * @@ -45,18 +32,9 @@ class UI_slider : public UI_item * @param value The initial value * @param parent The parent QObject */ - UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value, + UI_slider(QString text, double min, double max, double value, QObject *parent = nullptr); - /** - * @brief Construct a UI slider object - * - * @param text The text to display - * @param min The minimum value - * @param max The maximum value - * @param value The initial value - * @param parent The parent QObject - */ - UI_slider(std::string text, double min, double max, double value, QObject *parent = nullptr); + /** * @brief Construct a UI slider object * @@ -89,20 +67,6 @@ class UI_slider : public UI_item * @return double The maximum value */ double max() const; - - /** - * @brief Deserialize the slider from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the slider to JSON - * - * @param id The id of the slider - * @return json The JSON representation of the slider - */ - json to_json(size_t id) const override; signals: /** * @brief Signal emitted when the slider value changes @@ -110,10 +74,4 @@ class UI_slider : public UI_item * @param value The new value of the slider */ void changed(double value); - - private: - double m_min; - double m_max; - double m_value; - std::string m_unit; }; diff --git a/UI/ui_spinbox.cpp b/UI/ui_spinbox.cpp index 3d771ab..ef20a62 100644 --- a/UI/ui_spinbox.cpp +++ b/UI/ui_spinbox.cpp @@ -1,57 +1,39 @@ #include "ui_spinbox.hpp" -UI_spinbox::UI_spinbox(QObject *parent) : UI_item(UI_enum::ui_spinbox, parent) +UI_spinbox::UI_spinbox(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_spinbox, parent) { - setup_item(false, false, false); + m_ui_item.setSpinbox(UI_spinbox_m()); } -UI_spinbox::UI_spinbox(double min, double max, double value, QObject *parent) : UI_item(UI_enum::ui_spinbox, parent) +UI_spinbox::UI_spinbox(double min, double max, double value, QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_spinbox, parent) { - setup_item(false, false, false); - m_min = min; - m_max = max; - m_value = value; + m_ui_item.setSpinbox(UI_spinbox_m()); + m_ui_item.spinbox().setMin(min); + m_ui_item.spinbox().setMax(max); + m_ui_item.spinbox().setValue(value); } void UI_spinbox::set_value(double value) { - if (value < m_min || value > m_max) + if (value < m_ui_item.spinbox().min() || value > m_ui_item.spinbox().max()) return; - if (value == m_value) + if (value == m_ui_item.spinbox().value()) return; - this->m_value = value; + m_ui_item.spinbox().setValue(value); emit ui_changed(); - emit changed(m_value); + emit changed(m_ui_item.spinbox().value()); } double UI_spinbox::value() const { - return m_value; + return m_ui_item.spinbox().value(); } double UI_spinbox::min() const { - return m_min; + return m_ui_item.spinbox().min(); } double UI_spinbox::max() const { - return m_max; -} - -void UI_spinbox::from_json(const json &j) -{ - UI_item::from_json(j); - - this->m_min = j.at("min"); - this->m_max = j.at("max"); - this->m_value = j.at("value"); -} - -json UI_spinbox::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["min"] = this->m_min; - j["max"] = this->m_max; - j["value"] = this->m_value; - return j; + return m_ui_item.spinbox().max(); } diff --git a/UI/ui_spinbox.hpp b/UI/ui_spinbox.hpp index 1d7a8d8..aebb1a2 100644 --- a/UI/ui_spinbox.hpp +++ b/UI/ui_spinbox.hpp @@ -50,20 +50,6 @@ class UI_spinbox : public UI_item * @return double The maximum value */ double max() const; - - /** - * @brief Deserialize the spinbox from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the spinbox to JSON - * - * @param id The id of the spinbox - * @return json The JSON representation of the spinbox - */ - json to_json(size_t id) const override; signals: /** * @brief Signal emitted when the spinbox value changes @@ -71,9 +57,4 @@ class UI_spinbox : public UI_item * @param value The new value of the spinbox */ void changed(double value); - - private: - double m_min; - double m_max; - double m_value; }; diff --git a/UI/ui_stacked_widget.cpp b/UI/ui_stacked_widget.cpp index c4516e1..0f83952 100644 --- a/UI/ui_stacked_widget.cpp +++ b/UI/ui_stacked_widget.cpp @@ -1,44 +1,34 @@ #include "ui_stacked_widget.hpp" -UI_stacked_widget::UI_stacked_widget(QObject *parent) : UI_item(UI_enum::ui_stacked_widget, parent) +UI_stacked_widget::UI_stacked_widget(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_stacked_widget, parent) { + m_ui_item.setStackedWidget(UI_stacked_widget_m()); } -UI_stacked_widget::UI_stacked_widget(size_t tab_count, size_t current_tab, QObject *parent) - : UI_item(UI_enum::ui_stacked_widget, parent), m_tab_count(tab_count), m_current_tab(current_tab) +UI_stacked_widget::UI_stacked_widget(qsizetype tab_count, qsizetype current_tab, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_stacked_widget, parent) { + m_ui_item.setStackedWidget(UI_stacked_widget_m()); + m_ui_item.stackedWidget().setTabCount(tab_count); + m_ui_item.stackedWidget().setCurrentTab(current_tab); } -void UI_stacked_widget::set_selected(size_t selected) +void UI_stacked_widget::set_selected(qsizetype selected) { - if (selected >= m_tab_count) + if (selected >= m_ui_item.stackedWidget().tabCount()) return; - m_current_tab = selected; + m_ui_item.stackedWidget().setCurrentTab(selected); emit ui_changed(); } -size_t UI_stacked_widget::selected() const +qsizetype UI_stacked_widget::selected() const { - return m_current_tab; + return m_ui_item.stackedWidget().currentTab(); } void UI_stacked_widget::advance_tab() { - if (m_tab_count == 0) + if (m_ui_item.stackedWidget().tabCount() == 0) return; - m_current_tab = (m_current_tab + 1) % m_tab_count; + m_ui_item.stackedWidget().setCurrentTab((m_ui_item.stackedWidget().currentTab() + 1) % m_ui_item.stackedWidget().tabCount()); emit ui_changed(); } - -void UI_stacked_widget::from_json(const json &j) -{ - UI_item::from_json(j); - m_tab_count = j.at("tab_count"); - m_current_tab = j.at("current_tab"); -} -json UI_stacked_widget::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["tab_count"] = m_tab_count; - j["current_tab"] = m_current_tab; - return j; -} diff --git a/UI/ui_stacked_widget.hpp b/UI/ui_stacked_widget.hpp index ee67472..4cd97e4 100644 --- a/UI/ui_stacked_widget.hpp +++ b/UI/ui_stacked_widget.hpp @@ -22,41 +22,23 @@ class UI_stacked_widget : public UI_item * @param current_tab The currently selected tab * @param parent The parent QObject */ - UI_stacked_widget(size_t tab_count, size_t current_tab, QObject *parent = nullptr); + UI_stacked_widget(qsizetype tab_count, qsizetype current_tab, QObject *parent = nullptr); /** * @brief Set the selected tab by index * * @param selected The index of the tab to select */ - void set_selected(size_t selected) override; + void set_selected(qsizetype selected) override; /** * @brief Get the index of the selected tab * * @return size_t The index of the selected tab */ - size_t selected() const; + qsizetype selected() const; /** * @brief Advance to the next tab * */ void advance_tab(); - - /** - * @brief Deserialize the stacked widget from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the stacked widget to JSON - * - * @param id The id of the stacked widget - * @return json The JSON representation of the stacked widget - */ - json to_json(size_t id) const override; - - private: - size_t m_tab_count; - size_t m_current_tab; }; diff --git a/UI/ui_status_bar.cpp b/UI/ui_status_bar.cpp index 6add252..e31b380 100644 --- a/UI/ui_status_bar.cpp +++ b/UI/ui_status_bar.cpp @@ -1,44 +1,33 @@ #include "ui_status_bar.hpp" -UI_status_bar::UI_status_bar(QObject *parent) : UI_item(UI_enum::ui_status_bar, parent), m_timeout(0) +UI_status_bar::UI_status_bar(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_status_bar, parent) { - setup_item(true, false, false); + m_ui_item.setStatusBar(UI_status_bar_m()); + m_ui_item.statusBar().setTimeout(0); } -UI_status_bar::UI_status_bar(std::string message, QObject *parent) - : UI_item(UI_enum::ui_status_bar, parent), m_timeout(0) +UI_status_bar::UI_status_bar(QString message, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_status_bar, parent) { - m_text = std::move(message); - setup_item(true, false, false); + m_ui_item.setStatusBar(UI_status_bar_m()); + m_ui_item.statusBar().setMessage(message); + m_ui_item.statusBar().setTimeout(0); } -void UI_status_bar::show_message(std::string message, size_t timeout) +void UI_status_bar::show_message(QString message, size_t timeout) { // This should work because the message gets only send once when it changes - m_text = std::move(message); - m_timeout = timeout; + m_ui_item.statusBar().setMessage(message); + m_ui_item.statusBar().setTimeout(timeout); emit ui_changed(); } -std::string UI_status_bar::message() const & +QString UI_status_bar::message() const & { - return m_text; + return m_ui_item.statusBar().message(); } size_t UI_status_bar::timeout() const { - return m_timeout; -} - -void UI_status_bar::from_json(const json &j) -{ - UI_item::from_json(j); - m_timeout = j.at("timeout"); -} - -json UI_status_bar::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["timeout"] = m_timeout; - return j; + return m_ui_item.statusBar().timeout(); } diff --git a/UI/ui_status_bar.hpp b/UI/ui_status_bar.hpp index aae3eb2..8e7dce4 100644 --- a/UI/ui_status_bar.hpp +++ b/UI/ui_status_bar.hpp @@ -21,7 +21,7 @@ class UI_status_bar : public UI_item * @param message The initial message * @param parent The parent QObject */ - UI_status_bar(std::string message, QObject *parent = nullptr); + UI_status_bar(QString message, QObject *parent = nullptr); /** * @brief Show a message on the status bar @@ -29,34 +29,17 @@ class UI_status_bar : public UI_item * @param message The message to show * @param timeout The timeout in milliseconds (0 for no timeout) */ - void show_message(std::string message, size_t timeout = 0); + void show_message(QString message, size_t timeout = 0); /** * @brief Get the current message * - * @return std::string The current message + * @return QString The current message */ - std::string message() const &; + QString message() const &; /** * @brief Get the timeout for the current message * * @return size_t The timeout in milliseconds */ size_t timeout() const; - - /** - * @brief Deserialize the status bar from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the status bar to JSON - * - * @param id The id of the status bar - * @return json The JSON representation of the status bar - */ - json to_json(size_t id) const override; - - private: - size_t m_timeout; }; diff --git a/UI/ui_tab_widget.cpp b/UI/ui_tab_widget.cpp index 64d55cc..2631645 100644 --- a/UI/ui_tab_widget.cpp +++ b/UI/ui_tab_widget.cpp @@ -1,104 +1,78 @@ #include "ui_tab_widget.hpp" -UI_tab_widget::UI_tab_widget(QObject *parent) : UI_item(UI_enum::ui_tab_widget, parent) +UI_tab_widget::UI_tab_widget(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_tab_widget, parent) { - setup_item(false, false, false); + m_ui_item.setStackedWidget(UI_stacked_widget_m()); } -UI_tab_widget::UI_tab_widget(std::vector tab_names, size_t selected, QObject *parent) - : UI_item(UI_enum::ui_tab_widget, parent), m_selected_tab(selected), m_tab_names(tab_names) +UI_tab_widget::UI_tab_widget(QList tab_names, qsizetype selected, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_tab_widget, parent) { - setup_item(false, false, false); - m_tab_visible.resize(m_tab_names.size(), true); + m_ui_item.setTabWidget(UI_tab_widget_m()); + m_ui_item.tabWidget().setTabNames(tab_names); + m_ui_item.tabWidget().setSelecteTab(selected); } -void UI_tab_widget::set_selected(size_t selected) +void UI_tab_widget::set_selected(qsizetype selected) { - if (selected >= m_tab_names.size()) + if (selected >= m_ui_item.tabWidget().tabNames().size()) return; - m_selected_tab = selected; + m_ui_item.tabWidget().setSelecteTab(selected); emit ui_changed(); - emit changed(m_selected_tab); + emit changed(selected); } -size_t UI_tab_widget::selected() const +qsizetype UI_tab_widget::selected() const { - return m_selected_tab; + return m_ui_item.tabWidget().selecteTab(); } -void UI_tab_widget::set_visible(size_t index, bool visible) +void UI_tab_widget::set_visible(qsizetype index, bool visible) { - if (index >= m_tab_visible.size()) + if (index >= m_ui_item.tabWidget().tabNames().size()) { // Only allow known tab amount from constructor return; } - m_tab_visible.at(index) = visible; + auto list = m_ui_item.tabWidget().tabVisible(); + list.replace(index, visible); + m_ui_item.tabWidget().setTabVisible(list); emit ui_changed(); } -bool UI_tab_widget::visible(size_t index) const +bool UI_tab_widget::visible(qsizetype index) const { - if (index >= m_tab_visible.size()) + if (index >= m_ui_item.tabWidget().tabNames().size()) { return false; } - return m_tab_visible.at(index); + return m_ui_item.tabWidget().tabVisible().at(index); } -void UI_tab_widget::set_tab_name(size_t index, std::string name) +void UI_tab_widget::set_tab_name(qsizetype index, QString name) { - if (index >= m_tab_names.size() || index >= m_tab_visible.size()) + if (index >= m_ui_item.tabWidget().tabNames().size() || index >= m_ui_item.tabWidget().tabVisible().size()) { // Only allow known tab amount from constructor return; } - m_tab_names.at(index) = name; + auto list = m_ui_item.tabWidget().tabNames(); + list.replace(index, name); + m_ui_item.tabWidget().setTabNames(list); emit ui_changed(); } -std::string UI_tab_widget::tab_name(size_t index) const +QString UI_tab_widget::tab_name(qsizetype index) const { - if (index >= m_tab_names.size()) + if (index >= m_ui_item.tabWidget().tabNames().size()) { return ""; } - return m_tab_names.at(index); + return m_ui_item.tabWidget().tabNames().at(index); } void UI_tab_widget::advance_tab() { - if (m_tab_names.size() == 0) + if (m_ui_item.tabWidget().tabNames().empty()) return; - m_selected_tab = (m_selected_tab + 1) % m_tab_names.size(); + m_ui_item.tabWidget().setSelecteTab((m_ui_item.tabWidget().selecteTab() + 1) % m_ui_item.tabWidget().tabNames().size()); emit ui_changed(); - emit changed(m_selected_tab); -} - -void UI_tab_widget::from_json(const json &j) -{ - UI_item::from_json(j); - if (j.contains("tab_names")) - { - this->m_tab_names.clear(); - for (auto &option : j["tab_names"]) - { - this->m_tab_names.push_back(option); - } - } - if (j.contains("tab_visible")) - { - this->m_tab_visible.clear(); - for (auto &option : j["tab_visible"]) - { - this->m_tab_visible.push_back(option); - } - } - m_selected_tab = j.at("selected"); -} - -json UI_tab_widget::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["tab_names"] = m_tab_names; - j["tab_visible"] = m_tab_visible; - j["selected"] = m_selected_tab; - return j; + emit changed(m_ui_item.tabWidget().selecteTab()); } diff --git a/UI/ui_tab_widget.hpp b/UI/ui_tab_widget.hpp index 5529225..5774b3b 100644 --- a/UI/ui_tab_widget.hpp +++ b/UI/ui_tab_widget.hpp @@ -21,20 +21,20 @@ class UI_tab_widget : public UI_item * @param selected The initially selected tab * @param parent The parent QObject */ - UI_tab_widget(std::vector tab_names, size_t selected = 0, QObject *parent = nullptr); + UI_tab_widget(QList tab_names, qsizetype selected = 0, QObject *parent = nullptr); /** * @brief Set the selected tab by index * * @param selected The index of the tab to select */ - void set_selected(size_t selected) override; + void set_selected(qsizetype selected) override; /** * @brief Get the index of the selected tab * * @return size_t The index of the selected tab */ - size_t selected() const; + qsizetype selected() const; /** * @brief Set the visibility of a tab by index @@ -42,7 +42,7 @@ class UI_tab_widget : public UI_item * @param index The index of the tab * @param visible True to show, false to hide */ - void set_visible(size_t index, bool visible); + void set_visible(qsizetype index, bool visible); /** * @brief Get the visibility of a tab by index * @@ -50,7 +50,7 @@ class UI_tab_widget : public UI_item * @return true If the tab is visible * @return false If the tab is hidden */ - bool visible(size_t index) const; + bool visible(qsizetype index) const; /** * @brief Set the name of a tab by index @@ -58,44 +58,25 @@ class UI_tab_widget : public UI_item * @param index The index of the tab * @param name The name to set */ - void set_tab_name(size_t index, std::string name); + void set_tab_name(qsizetype index, QString name); /** * @brief Get the name of a tab by index * * @param index The index of the tab * @return std::string The name of the tab */ - std::string tab_name(size_t index) const; + QString tab_name(qsizetype index) const; /** * @brief Advance to the next tab * */ void advance_tab(); - - /** - * @brief Deserialize the tab widget from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the tab widget to JSON - * - * @param id The id of the tab widget - * @return json The JSON representation of the tab widget - */ - json to_json(size_t id) const override; signals: /** * @brief Signal emitted when the selected tab changes * * @param index The index of the newly selected tab */ - void changed(size_t index); - - private: - size_t m_selected_tab; - std::vector m_tab_names; - std::vector m_tab_visible; + void changed(qsizetype index); }; diff --git a/UI/ui_table.cpp b/UI/ui_table.cpp index f5dc680..6d357a2 100644 --- a/UI/ui_table.cpp +++ b/UI/ui_table.cpp @@ -1,162 +1,168 @@ #include "ui_table.hpp" -UI_table::UI_table(QObject *parent) : UI_item(UI_enum::ui_table, parent), m_row_count(0), m_column_count(0) +UI_table::UI_table(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_table, parent) { - setup_item(false, false, false); + m_ui_item.setTable(UI_table_m()); } -UI_table::UI_table(size_t row_count, size_t column_count, std::vector row_labels, - std::vector column_labels, QObject *parent) - : UI_item(UI_enum::ui_table, parent), m_row_count(row_count), m_column_count(column_count), - m_row_labels(row_labels), m_column_labels(column_labels), m_table() +UI_table::UI_table(qsizetype row_count, qsizetype column_count, QList row_labels, + QList column_labels, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_table, parent) { - setup_item(false, false, false); - m_row_labels.reserve(100); - m_column_labels.reserve(100); - m_table.reserve(500); + m_ui_item.setTable(UI_table_m()); + m_ui_item.table().setRowCount(row_count); + m_ui_item.table().setColumnCount(column_count); + m_ui_item.table().setColumnLabels(column_labels); + m_ui_item.table().setRowLabels(row_labels); } -void UI_table::set_row_count(size_t count) +void UI_table::set_row_count(qsizetype count) { - m_row_count = count; - if (m_row_count != 0 || m_column_count != 0) + m_ui_item.table().setRowCount(count); + auto column_count = m_ui_item.table().columnCount(); + auto row_count = m_ui_item.table().rowCount(); + auto row_labels = m_ui_item.table().rowLabels(); + + if (row_count != 0 || column_count != 0) { - m_table.resize(m_column_count * m_row_count); + auto table = m_ui_item.table().table(); + table.resize(column_count * count); + m_ui_item.table().setTable(table); } - m_row_labels.resize(m_row_count); + row_labels.resize(count); + m_ui_item.table().setRowLabels(row_labels); emit ui_changed(); } -size_t UI_table::row_count() const +qsizetype UI_table::row_count() const { - return m_row_count; + return m_ui_item.table().rowCount(); } -void UI_table::set_column_count(size_t count) +void UI_table::set_column_count(qsizetype count) { - m_column_count = count; - if (m_row_count != 0 || m_column_count != 0) + m_ui_item.table().setColumnCount(count); + auto column_count = m_ui_item.table().columnCount(); + auto row_count = m_ui_item.table().rowCount(); + auto column_labels = m_ui_item.table().columnLabels(); + + if (row_count != 0 || column_count != 0) { - m_table.resize(m_column_count * m_row_count); + auto table = m_ui_item.table().table(); + table.resize(column_count * count); + m_ui_item.table().setTable(table); } - m_column_labels.resize(m_column_count); + + column_labels.resize(count); + m_ui_item.table().setColumnLabels(column_labels); emit ui_changed(); } -size_t UI_table::column_count() const +qsizetype UI_table::column_count() const { - return m_column_count; + return m_ui_item.table().columnCount(); } -size_t UI_table::capacity() const +qsizetype UI_table::capacity() const { - return m_row_count * m_column_count; + return m_ui_item.table().rowCount() * m_ui_item.table().columnCount(); } -void UI_table::set_row_label(size_t index, std::string label) +void UI_table::set_row_label(qsizetype index, QString label) { - if (m_row_count <= index) + if (m_ui_item.table().rowCount() <= index) { return; } - m_row_labels[index] = std::move(label); + auto labels = m_ui_item.table().rowLabels(); + labels.replace(index, label); + m_ui_item.table().setRowLabels(labels); emit ui_changed(); } -std::string UI_table::row_label(size_t index) const +QString UI_table::row_label(qsizetype index) const { - if (m_row_count <= index) + if (m_ui_item.table().rowCount() <= index) { return ""; } - return m_row_labels[index]; + return m_ui_item.table().rowLabels().at(index); } -void UI_table::set_column_label(size_t index, std::string label) +void UI_table::set_column_label(qsizetype index, QString label) { - if (m_column_count <= index) + if (m_ui_item.table().columnCount() <= index) { return; } - m_column_labels[index] = std::move(label); + auto labels = m_ui_item.table().columnLabels(); + labels.replace(index, label); + m_ui_item.table().setColumnLabels(labels); emit ui_changed(); } -std::string UI_table::column_label(size_t index) const & +QString UI_table::column_label(qsizetype index) const & { - if (m_column_count <= index) + if (m_ui_item.table().columnCount() <= index) { return ""; } - return m_column_labels[index]; + return m_ui_item.table().columnLabels().at(index); } -void UI_table::insert_item(size_t row, size_t column, std::string text) +void UI_table::insert_item(qsizetype row, qsizetype column, QString text) { - if (m_column_count <= column || m_row_count <= row) + if (m_ui_item.table().columnCount() <= column || m_ui_item.table().rowCount() <= row) { return; } - if (capacity() > m_table.size()) + if (capacity() > m_ui_item.table().table().size()) { - m_table.resize(capacity()); + auto table = m_ui_item.table().table(); + table.resize(capacity()); + m_ui_item.table().setTable(table); } - size_t index = row * m_column_count + column; + qsizetype index = row * m_ui_item.table().columnCount() + column; - m_table.at(index) = std::move(text); + auto table = m_ui_item.table().table(); + table.replace(index, text); + m_ui_item.table().setTable(table); emit ui_changed(); } -std::string UI_table::item(size_t row, size_t column) const & +QString UI_table::item(qsizetype row, qsizetype column) const & { - if (m_column_count <= column || m_row_count <= row) + if (m_ui_item.table().columnCount() <= column || m_ui_item.table().rowCount() <= row) { return ""; } - size_t index = row * m_column_count + column; + qsizetype index = row * m_ui_item.table().columnCount() + column; - return m_table.at(index); + return m_ui_item.table().table().at(index); } -void UI_table::empty_item(size_t row, size_t column) +void UI_table::empty_item(qsizetype row, qsizetype column) { - size_t index = row * m_column_count + column; + if (m_ui_item.table().columnCount() <= column || m_ui_item.table().rowCount() <= row) + { + return; + } + qsizetype index = row * m_ui_item.table().columnCount() + column; - m_table[index] = ""; + auto table = m_ui_item.table().table(); + table.replace(index, ""); + m_ui_item.table().setTable(table); emit ui_changed(); } - -void UI_table::from_json(const json &j) -{ - UI_item::from_json(j); - - this->m_row_count = j.at("row_count"); - this->m_row_labels = j.at("row_labels"); - this->m_column_count = j.at("column_count"); - this->m_column_labels = j.at("column_labels"); - this->m_table = j.at("table"); -} - -json UI_table::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["row_count"] = m_row_count; - j["row_labels"] = m_row_labels; - j["column_count"] = m_column_count; - j["column_labels"] = m_column_labels; - j["table"] = m_table; - - return j; -} diff --git a/UI/ui_table.hpp b/UI/ui_table.hpp index 01c148c..39b221f 100644 --- a/UI/ui_table.hpp +++ b/UI/ui_table.hpp @@ -24,41 +24,41 @@ class UI_table : public UI_item * @param column_labels The labels for the columns * @param parent The parent QObject */ - explicit UI_table(size_t row_count, size_t column_count, std::vector row_labels, - std::vector column_labels, QObject *parent = nullptr); + explicit UI_table(qsizetype row_count, qsizetype column_count, QList row_labels, + QList column_labels, QObject *parent = nullptr); /** * @brief Set the number of rows in the table * * @param count The number of rows */ - void set_row_count(size_t count); + void set_row_count(qsizetype count); /** * @brief Get the number of rows in the table * * @return size_t The number of rows */ - size_t row_count() const; + qsizetype row_count() const; /** * @brief Set the number of columns in the table * * @param count The number of columns */ - void set_column_count(size_t count); + void set_column_count(qsizetype count); /** * @brief Get the number of columns in the table * * @return size_t The number of columns */ - size_t column_count() const; + qsizetype column_count() const; /** * @brief Get the capacity of the table (rows * columns) * * @return size_t The capacity of the table */ - size_t capacity() const; + qsizetype capacity() const; /** * @brief Set the label for a specific row @@ -66,14 +66,14 @@ class UI_table : public UI_item * @param index The index of the row * @param label The label to set */ - void set_row_label(size_t index, std::string label); + void set_row_label(qsizetype index, QString label); /** * @brief Get the label of a specific row * * @param index The index of the row - * @return std::string The label of the row + * @return QString The label of the row */ - std::string row_label(size_t index) const; + QString row_label(qsizetype index) const; /** * @brief Set the label for a specific column @@ -81,14 +81,14 @@ class UI_table : public UI_item * @param index The index of the column * @param label The label to set */ - void set_column_label(size_t index, std::string label); + void set_column_label(qsizetype index, QString label); /** * @brief Get the label of a specific column * * @param index The index of the column - * @return std::string The label of the column + * @return QString The label of the column */ - std::string column_label(size_t index) const &; + QString column_label(qsizetype index) const &; /** * @brief Insert an item into the table at the specified row and column @@ -97,42 +97,20 @@ class UI_table : public UI_item * @param column The column of the item * @param text The text of the item */ - void insert_item(size_t row, size_t column, std::string text); + void insert_item(qsizetype row, qsizetype column, QString text); /** * @brief Get the item at the specified row and column * * @param row The row of the item * @param column The column of the item - * @return std::string The text of the item + * @return QString The text of the item */ - std::string item(size_t row, size_t column) const &; + QString item(qsizetype row, qsizetype column) const &; /** * @brief empty_item This function clears the item * @param row The row of the item * @param column The column of the item */ - void empty_item(size_t row, size_t column); - - /** - * @brief Deserialize the table from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the table to JSON - * - * @param id The id of the table - * @return json The JSON representation of the table - */ - json to_json(size_t id) const override; - - private: - size_t m_row_count; - size_t m_column_count; - std::vector m_row_labels; - std::vector m_column_labels; - - std::vector m_table; + void empty_item(qsizetype row, qsizetype column); }; diff --git a/UI/ui_textbox.cpp b/UI/ui_textbox.cpp index 284f478..ab1217f 100644 --- a/UI/ui_textbox.cpp +++ b/UI/ui_textbox.cpp @@ -1,43 +1,61 @@ #include "ui_textbox.hpp" -UI_textbox::UI_textbox(std::string hint, Color fg_color, Color bg_color, QObject *parent) - : UI_item(UI_enum::ui_textbox, "", fg_color, bg_color, parent), m_hint(hint) +UI_textbox::UI_textbox(QString hint, Color fg_color, Color bg_color, QObject *parent) + : UI_item(UI_typeGadget::UI_type::ui_textbox, parent) { + m_ui_item.setTextbox(UI_textbox_m()); + m_ui_item.textbox().setHint(hint); + m_ui_item.textbox().mutColor().setFgColor(fg_color.color()); + m_ui_item.textbox().mutColor().setBgColor(bg_color.color()); } -UI_textbox::UI_textbox(QObject *parent) : UI_item(UI_enum::ui_textbox, parent) +UI_textbox::UI_textbox(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_textbox, parent) { + m_ui_item.setTextbox(UI_textbox_m()); } -void UI_textbox::set_text(std::string text) +void UI_textbox::set_text(QString text) { - if (text == m_text) + if (text == m_ui_item.textbox().text()) return; - m_text = std::move(text); + m_ui_item.textbox().setText(text); emit ui_changed(); - emit changed(m_text); + emit changed(m_ui_item.textbox().text()); } -void UI_textbox::set_hint(std::string hint) +QString UI_textbox::text() const { - m_hint = std::move(hint); + return m_ui_item.label().text(); +} + +void UI_textbox::set_fg_color(Color color) +{ + m_ui_item.label().mutColor().setFgColor(color.color()); +} + +Color UI_textbox::fg_color() const +{ + return Color(m_ui_item.label().color().fgColor()); +} + +void UI_textbox::set_bg_color(Color color) +{ + m_ui_item.label().mutColor().setBgColor(color.color()); +} + +Color UI_textbox::bg_color() const +{ + return Color(m_ui_item.label().color().bgColor()); +} + +void UI_textbox::set_hint(QString hint) +{ + m_ui_item.textbox().setHint(hint); emit ui_changed(); } -std::string UI_textbox::hint() const & +QString UI_textbox::hint() const & { - return m_hint; + return m_ui_item.textbox().hint(); } -void UI_textbox::from_json(const json &j) -{ - UI_item::from_json(j); - m_hint = j.at("hint"); -} - -json UI_textbox::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["hint"] = m_hint; - return j; -} diff --git a/UI/ui_textbox.hpp b/UI/ui_textbox.hpp index 92bdba9..1484ee0 100644 --- a/UI/ui_textbox.hpp +++ b/UI/ui_textbox.hpp @@ -18,7 +18,7 @@ class UI_textbox : public UI_item * @param bg_color The background color * @param parent The parent QObject */ - UI_textbox(std::string hint, Color fg_color, Color bg_color, QObject *parent = nullptr); + UI_textbox(QString hint, Color fg_color, Color bg_color, QObject *parent = nullptr); /** * @brief Construct a UI textbox object * @@ -31,42 +31,32 @@ class UI_textbox : public UI_item * * @param text The text to set */ - void set_text(std::string text) override; + void set_text(QString text) override; + + QString text() const; + + void set_fg_color(Color fg_color); + Color fg_color() const; + void set_bg_color(Color bg_color); + Color bg_color() const; /** * @brief Get the hint text of the textbox * * @param hint The hint text to set */ - void set_hint(std::string hint); + void set_hint(QString hint); /** * @brief Get the hint text of the textbox * - * @return std::string The hint text + * @return QString The hint text */ - std::string hint() const &; - - /** - * @brief Deserialize the textbox from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the textbox to JSON - * - * @param id The id of the textbox - * @return json The JSON representation of the textbox - */ - json to_json(size_t id) const override; + QString hint() const &; signals: /** * @brief Signal emitted when the text changes * * @param text The new text */ - void changed(std::string text); - - private: - std::string m_hint; + void changed(QString text); }; diff --git a/UI/ui_thermo.cpp b/UI/ui_thermo.cpp index c6d2327..aa7efc4 100644 --- a/UI/ui_thermo.cpp +++ b/UI/ui_thermo.cpp @@ -1,143 +1,107 @@ #include "ui_thermo.hpp" -UI_thermo::UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, +UI_thermo::UI_thermo(QString text, QString unit, double min, double max, double value, QObject *parent) - : UI_item(UI_enum::ui_thermo, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), - m_unit(unit) + : UI_item(UI_typeGadget::UI_type::ui_thermo, parent) { + m_ui_item.setRange(UI_range_m()); + m_ui_item.range().setText(text); + m_ui_item.range().setUnit(unit); + m_ui_item.range().setMin(min); + m_ui_item.range().setMax(max); + m_ui_item.range().setValue(value); } -UI_thermo::UI_thermo(std::string text, std::string unit, double min, double max, double value, QObject *parent) - : UI_thermo(text, unit, Color::Default, Color::Default, min, max, value, parent) -{ -} - -UI_thermo::UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value, +UI_thermo::UI_thermo(QString text, double min, double max, double value, QObject *parent) - : UI_thermo(text, "", fg_color, bg_color, min, max, value, parent) + : UI_thermo(text, "", min, max, value, parent) { } -UI_thermo::UI_thermo(std::string text, double min, double max, double value, QObject *parent) - : UI_thermo(text, "", Color::Default, Color::Default, min, max, value, parent) -{ -} - -UI_thermo::UI_thermo(QObject *parent) : UI_item(UI_enum::ui_thermo, parent) +UI_thermo::UI_thermo(QObject *parent) : UI_item(UI_typeGadget::UI_type::ui_thermo, parent) { } void UI_thermo::set_value(double value) { - if (value < m_min || value > m_max) + if (value < m_ui_item.range().min() || value > m_ui_item.range().max()) return; - if (value == m_value) + if (value == m_ui_item.range().value()) return; - this->m_value = value; + m_ui_item.range().setValue(value); emit ui_changed(); } double UI_thermo::value() const { - return m_value; + return m_ui_item.range().value(); } double UI_thermo::min() const { - return m_min; + return m_ui_item.range().min(); } double UI_thermo::max() const { - return m_max; + return m_ui_item.range().max(); } void UI_thermo::set_start_color(Color color) { - this->m_color_map[0] = color; - emit ui_changed(); + Q_UNUSED(color); + // this->m_color_map[0] = color; + // emit ui_changed(); } void UI_thermo::set_end_color(Color color) { - this->m_color_map[1] = color; - emit ui_changed(); + Q_UNUSED(color); + // this->m_color_map[1] = color; + // emit ui_changed(); } void UI_thermo::add_color_stop(double value, Color color) { - if (value <= 0 || value >= 1) - return; + Q_UNUSED(value); + Q_UNUSED(color); + // if (value <= 0 || value >= 1) + // return; - this->m_color_map[value] = color; - emit ui_changed(); + // this->m_color_map[value] = color; + // emit ui_changed(); } void UI_thermo::add_color_stop_normalized(double value, Color color) { - if (value < m_min || value > m_max) - return; + Q_UNUSED(value); + Q_UNUSED(color); + // if (value < m_min || value > m_max) + // return; - double normalized = (value - m_min) / (m_max - m_min); - this->m_color_map[normalized] = color; - emit ui_changed(); + // double normalized = (value - m_min) / (m_max - m_min); + // this->m_color_map[normalized] = color; + // emit ui_changed(); } void UI_thermo::remove_color_stop(double value) { - if (value <= 0 || value >= 1) - return; + Q_UNUSED(value); + // if (value <= 0 || value >= 1) + // return; - this->m_color_map.erase(value); - emit ui_changed(); + // this->m_color_map.erase(value); + // emit ui_changed(); } void UI_thermo::remove_color_stop_normalized(double value) { - if (value < m_min || value > m_max) - return; + Q_UNUSED(value); + // if (value < m_min || value > m_max) + // return; - double normalized = (value - m_min) / (m_max - m_min); - this->m_color_map.erase(normalized); - emit ui_changed(); -} - -void UI_thermo::from_json(const json &j) -{ - UI_item::from_json(j); - - this->m_min = j.at("min"); - this->m_max = j.at("max"); - this->m_value = j.at("value"); - this->m_unit = j.at("unit"); - this->m_color_map.clear(); - if (!j.contains("color_map")) - return; - for (auto &i : j["color_map"]) - { - double k = i.at("key"); - std::string c = i.at("value"); - this->m_color_map[k] = Color(c); - } -} - -json UI_thermo::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["min"] = this->m_min; - j["max"] = this->m_max; - j["value"] = this->m_value; - j["unit"] = this->m_unit; - if (this->m_color_map.empty()) - return j; - j["color_map"] = json::array(); - for (auto &[key, value] : this->m_color_map) - { - json item = json::object(); - item["key"] = key; - item["value"] = value.to_hex(); - j["color_map"].push_back(item); - } - return j; + // double normalized = (value - m_min) / (m_max - m_min); + // this->m_color_map.erase(normalized); + // emit ui_changed(); } diff --git a/UI/ui_thermo.hpp b/UI/ui_thermo.hpp index 9c69d60..51bc40f 100644 --- a/UI/ui_thermo.hpp +++ b/UI/ui_thermo.hpp @@ -15,26 +15,13 @@ class UI_thermo : public UI_item * * @param text The text to display * @param unit The unit of the thermometer - * @param fg_color The foreground color - * @param bg_color The background color * @param min The minimum value * @param max The maximum value * @param value The initial value * @param parent The parent QObject */ - UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, + UI_thermo(QString text, QString unit, double min, double max, double value, QObject *parent = nullptr); - /** - * @brief Construct a UI thermometer object - * - * @param text The text to display - * @param unit The unit of the thermometer - * @param min The minimum value - * @param max The maximum value - * @param value The initial value - * @param parent The parent QObject - */ - UI_thermo(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); /** * @brief Construct a UI thermometer object * @@ -46,18 +33,8 @@ class UI_thermo : public UI_item * @param value The initial value * @param parent The parent QObject */ - UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value, + UI_thermo(QString text, double min, double max, double value, QObject *parent = nullptr); - /** - * @brief Construct a UI thermometer object - * - * @param text The text to display - * @param min The minimum value - * @param max The maximum value - * @param value The initial value - * @param parent The parent QObject - */ - UI_thermo(std::string text, double min, double max, double value, QObject *parent = nullptr); /** * @brief Construct a UI thermometer object * @@ -129,25 +106,4 @@ class UI_thermo : public UI_item * @param value The normalized value (0.0 to 1.0) of the color stop to remove */ void remove_color_stop_normalized(double value); - - /** - * @brief Deserialize the thermometer from JSON - * - * @param j The JSON object - */ - void from_json(const json &j) override; - /** - * @brief Serialize the thermometer to JSON - * - * @param id The id of the thermometer - * @return json The JSON representation of the thermometer - */ - json to_json(size_t id) const override; - - private: - double m_min; - double m_max; - double m_value; - std::string m_unit; - std::unordered_map m_color_map; };