mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
server doxygen
Add documentation to the server
This commit is contained in:
@@ -3,18 +3,54 @@
|
|||||||
|
|
||||||
#define UI_BUTTON_TYPE std::string("ui_button")
|
#define UI_BUTTON_TYPE std::string("ui_button")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI button
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_button : public UI_item
|
class UI_button : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI button object
|
||||||
|
*
|
||||||
|
* @param text The text to display on the button
|
||||||
|
* @param fg_color The foreground color of the button
|
||||||
|
* @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(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI button object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_button(QObject *parent = nullptr);
|
UI_button(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the button from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
void from_json(const json &j) override;
|
||||||
|
/**
|
||||||
|
* @brief Serialize the button to JSON
|
||||||
|
*
|
||||||
|
* @param id The id of the button
|
||||||
|
* @return json The JSON representation of the button
|
||||||
|
*/
|
||||||
json to_json(size_t id) const override;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle a click event on the button
|
||||||
|
*
|
||||||
|
*/
|
||||||
void click() override;
|
void click() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the button is clicked
|
||||||
|
*
|
||||||
|
*/
|
||||||
void clicked();
|
void clicked();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,35 +4,119 @@
|
|||||||
|
|
||||||
#define UI_CAN_TYPE std::string("ui_can")
|
#define UI_CAN_TYPE std::string("ui_can")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a CAN UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
class CanFrame
|
class CanFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Can Frame object
|
||||||
|
*
|
||||||
|
* @param sid The standard identifier
|
||||||
|
* @param dlc The data length code
|
||||||
|
* @param payload The data payload
|
||||||
|
*/
|
||||||
CanFrame(uint32_t sid, uint8_t dlc, std::array<uint8_t, 8> payload) : m_SID(sid), m_DLC(dlc), m_payload(payload)
|
CanFrame(uint32_t sid, uint8_t dlc, std::array<uint8_t, 8> payload) : m_SID(sid), m_DLC(dlc), m_payload(payload)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief Get the Standard Identifier
|
||||||
|
*
|
||||||
|
* @return uint32_t The standard identifier
|
||||||
|
*/
|
||||||
uint32_t m_SID;
|
uint32_t m_SID;
|
||||||
|
/**
|
||||||
|
* @brief The Data Length Code
|
||||||
|
*
|
||||||
|
*/
|
||||||
uint8_t m_DLC;
|
uint8_t m_DLC;
|
||||||
|
/**
|
||||||
|
* @brief The Payload
|
||||||
|
*
|
||||||
|
*/
|
||||||
std::array<uint8_t, 8> m_payload;
|
std::array<uint8_t, 8> m_payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a CAN UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_can : public UI_item
|
class UI_can : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI can object
|
||||||
|
*
|
||||||
|
* @param fg_color The foreground color
|
||||||
|
* @param bg_color The background color
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_can(Color fg_color, Color bg_color, QObject *parent = nullptr);
|
UI_can(Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI can object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_can(QObject *parent = nullptr);
|
UI_can(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add a CAN message to the send buffer
|
||||||
|
*
|
||||||
|
* @param msg The CAN message to add
|
||||||
|
*/
|
||||||
void add_send_message(QCanBusFrame msg);
|
void add_send_message(QCanBusFrame msg);
|
||||||
|
/**
|
||||||
|
* @brief Add a CAN message to the receive buffer
|
||||||
|
*
|
||||||
|
* @param msg The CAN message to add
|
||||||
|
*/
|
||||||
void add_received_message(QCanBusFrame msg);
|
void add_received_message(QCanBusFrame msg);
|
||||||
|
/**
|
||||||
|
* @brief Clear the send buffer
|
||||||
|
*
|
||||||
|
*/
|
||||||
void clear_send_buffer();
|
void clear_send_buffer();
|
||||||
|
/**
|
||||||
|
* @brief Clear the receive buffer
|
||||||
|
*
|
||||||
|
*/
|
||||||
void clear_receive_buffer();
|
void clear_receive_buffer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the CAN item from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle a CAN send event
|
||||||
|
*
|
||||||
|
* @param id The CAN identifier
|
||||||
|
* @param dlc The data length code
|
||||||
|
* @param payload The data payload
|
||||||
|
*/
|
||||||
void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload) override;
|
void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload) override;
|
||||||
|
/**
|
||||||
|
* @brief Clear the CAN item
|
||||||
|
*
|
||||||
|
*/
|
||||||
void clear() override;
|
void clear() override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when a CAN message wants to be sent
|
||||||
|
* @param msg The CAN message sent
|
||||||
|
*/
|
||||||
void send(QCanBusFrame msg);
|
void send(QCanBusFrame msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+49
-1
@@ -3,22 +3,70 @@
|
|||||||
|
|
||||||
#define UI_CHECKBOX_TYPE std::string("ui_checkbox")
|
#define UI_CHECKBOX_TYPE std::string("ui_checkbox")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI checkbox
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_checkbox : public UI_item
|
class UI_checkbox : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI checkbox object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_checkbox(QObject *parent = nullptr);
|
UI_checkbox(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI checkbox object
|
||||||
|
*
|
||||||
|
* @param text The text to display
|
||||||
|
* @param fg_color The foreground color
|
||||||
|
* @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(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle a click event on the checkbox
|
||||||
|
*
|
||||||
|
*/
|
||||||
void click() override;
|
void click() override;
|
||||||
|
/**
|
||||||
|
* @brief Set the state of the checkbox
|
||||||
|
*
|
||||||
|
* @param state The state to set
|
||||||
|
*/
|
||||||
void set_state(bool state);
|
void set_state(bool state);
|
||||||
|
/**
|
||||||
|
* @brief Get the state of the checkbox
|
||||||
|
*
|
||||||
|
* @return true If checked
|
||||||
|
* @return false If unchecked
|
||||||
|
*/
|
||||||
bool state() const;
|
bool state() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the checkbox from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed(bool);
|
/**
|
||||||
|
* @brief Signal emitted when the checkbox state changes
|
||||||
|
*
|
||||||
|
* @param checked The new state of the checkbox
|
||||||
|
*/
|
||||||
|
void changed(bool checked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_checked;
|
bool m_checked;
|
||||||
|
|||||||
@@ -3,22 +3,76 @@
|
|||||||
|
|
||||||
#define UI_COMBOBOX_TYPE std::string("ui_combobox")
|
#define UI_COMBOBOX_TYPE std::string("ui_combobox")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI combobox
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_combobox : public UI_item
|
class UI_combobox : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI combobox object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_combobox(QObject *parent = nullptr);
|
UI_combobox(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI combobox object
|
||||||
|
*
|
||||||
|
* @param fg_color The foreground color
|
||||||
|
* @param bg_color The background color
|
||||||
|
* @param options The list of options
|
||||||
|
* @param selected The initially selected option
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected = 0,
|
UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected = 0,
|
||||||
QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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(size_t 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(std::string selected);
|
||||||
|
/**
|
||||||
|
* @brief Get the index of the selected option
|
||||||
|
*
|
||||||
|
* @return size_t The index of the selected option
|
||||||
|
*/
|
||||||
size_t selected() const;
|
size_t selected() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the text of the selected option
|
||||||
|
*
|
||||||
|
* @return std::string The text of the selected option
|
||||||
|
*/
|
||||||
std::string selected_text() const;
|
std::string selected_text() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the combobox from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the selected option changes
|
||||||
|
*
|
||||||
|
* @param selected The text of the newly selected option
|
||||||
|
*/
|
||||||
void changed(std::string selected);
|
void changed(std::string selected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -3,26 +3,113 @@
|
|||||||
|
|
||||||
#define UI_DIAL_TYPE std::string("ui_dial")
|
#define UI_DIAL_TYPE std::string("ui_dial")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI dial
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_dial : public UI_item
|
class UI_dial : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI dial object
|
||||||
|
*
|
||||||
|
* @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,
|
UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
QObject *parent = nullptr);
|
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);
|
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,
|
UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI dial 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_dial(std::string text, double min, double max, double value, QObject *parent = nullptr);
|
UI_dial(std::string text, double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI dial object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_dial(QObject *parent = nullptr);
|
UI_dial(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the value of the dial
|
||||||
|
*
|
||||||
|
* @param value The value to set
|
||||||
|
*/
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the value of the dial
|
||||||
|
*
|
||||||
|
* @return double The current value
|
||||||
|
*/
|
||||||
double value() const;
|
double value() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the minimum value of the dial
|
||||||
|
*
|
||||||
|
* @return double The minimum value
|
||||||
|
*/
|
||||||
double min() const;
|
double min() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the maximum value of the dial
|
||||||
|
*
|
||||||
|
* @return double The maximum value
|
||||||
|
*/
|
||||||
double max() const;
|
double max() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the unit of the dial
|
||||||
|
*
|
||||||
|
* @return std::string The unit of the dial
|
||||||
|
*/
|
||||||
std::string unit() const;
|
std::string unit() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the dial from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -3,22 +3,75 @@
|
|||||||
|
|
||||||
#define UI_DOUBLE_SPINBOX_TYPE std::string("ui_double_spinbox")
|
#define UI_DOUBLE_SPINBOX_TYPE std::string("ui_double_spinbox")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI double spinbox
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_double_spinbox : public UI_item
|
class UI_double_spinbox : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI double spinbox object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_double_spinbox(QObject *parent = nullptr);
|
explicit UI_double_spinbox(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI double spinbox object
|
||||||
|
*
|
||||||
|
* @param min The minimum value
|
||||||
|
* @param max The maximum value
|
||||||
|
* @param value The initial value
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_double_spinbox(double min, double max, double value, QObject *parent = nullptr);
|
UI_double_spinbox(double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the value of the double spinbox
|
||||||
|
*
|
||||||
|
* @param value The value to set
|
||||||
|
*/
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the value of the double spinbox
|
||||||
|
*
|
||||||
|
* @return double The current value
|
||||||
|
*/
|
||||||
double value() const;
|
double value() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the minimum value of the double spinbox
|
||||||
|
*
|
||||||
|
* @return double The minimum value
|
||||||
|
*/
|
||||||
double min() const;
|
double min() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the maximum value of the double spinbox
|
||||||
|
*
|
||||||
|
* @return double The maximum value
|
||||||
|
*/
|
||||||
double max() const;
|
double max() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the double spinbox from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the double spinbox value changes
|
||||||
|
*
|
||||||
|
* @param value The new value
|
||||||
|
*/
|
||||||
void changed(double value);
|
void changed(double value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -7,18 +7,67 @@ class UI_hex_spinbox : public UI_item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI hex spinbox object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_hex_spinbox(QObject *parent = nullptr);
|
explicit UI_hex_spinbox(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI hex spinbox object
|
||||||
|
*
|
||||||
|
* @param min The minimum value
|
||||||
|
* @param max The maximum value
|
||||||
|
* @param value The initial value
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_hex_spinbox(double min, double max, double value, QObject *parent = nullptr);
|
UI_hex_spinbox(double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the value of the hex spinbox
|
||||||
|
*
|
||||||
|
* @param value The value to set
|
||||||
|
*/
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the value of the hex spinbox
|
||||||
|
*
|
||||||
|
* @return double The current value
|
||||||
|
*/
|
||||||
double value() const;
|
double value() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the minimum value of the hex spinbox
|
||||||
|
*
|
||||||
|
* @return double The minimum value
|
||||||
|
*/
|
||||||
double min() const;
|
double min() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the maximum value of the hex spinbox
|
||||||
|
*
|
||||||
|
* @return double The maximum value
|
||||||
|
*/
|
||||||
double max() const;
|
double max() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the hex spinbox from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the hex spinbox value changes
|
||||||
|
*
|
||||||
|
* @param value The new value
|
||||||
|
*/
|
||||||
void changed(double value);
|
void changed(double value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ UI_item::UI_item(const json &j, QObject *parent) : QObject(parent)
|
|||||||
from_json(j);
|
from_json(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_item::~UI_item()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string UI_item::type() const
|
std::string UI_item::type() const
|
||||||
{
|
{
|
||||||
return m_type;
|
return m_type;
|
||||||
|
|||||||
+181
-1
@@ -10,58 +10,238 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
#define UNUSED(x) (void)(x)
|
#define UNUSED(x) (void)(x)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Base class representing a UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_item : public QObject
|
class UI_item : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new UI item object
|
||||||
|
*
|
||||||
|
* @param type The type of the UI item
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_item(std::string type, QObject *parent = nullptr);
|
explicit UI_item(std::string 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(std::string type, std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
explicit UI_item(std::string type, std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a new UI item object from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_item(const json &j, QObject *parent = nullptr);
|
explicit UI_item(const json &j, QObject *parent = nullptr);
|
||||||
~UI_item();
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the type of the UI item
|
||||||
|
*
|
||||||
|
* @return std::string The type of the UI item
|
||||||
|
*/
|
||||||
std::string type() const;
|
std::string 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);
|
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);
|
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);
|
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;
|
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);
|
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;
|
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);
|
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;
|
Color bg_color() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable or disable the UI item
|
||||||
|
*
|
||||||
|
* @param enabled True to enable, false to disable
|
||||||
|
*/
|
||||||
void set_enabled(bool enabled);
|
void set_enabled(bool enabled);
|
||||||
|
/**
|
||||||
|
* @brief Check if the UI item is enabled
|
||||||
|
*
|
||||||
|
* @return true If enabled
|
||||||
|
* @return false If disabled
|
||||||
|
*/
|
||||||
bool is_enabled() const;
|
bool is_enabled() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the visibility of the UI item
|
||||||
|
*
|
||||||
|
* @param visible True to show, false to hide
|
||||||
|
*/
|
||||||
void set_visible(bool visible);
|
void set_visible(bool visible);
|
||||||
|
/**
|
||||||
|
* @brief Check if the UI item is visible
|
||||||
|
*
|
||||||
|
* @return true If visible
|
||||||
|
* @return false If hidden
|
||||||
|
*/
|
||||||
bool is_visible() const;
|
bool is_visible() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the UI item from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
virtual void from_json(const json &j);
|
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;
|
virtual json to_json(size_t id) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Virtual method to handle click events
|
||||||
|
*
|
||||||
|
*/
|
||||||
virtual void click();
|
virtual void click();
|
||||||
|
/**
|
||||||
|
* @brief Virtual method to set the selected option (for comboboxes)
|
||||||
|
*
|
||||||
|
* @param selected The index of the option to select
|
||||||
|
*/
|
||||||
virtual void set_selected(size_t selected);
|
virtual void set_selected(size_t selected);
|
||||||
|
/**
|
||||||
|
* @brief Virtual method to set the value (for spinboxes)
|
||||||
|
*
|
||||||
|
* @param value The value to set
|
||||||
|
*/
|
||||||
virtual void set_value(double value);
|
virtual void set_value(double value);
|
||||||
|
/**
|
||||||
|
* @brief Virtual method to handle CAN send events
|
||||||
|
*
|
||||||
|
* @param id The CAN ID
|
||||||
|
* @param dlc The data length code
|
||||||
|
* @param payload The payload data
|
||||||
|
*/
|
||||||
virtual void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload);
|
virtual void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload);
|
||||||
|
/**
|
||||||
|
* @brief Virtual method to clear the UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the UI item changes
|
||||||
|
*
|
||||||
|
*/
|
||||||
void ui_changed();
|
void ui_changed();
|
||||||
|
|
||||||
protected:
|
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);
|
void setup_item(bool text, bool fg_color, bool bg_color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The id of the UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
size_t m_id;
|
size_t m_id;
|
||||||
|
/**
|
||||||
|
* @brief The type of the UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
std::string m_type;
|
std::string m_type;
|
||||||
|
/**
|
||||||
|
* @brief The text of the UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
|
/**
|
||||||
|
* @brief Whether the text property is enabled
|
||||||
|
*
|
||||||
|
*/
|
||||||
bool m_text_enabled = true;
|
bool m_text_enabled = true;
|
||||||
|
/**
|
||||||
|
* @brief The foreground color of the UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
Color m_fg_color;
|
Color m_fg_color;
|
||||||
|
/**
|
||||||
|
* @brief Whether the foreground color property is enabled
|
||||||
|
*
|
||||||
|
*/
|
||||||
bool m_fg_color_enabled = true;
|
bool m_fg_color_enabled = true;
|
||||||
|
/**
|
||||||
|
* @brief The background color of the UI item
|
||||||
|
*
|
||||||
|
*/
|
||||||
Color m_bg_color;
|
Color m_bg_color;
|
||||||
|
/**
|
||||||
|
* @brief Whether the background color property is enabled
|
||||||
|
*
|
||||||
|
*/
|
||||||
bool m_bg_color_enabled = true;
|
bool m_bg_color_enabled = true;
|
||||||
|
/**
|
||||||
|
* @brief Whether the UI item is enabled
|
||||||
|
*
|
||||||
|
*/
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
|
/**
|
||||||
|
* @brief Whether the UI item is visible
|
||||||
|
*
|
||||||
|
*/
|
||||||
bool m_visible;
|
bool m_visible;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,13 +4,41 @@
|
|||||||
|
|
||||||
#define UI_LABEL_TYPE std::string("ui_label")
|
#define UI_LABEL_TYPE std::string("ui_label")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI label
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_label : public UI_item
|
class UI_label : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI label object
|
||||||
|
*
|
||||||
|
* @param text The text to display
|
||||||
|
* @param fg_color The foreground color
|
||||||
|
* @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(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI label object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_label(QObject *parent = nullptr);
|
UI_label(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the label from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
void from_json(const json &j) override;
|
||||||
|
/**
|
||||||
|
* @brief Serialize the label to JSON
|
||||||
|
*
|
||||||
|
* @param id The id of the label
|
||||||
|
* @return json The JSON representation of the label
|
||||||
|
*/
|
||||||
json to_json(size_t id) const override;
|
json to_json(size_t id) const override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,15 +4,52 @@
|
|||||||
|
|
||||||
#define UI_LED_TYPE std::string("ui_led")
|
#define UI_LED_TYPE std::string("ui_led")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI led
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_led : public UI_item
|
class UI_led : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI led object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_led(QObject *parent = nullptr);
|
UI_led(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI led object
|
||||||
|
*
|
||||||
|
* @param text The text to display
|
||||||
|
* @param fg_color The foreground color
|
||||||
|
* @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(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the state of the LED
|
||||||
|
*
|
||||||
|
* @param state The state to set
|
||||||
|
* @param on The color when the LED is on
|
||||||
|
* @param off The color when the LED is off
|
||||||
|
* @return true If the state was changed
|
||||||
|
* @return false If the state was not changed
|
||||||
|
*/
|
||||||
bool set_led(bool state, Color on, Color off);
|
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;
|
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;
|
json to_json(size_t id) const override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,24 +2,101 @@
|
|||||||
#include "ui_item.hpp"
|
#include "ui_item.hpp"
|
||||||
#define UI_PLOT_TYPE std::string("ui_plot")
|
#define UI_PLOT_TYPE std::string("ui_plot")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI plot
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_plot : public UI_item
|
class UI_plot : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI plot object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_plot(QObject *parent = nullptr);
|
explicit UI_plot(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI plot object
|
||||||
|
*
|
||||||
|
* @param text The text to display
|
||||||
|
* @param x_label The label for the x-axis
|
||||||
|
* @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(std::string text, std::string x_label, std::string 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(std::string name);
|
||||||
|
/**
|
||||||
|
* @brief Get the label for the x-axis
|
||||||
|
*
|
||||||
|
* @return std::string The x-axis label
|
||||||
|
*/
|
||||||
std::string x_label() const;
|
std::string 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(std::string name);
|
||||||
|
/**
|
||||||
|
* @brief Get the label for the y-axis
|
||||||
|
*
|
||||||
|
* @return std::string The y-axis label
|
||||||
|
*/
|
||||||
std::string y_label() const;
|
std::string y_label() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add a value to the plot
|
||||||
|
*
|
||||||
|
* @param y The y value to add
|
||||||
|
*/
|
||||||
void add_value(double y);
|
void add_value(double y);
|
||||||
|
/**
|
||||||
|
* @brief Add a value pair to the plot
|
||||||
|
*
|
||||||
|
* @param x The x value to add
|
||||||
|
* @param y The y value to add
|
||||||
|
*/
|
||||||
void add_value(double x, double y);
|
void add_value(double x, double y);
|
||||||
|
/**
|
||||||
|
* @brief Get the x and y values of the plot
|
||||||
|
* This is only for testing purposes
|
||||||
|
*
|
||||||
|
* @return a list of x values and a list of y values
|
||||||
|
*/
|
||||||
const std::vector<double> &x_vals() const;
|
const std::vector<double> &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<double> &y_vals() const;
|
const std::vector<double> &y_vals() const;
|
||||||
|
/**
|
||||||
|
* @brief Clear all values from the plot
|
||||||
|
*
|
||||||
|
*/
|
||||||
void clean_vals();
|
void clean_vals();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the plot from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -3,27 +3,114 @@
|
|||||||
|
|
||||||
#define UI_SLIDER_TYPE std::string("ui_slider")
|
#define UI_SLIDER_TYPE std::string("ui_slider")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI slider
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_slider : public UI_item
|
class UI_slider : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI slider object
|
||||||
|
*
|
||||||
|
* @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(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
QObject *parent = nullptr);
|
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);
|
UI_slider(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI slider 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_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
QObject *parent = nullptr);
|
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);
|
UI_slider(std::string text, double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI slider object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_slider(QObject *parent = nullptr);
|
UI_slider(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the value of the slider
|
||||||
|
*
|
||||||
|
* @param value The value to set
|
||||||
|
*/
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the value of the slider
|
||||||
|
*
|
||||||
|
* @return double The current value
|
||||||
|
*/
|
||||||
double value() const;
|
double value() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the minimum value of the slider
|
||||||
|
*
|
||||||
|
* @return double The minimum value
|
||||||
|
*/
|
||||||
double min() const;
|
double min() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the maximum value of the slider
|
||||||
|
*
|
||||||
|
* @return double The maximum value
|
||||||
|
*/
|
||||||
double max() const;
|
double max() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the slider from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the slider value changes
|
||||||
|
*
|
||||||
|
* @param value The new value of the slider
|
||||||
|
*/
|
||||||
void changed(double value);
|
void changed(double value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -3,22 +3,75 @@
|
|||||||
|
|
||||||
#define UI_SPINBOX_TYPE std::string("ui_spinbox")
|
#define UI_SPINBOX_TYPE std::string("ui_spinbox")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI spinbox
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_spinbox : public UI_item
|
class UI_spinbox : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI spinbox object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_spinbox(QObject *parent = nullptr);
|
explicit UI_spinbox(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI spinbox object
|
||||||
|
*
|
||||||
|
* @param min The minimum value
|
||||||
|
* @param max The maximum value
|
||||||
|
* @param value The initial value
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_spinbox(double min, double max, double value, QObject *parent = nullptr);
|
UI_spinbox(double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the value of the spinbox
|
||||||
|
*
|
||||||
|
* @param value The value to set
|
||||||
|
*/
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the value of the spinbox
|
||||||
|
*
|
||||||
|
* @return double The current value
|
||||||
|
*/
|
||||||
double value() const;
|
double value() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the minimum value of the spinbox
|
||||||
|
*
|
||||||
|
* @return double The minimum value
|
||||||
|
*/
|
||||||
double min() const;
|
double min() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the maximum value of the spinbox
|
||||||
|
*
|
||||||
|
* @return double The maximum value
|
||||||
|
*/
|
||||||
double max() const;
|
double max() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the spinbox from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the spinbox value changes
|
||||||
|
*
|
||||||
|
* @param value The new value of the spinbox
|
||||||
|
*/
|
||||||
void changed(double value);
|
void changed(double value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -2,18 +2,59 @@
|
|||||||
#include "ui_item.hpp"
|
#include "ui_item.hpp"
|
||||||
#define UI_STACKED_WIDGET_TYPE std::string("ui_stacked_widget")
|
#define UI_STACKED_WIDGET_TYPE std::string("ui_stacked_widget")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI stacked widget
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_stacked_widget : public UI_item
|
class UI_stacked_widget : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI stacked widget object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_stacked_widget(QObject *parent = nullptr);
|
explicit UI_stacked_widget(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI stacked widget object
|
||||||
|
*
|
||||||
|
* @param tab_count The number of tabs
|
||||||
|
* @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(size_t tab_count, size_t 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(size_t selected) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the index of the selected tab
|
||||||
|
*
|
||||||
|
* @return size_t The index of the selected tab
|
||||||
|
*/
|
||||||
size_t selected() const;
|
size_t selected() const;
|
||||||
|
/**
|
||||||
|
* @brief Advance to the next tab
|
||||||
|
*
|
||||||
|
*/
|
||||||
void advance_tab();
|
void advance_tab();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the stacked widget from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -2,18 +2,60 @@
|
|||||||
#include "ui_item.hpp"
|
#include "ui_item.hpp"
|
||||||
#define UI_STATUS_BAR_TYPE std::string("ui_status_bar")
|
#define UI_STATUS_BAR_TYPE std::string("ui_status_bar")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI status bar
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_status_bar : public UI_item
|
class UI_status_bar : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI status bar object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_status_bar(QObject *parent = nullptr);
|
explicit UI_status_bar(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI status bar object
|
||||||
|
*
|
||||||
|
* @param message The initial message
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_status_bar(std::string message, QObject *parent = nullptr);
|
UI_status_bar(std::string message, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Show a message on the status bar
|
||||||
|
*
|
||||||
|
* @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(std::string message, size_t timeout = 0);
|
||||||
|
/**
|
||||||
|
* @brief Get the current message
|
||||||
|
*
|
||||||
|
* @return std::string The current message
|
||||||
|
*/
|
||||||
std::string message() const;
|
std::string message() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the timeout for the current message
|
||||||
|
*
|
||||||
|
* @return size_t The timeout in milliseconds
|
||||||
|
*/
|
||||||
size_t timeout() const;
|
size_t timeout() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the status bar from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -3,27 +3,97 @@
|
|||||||
|
|
||||||
#define UI_TAB_WIDGET_TYPE std::string("ui_tab_widget")
|
#define UI_TAB_WIDGET_TYPE std::string("ui_tab_widget")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI tab widget
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_tab_widget : public UI_item
|
class UI_tab_widget : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/** * @brief Construct a UI tab widget object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_tab_widget(QObject *parent = nullptr);
|
explicit UI_tab_widget(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI tab widget object
|
||||||
|
*
|
||||||
|
* @param tab_names The names of the tabs
|
||||||
|
* @param selected The initially selected tab
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_tab_widget(std::vector<std::string> tab_names, size_t selected = 0, QObject *parent = nullptr);
|
UI_tab_widget(std::vector<std::string> tab_names, size_t 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(size_t selected) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the index of the selected tab
|
||||||
|
*
|
||||||
|
* @return size_t The index of the selected tab
|
||||||
|
*/
|
||||||
size_t selected() const;
|
size_t selected() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the visibility of a tab by index
|
||||||
|
*
|
||||||
|
* @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(size_t index, bool visible);
|
||||||
|
/**
|
||||||
|
* @brief Get the visibility of a tab by index
|
||||||
|
*
|
||||||
|
* @param index The index of the tab
|
||||||
|
* @return true If the tab is visible
|
||||||
|
* @return false If the tab is hidden
|
||||||
|
*/
|
||||||
bool visible(size_t index) const;
|
bool visible(size_t index) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the name of a tab by index
|
||||||
|
*
|
||||||
|
* @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(size_t index, std::string 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;
|
std::string tab_name(size_t index) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Advance to the next tab
|
||||||
|
*
|
||||||
|
*/
|
||||||
void advance_tab();
|
void advance_tab();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the tab widget from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the selected tab changes
|
||||||
|
*
|
||||||
|
* @param index The index of the newly selected tab
|
||||||
|
*/
|
||||||
void changed(size_t index);
|
void changed(size_t index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+97
-1
@@ -3,35 +3,131 @@
|
|||||||
|
|
||||||
#define UI_TABLE_TYPE std::string("ui_table")
|
#define UI_TABLE_TYPE std::string("ui_table")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI table
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_table : public UI_item
|
class UI_table : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI table object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit UI_table(QObject *parent = nullptr);
|
explicit UI_table(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI table object
|
||||||
|
*
|
||||||
|
* @param row_count The number of rows
|
||||||
|
* @param column_count The number of columns
|
||||||
|
* @param row_labels The labels for the rows
|
||||||
|
* @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<std::string> row_labels,
|
explicit UI_table(size_t row_count, size_t column_count, std::vector<std::string> row_labels,
|
||||||
std::vector<std::string> column_labels, QObject *parent = nullptr);
|
std::vector<std::string> 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(size_t count);
|
||||||
|
/**
|
||||||
|
* @brief Get the number of rows in the table
|
||||||
|
*
|
||||||
|
* @return size_t The number of rows
|
||||||
|
*/
|
||||||
size_t row_count() const;
|
size_t 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(size_t count);
|
||||||
|
/**
|
||||||
|
* @brief Get the number of columns in the table
|
||||||
|
*
|
||||||
|
* @return size_t The number of columns
|
||||||
|
*/
|
||||||
size_t column_count() const;
|
size_t column_count() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the capacity of the table (rows * columns)
|
||||||
|
*
|
||||||
|
* @return size_t The capacity of the table
|
||||||
|
*/
|
||||||
size_t capacity() const;
|
size_t capacity() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the label for a specific row
|
||||||
|
*
|
||||||
|
* @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(size_t index, std::string label);
|
||||||
|
/**
|
||||||
|
* @brief Get the label of a specific row
|
||||||
|
*
|
||||||
|
* @param index The index of the row
|
||||||
|
* @return std::string The label of the row
|
||||||
|
*/
|
||||||
std::string row_label(size_t index) const;
|
std::string row_label(size_t index) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the label for a specific column
|
||||||
|
*
|
||||||
|
* @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(size_t index, std::string label);
|
||||||
|
/**
|
||||||
|
* @brief Get the label of a specific column
|
||||||
|
*
|
||||||
|
* @param index The index of the column
|
||||||
|
* @return std::string The label of the column
|
||||||
|
*/
|
||||||
std::string column_label(size_t index) const;
|
std::string column_label(size_t index) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Insert an item into the table at the specified row and column
|
||||||
|
*
|
||||||
|
* @param row The row of the 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(size_t row, size_t column, std::string 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
|
||||||
|
*/
|
||||||
std::string item(size_t row, size_t column) const;
|
std::string item(size_t row, size_t column) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief empty_item This function clears the item and makes it invalid
|
* @brief empty_item This function clears the item
|
||||||
* @param row The row of the item
|
* @param row The row of the item
|
||||||
* @param column The column of the item
|
* @param column The column of the item
|
||||||
*/
|
*/
|
||||||
void empty_item(size_t row, size_t column);
|
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;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -4,21 +4,69 @@
|
|||||||
|
|
||||||
#define UI_TEXTBOX_TYPE std::string("ui_textbox")
|
#define UI_TEXTBOX_TYPE std::string("ui_textbox")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI textbox
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_textbox : public UI_item
|
class UI_textbox : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI textbox object
|
||||||
|
*
|
||||||
|
* @param hint The hint text
|
||||||
|
* @param fg_color The foreground color
|
||||||
|
* @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(std::string hint, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI textbox object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_textbox(QObject *parent = nullptr);
|
UI_textbox(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the text of the textbox
|
||||||
|
*
|
||||||
|
* @param text The text to set
|
||||||
|
*/
|
||||||
void set_text(std::string text) override;
|
void set_text(std::string text) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the hint text of the textbox
|
||||||
|
*
|
||||||
|
* @param hint The hint text to set
|
||||||
|
*/
|
||||||
void set_hint(std::string hint);
|
void set_hint(std::string hint);
|
||||||
|
/**
|
||||||
|
* @brief Get the hint text of the textbox
|
||||||
|
*
|
||||||
|
* @return std::string The hint text
|
||||||
|
*/
|
||||||
std::string hint() const;
|
std::string hint() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deserialize the textbox from JSON
|
||||||
|
*
|
||||||
|
* @param j The JSON object
|
||||||
|
*/
|
||||||
void from_json(const json &j) override;
|
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;
|
json to_json(size_t id) const override;
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the text changes
|
||||||
|
*
|
||||||
|
* @param text The new text
|
||||||
|
*/
|
||||||
void changed(std::string text);
|
void changed(std::string text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -4,32 +4,146 @@
|
|||||||
#define UI_THERMO_TYPE std::string("ui_thermo")
|
#define UI_THERMO_TYPE std::string("ui_thermo")
|
||||||
|
|
||||||
// TODO: Add color scale
|
// TODO: Add color scale
|
||||||
|
/**
|
||||||
|
* @brief Class representing a UI thermometer
|
||||||
|
*
|
||||||
|
*/
|
||||||
class UI_thermo : public UI_item
|
class UI_thermo : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI thermometer object
|
||||||
|
*
|
||||||
|
* @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(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
QObject *parent = nullptr);
|
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);
|
UI_thermo(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI thermometer 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_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
QObject *parent = nullptr);
|
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);
|
UI_thermo(std::string text, double min, double max, double value, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a UI thermometer object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
UI_thermo(QObject *parent = nullptr);
|
UI_thermo(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the value of the thermometer
|
||||||
|
*
|
||||||
|
* @param value The value to set
|
||||||
|
*/
|
||||||
void set_value(double value) override;
|
void set_value(double value) override;
|
||||||
|
/**
|
||||||
|
* @brief Get the value of the thermometer
|
||||||
|
*
|
||||||
|
* @return double The current value
|
||||||
|
*/
|
||||||
double value() const;
|
double value() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the minimum value of the thermometer
|
||||||
|
*
|
||||||
|
* @return double The minimum value
|
||||||
|
*/
|
||||||
double min() const;
|
double min() const;
|
||||||
|
/**
|
||||||
|
* @brief Get the maximum value of the thermometer
|
||||||
|
*
|
||||||
|
* @return double The maximum value
|
||||||
|
*/
|
||||||
double max() const;
|
double max() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the start color object
|
||||||
|
*
|
||||||
|
* @param color
|
||||||
|
*/
|
||||||
void set_start_color(Color color);
|
void set_start_color(Color color);
|
||||||
|
/**
|
||||||
|
* @brief Set the end color object
|
||||||
|
*
|
||||||
|
* @param color
|
||||||
|
*/
|
||||||
void set_end_color(Color color);
|
void set_end_color(Color color);
|
||||||
|
/**
|
||||||
|
* @brief Add a color stop at the given value
|
||||||
|
*
|
||||||
|
* @param value The value at which to add the color stop
|
||||||
|
* @param color The color of the stop
|
||||||
|
*/
|
||||||
void add_color_stop(double value, Color color);
|
void add_color_stop(double value, Color color);
|
||||||
|
/**
|
||||||
|
* @brief Add a normalized color stop at the given value
|
||||||
|
*
|
||||||
|
* @param value The normalized value (0.0 to 1.0) at which to add the color stop
|
||||||
|
* @param color The color of the stop
|
||||||
|
*/
|
||||||
void add_color_stop_normalized(double value, Color color);
|
void add_color_stop_normalized(double value, Color color);
|
||||||
|
/**
|
||||||
|
* @brief Remove the color stop at the given value
|
||||||
|
*
|
||||||
|
* @param value The value of the color stop to remove
|
||||||
|
*/
|
||||||
void remove_color_stop(double value);
|
void remove_color_stop(double value);
|
||||||
|
/**
|
||||||
|
* @brief Remove the normalized color stop at the given value
|
||||||
|
*
|
||||||
|
* @param value The normalized value (0.0 to 1.0) of the color stop to remove
|
||||||
|
*/
|
||||||
void remove_color_stop_normalized(double value);
|
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;
|
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;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -4,20 +4,59 @@
|
|||||||
#include <QCanBusFrame>
|
#include <QCanBusFrame>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a CAN interface
|
||||||
|
*
|
||||||
|
*/
|
||||||
class CAN_Interface : public QObject
|
class CAN_Interface : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new CAN Interface object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
CAN_Interface(QObject *parent = nullptr);
|
CAN_Interface(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Destroy the CAN Interface object
|
||||||
|
*
|
||||||
|
*/
|
||||||
~CAN_Interface();
|
~CAN_Interface();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Connect to a CAN device
|
||||||
|
*
|
||||||
|
* @param dev The device to connect to (e.g. "can0")
|
||||||
|
*/
|
||||||
void connect_to_dev(QString dev);
|
void connect_to_dev(QString dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send a CAN frame
|
||||||
|
*
|
||||||
|
* @param frame The frame to send
|
||||||
|
*/
|
||||||
void send_frame(const QCanBusFrame frame);
|
void send_frame(const QCanBusFrame frame);
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when a CAN frame is received
|
||||||
|
*
|
||||||
|
* @param frame The received CAN frame
|
||||||
|
*/
|
||||||
void frame_received(QCanBusFrame frame);
|
void frame_received(QCanBusFrame frame);
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when a CAN frame is sent
|
||||||
|
*
|
||||||
|
* @param frame The sent CAN frame
|
||||||
|
*/
|
||||||
void frame_send(QCanBusFrame frame);
|
void frame_send(QCanBusFrame frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Private method to process CAN bus errors
|
||||||
|
*
|
||||||
|
* @param error The CAN bus error
|
||||||
|
*/
|
||||||
void processErrors(QCanBusDevice::CanBusError error) const;
|
void processErrors(QCanBusDevice::CanBusError error) const;
|
||||||
QCanBusDevice *m_canDevice;
|
QCanBusDevice *m_canDevice;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void Visa::send(QString data)
|
|||||||
m_tcp_socket->waitForBytesWritten();
|
m_tcp_socket->waitForBytesWritten();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Visa::querry(QString data)
|
QString Visa::query(QString data)
|
||||||
{
|
{
|
||||||
uint32_t counter = 0;
|
uint32_t counter = 0;
|
||||||
m_data.clear();
|
m_data.clear();
|
||||||
|
|||||||
+55
-1
@@ -1,23 +1,77 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a VISA interface also known as SCIPI over TCP/IP
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Visa : public QObject
|
class Visa : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Visa object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit Visa(QObject *parent = nullptr);
|
explicit Visa(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Destroy the Visa object
|
||||||
|
*
|
||||||
|
*/
|
||||||
~Visa();
|
~Visa();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Connect to a VISA device
|
||||||
|
*
|
||||||
|
* @param ip The IP address of the VISA device
|
||||||
|
* @param port The port number of the VISA device
|
||||||
|
*/
|
||||||
void connect(QString ip, quint16 port);
|
void connect(QString ip, quint16 port);
|
||||||
|
/**
|
||||||
|
* @brief Disconnect from the VISA device
|
||||||
|
*
|
||||||
|
*/
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the VISA device is connected
|
||||||
|
*
|
||||||
|
* @return true If the device is connected
|
||||||
|
* @return false If the device is not connected
|
||||||
|
*/
|
||||||
bool connected() const;
|
bool connected() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send data to the VISA device
|
||||||
|
*
|
||||||
|
* @param data The data to send
|
||||||
|
*/
|
||||||
void send(QString data);
|
void send(QString data);
|
||||||
QString querry(QString data);
|
/**
|
||||||
|
* @brief Query the VISA device
|
||||||
|
*
|
||||||
|
* @param data The query data
|
||||||
|
* @return QString The response from the device
|
||||||
|
*/
|
||||||
|
QString query(QString data);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the device is disconnected
|
||||||
|
*
|
||||||
|
*/
|
||||||
void s_disconnected();
|
void s_disconnected();
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the device is connected
|
||||||
|
*
|
||||||
|
*/
|
||||||
void s_connected();
|
void s_connected();
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when data is ready to be read
|
||||||
|
*
|
||||||
|
* @param data The data that is ready to be read
|
||||||
|
*/
|
||||||
void s_data_ready(QString data);
|
void s_data_ready(QString data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -6,19 +6,53 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class representing a GPIO pin
|
||||||
|
*
|
||||||
|
*/
|
||||||
class GPIO : public QObject
|
class GPIO : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Enum representing pin direction
|
||||||
|
*
|
||||||
|
*/
|
||||||
enum Direction
|
enum Direction
|
||||||
{
|
{
|
||||||
Input,
|
Input,
|
||||||
Output
|
Output
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* @brief Construct a new GPIO object
|
||||||
|
*
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
explicit GPIO(QObject *parent = nullptr);
|
explicit GPIO(QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Destroy the GPIO object
|
||||||
|
*
|
||||||
|
*/
|
||||||
~GPIO();
|
~GPIO();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configure a GPIO pin as input or output
|
||||||
|
*
|
||||||
|
* @param dir The direction of the pin (Input or Output)
|
||||||
|
* @param gpio The GPIO pin number
|
||||||
|
*/
|
||||||
void configure_pin(Direction dir, uint8_t gpio);
|
void configure_pin(Direction dir, uint8_t gpio);
|
||||||
|
/**
|
||||||
|
* @brief Set the value of the GPIO pin
|
||||||
|
*
|
||||||
|
* @param val The value to set (true for high, false for low)
|
||||||
|
*/
|
||||||
void set_value(bool val);
|
void set_value(bool val);
|
||||||
|
/**
|
||||||
|
* @brief Get the value of the GPIO pin
|
||||||
|
*
|
||||||
|
* @return bool The value of the pin (true for high, false for low)
|
||||||
|
*/
|
||||||
bool value();
|
bool value();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -22,17 +22,29 @@ Q_FORWARD_DECLARE_OBJC_CLASS(UI_item);
|
|||||||
return new sim(com, parent); \
|
return new sim(com, parent); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Struct holding all communication interfaces
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Communication
|
class Communication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CAN_Wrapper *c_if1 = nullptr;
|
/**
|
||||||
CAN_Wrapper *c_if2 = nullptr;
|
* @brief Array of CAN interfaces
|
||||||
QSerialPort *s_if1 = nullptr;
|
*
|
||||||
QSerialPort *s_if2 = nullptr;
|
*/
|
||||||
QSerialPort *s_if3 = nullptr;
|
CAN_Wrapper *can_if[3] = {nullptr, nullptr, nullptr};
|
||||||
QSerialPort *s_if4 = nullptr;
|
/**
|
||||||
|
* @brief Array of UART interfaces
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
QSerialPort *uart_if[4] = {nullptr, nullptr, nullptr, nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Base class for all simulators
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Simulator_base : public QObject
|
class Simulator_base : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -41,7 +53,9 @@ class Simulator_base : public QObject
|
|||||||
* @brief Construct a new Simulator_base object
|
* @brief Construct a new Simulator_base object
|
||||||
*
|
*
|
||||||
* @param name The name of the simulator
|
* @param name The name of the simulator
|
||||||
|
* @param comms The communication interfaces
|
||||||
* @param interval The interval of the timer (default is 100ms)
|
* @param interval The interval of the timer (default is 100ms)
|
||||||
|
* @param parent The parent QObject
|
||||||
*/
|
*/
|
||||||
Simulator_base(std::string name, Communication *comms,
|
Simulator_base(std::string name, Communication *comms,
|
||||||
std::chrono::milliseconds interval = std::chrono::milliseconds(100), QObject *parent = nullptr);
|
std::chrono::milliseconds interval = std::chrono::milliseconds(100), QObject *parent = nullptr);
|
||||||
@@ -76,6 +90,12 @@ class Simulator_base : public QObject
|
|||||||
*/
|
*/
|
||||||
UI_item *get_UI_item(size_t id) const;
|
UI_item *get_UI_item(size_t id) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the id of a UI item by pointer
|
||||||
|
*
|
||||||
|
* @param ptr A pointer to the UI item
|
||||||
|
* @return size_t The id of the UI item, or -1 if not found
|
||||||
|
*/
|
||||||
size_t ptr_to_id(UI_item *ptr) const
|
size_t ptr_to_id(UI_item *ptr) const
|
||||||
{
|
{
|
||||||
size_t id = 0;
|
size_t id = 0;
|
||||||
@@ -121,17 +141,57 @@ class Simulator_base : public QObject
|
|||||||
*/
|
*/
|
||||||
virtual void run_at_stop() {};
|
virtual void run_at_stop() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shutdown the system
|
||||||
|
*
|
||||||
|
*/
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
/**
|
||||||
|
* @brief Reboot the system
|
||||||
|
*
|
||||||
|
*/
|
||||||
void reboot();
|
void reboot();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if a specific bit is high in the input data
|
||||||
|
*
|
||||||
|
* @param data The input data
|
||||||
|
* @param pinnummer The pin number to check
|
||||||
|
* @return true If the bit is high
|
||||||
|
* @return false If the bit is low
|
||||||
|
*/
|
||||||
bool check_input_high(uint32_t data, uint16_t pinnummer);
|
bool check_input_high(uint32_t data, uint16_t pinnummer);
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the ui of the simulator changes
|
||||||
|
*
|
||||||
|
*/
|
||||||
void sim_changed();
|
void sim_changed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief The name of the simulator
|
||||||
|
*
|
||||||
|
*/
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
/**
|
||||||
|
* @brief The UI items of the simulator
|
||||||
|
*
|
||||||
|
*/
|
||||||
std::vector<UI_item *> m_UI_items;
|
std::vector<UI_item *> m_UI_items;
|
||||||
|
/**
|
||||||
|
* @brief The timer for the simulator
|
||||||
|
*
|
||||||
|
*/
|
||||||
QTimer *m_timer;
|
QTimer *m_timer;
|
||||||
|
/**
|
||||||
|
* @brief The interval of the timer
|
||||||
|
*
|
||||||
|
*/
|
||||||
std::chrono::milliseconds m_interval;
|
std::chrono::milliseconds m_interval;
|
||||||
|
/**
|
||||||
|
* @brief The communication interface
|
||||||
|
*
|
||||||
|
*/
|
||||||
Communication *m_com;
|
Communication *m_com;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ Simulators::Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject
|
|||||||
SPDLOG_CRITICAL("Error {}", m_serial->errorString().toStdString());
|
SPDLOG_CRITICAL("Error {}", m_serial->errorString().toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_com->c_if1 = m_can_wrapper;
|
m_com->can_if[0] = m_can_wrapper;
|
||||||
m_com->s_if1 = m_serial;
|
m_com->uart_if[0] = m_serial;
|
||||||
|
|
||||||
QLibrary lib;
|
QLibrary lib;
|
||||||
QDirIterator it(QCoreApplication::applicationDirPath(), QStringList() << "*.so", QDir::Files,
|
QDirIterator it(QCoreApplication::applicationDirPath(), QStringList() << "*.so", QDir::Files,
|
||||||
|
|||||||
+84
-1
@@ -17,10 +17,18 @@ Q_FORWARD_DECLARE_OBJC_CLASS(Communication);
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class managing all simulators
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Simulators : public QObject
|
class Simulators : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Enumeration of commands
|
||||||
|
*
|
||||||
|
*/
|
||||||
enum class Command
|
enum class Command
|
||||||
{
|
{
|
||||||
get_UI_element,
|
get_UI_element,
|
||||||
@@ -32,6 +40,10 @@ class Simulators : public QObject
|
|||||||
begin = 0
|
begin = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enumeration of events
|
||||||
|
*
|
||||||
|
*/
|
||||||
enum class Event
|
enum class Event
|
||||||
{
|
{
|
||||||
clicked,
|
clicked,
|
||||||
@@ -45,20 +57,91 @@ class Simulators : public QObject
|
|||||||
begin = 0
|
begin = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Simulators object
|
||||||
|
*
|
||||||
|
* @param port The port for the websocket server
|
||||||
|
* @param can_dev The CAN device path
|
||||||
|
* @param uart_dev The UART device path
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject *parent = nullptr);
|
Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Destroy the Simulators object
|
||||||
|
*
|
||||||
|
*/
|
||||||
~Simulators();
|
~Simulators();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the name of the active simulator
|
||||||
|
*
|
||||||
|
* @return std::string The name of the active simulator
|
||||||
|
*/
|
||||||
std::string active_simulator_name() const;
|
std::string active_simulator_name() const;
|
||||||
|
/**
|
||||||
|
* @brief Start the active simulator
|
||||||
|
*
|
||||||
|
*/
|
||||||
void start();
|
void start();
|
||||||
|
/**
|
||||||
|
* @brief Stop the active simulator
|
||||||
|
*
|
||||||
|
*/
|
||||||
void stop();
|
void stop();
|
||||||
|
/**
|
||||||
|
* @brief Switch to a different simulator
|
||||||
|
*
|
||||||
|
* @param name The name of the simulator to switch to
|
||||||
|
*/
|
||||||
void switch_simulator(std::string name);
|
void switch_simulator(std::string name);
|
||||||
|
/**
|
||||||
|
* @brief List all available simulators
|
||||||
|
*
|
||||||
|
* @return std::vector<std::string> A list of simulator names
|
||||||
|
*/
|
||||||
std::vector<std::string> list_simulators() const;
|
std::vector<std::string> list_simulators() const;
|
||||||
|
/**
|
||||||
|
* @brief Check if no simulator is active
|
||||||
|
*
|
||||||
|
* @return true If no simulator is active
|
||||||
|
* @return false If a simulator is active
|
||||||
|
*/
|
||||||
bool is_not_active() const;
|
bool is_not_active() const;
|
||||||
|
/**
|
||||||
|
* @brief Get a pointer to the active simulator
|
||||||
|
* Throws a lock on the simulators map
|
||||||
|
*
|
||||||
|
* @return Simulator_base* A pointer to the active simulator
|
||||||
|
*/
|
||||||
Simulator_base *invoke_active_simulator();
|
Simulator_base *invoke_active_simulator();
|
||||||
|
/**
|
||||||
|
* @brief Get the changed UI items in json format
|
||||||
|
* Throws a lock on the simulators map
|
||||||
|
*
|
||||||
|
* @return json The changed UI items
|
||||||
|
*/
|
||||||
json changed_UI_items();
|
json changed_UI_items();
|
||||||
|
|
||||||
// parsing of websocket messages
|
// Functions in message_parser.cpp
|
||||||
|
/**
|
||||||
|
* @brief Parse a websocket message
|
||||||
|
*
|
||||||
|
* @param message The message to parse
|
||||||
|
* @return QString The parsed message
|
||||||
|
*/
|
||||||
QString message_parser(QString message);
|
QString message_parser(QString message);
|
||||||
|
/**
|
||||||
|
* @brief Parse a command in json format
|
||||||
|
*
|
||||||
|
* @param command The command to parse
|
||||||
|
* @return json The parsed command
|
||||||
|
*/
|
||||||
json command_parser(json command);
|
json command_parser(json command);
|
||||||
|
/**
|
||||||
|
* @brief Handle an event in json format
|
||||||
|
*
|
||||||
|
* @param event The event to handle
|
||||||
|
*/
|
||||||
void event_handler(json event);
|
void event_handler(json event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
EXPORT_SIM(Can_Debugger);
|
EXPORT_SIM(Can_Debugger);
|
||||||
|
|
||||||
Can_Debugger::Can_Debugger(Communication *com, QObject *parent)
|
Can_Debugger::Can_Debugger(Communication *com, QObject *parent)
|
||||||
: Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent), m_wrapper(com->c_if1),
|
: Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent), m_wrapper(com->can_if[0]),
|
||||||
m_can_ui(Color::Black, Color::White)
|
m_can_ui(Color::Black, Color::White)
|
||||||
{
|
{
|
||||||
PUSH_UI_ITEM(m_can_ui);
|
PUSH_UI_ITEM(m_can_ui);
|
||||||
|
|||||||
+10
-2
@@ -24,8 +24,16 @@ Websocket::Websocket(uint16_t port, QString key_file, QString cert_file, QObject
|
|||||||
QSslConfiguration sslConfiguration;
|
QSslConfiguration sslConfiguration;
|
||||||
QFile certFile(cert_file);
|
QFile certFile(cert_file);
|
||||||
QFile keyFile(key_file);
|
QFile keyFile(key_file);
|
||||||
certFile.open(QIODevice::ReadOnly);
|
bool certFileOpened = certFile.open(QIODevice::ReadOnly);
|
||||||
keyFile.open(QIODevice::ReadOnly);
|
if (!certFileOpened)
|
||||||
|
{
|
||||||
|
SPDLOG_CRITICAL("WebSocket: Unable to open certificate file: {}", cert_file.toStdString());
|
||||||
|
}
|
||||||
|
bool keyFileOpened = keyFile.open(QIODevice::ReadOnly);
|
||||||
|
if (!keyFileOpened)
|
||||||
|
{
|
||||||
|
SPDLOG_CRITICAL("WebSocket: Unable to open key file: {}", key_file.toStdString());
|
||||||
|
}
|
||||||
QSslCertificate certificate(&certFile, QSsl::Pem);
|
QSslCertificate certificate(&certFile, QSsl::Pem);
|
||||||
QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
|
QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
|
||||||
certFile.close();
|
certFile.close();
|
||||||
|
|||||||
+56
-1
@@ -1,29 +1,84 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QtCore/QByteArray>
|
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
||||||
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class managing a WebSocket server
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Websocket : public QObject
|
class Websocket : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Websocket object
|
||||||
|
*
|
||||||
|
* @param port The port to listen on
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
Websocket(uint16_t port, QObject *parent = nullptr);
|
Websocket(uint16_t port, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Websocket object with SSL
|
||||||
|
*
|
||||||
|
* @param port The port to listen on
|
||||||
|
* @param key_file The path to the SSL key file
|
||||||
|
* @param cert_file The path to the SSL certificate file
|
||||||
|
* @param parent The parent QObject
|
||||||
|
*/
|
||||||
Websocket(uint16_t port, QString key_file, QString cert_file, QObject *parent = nullptr);
|
Websocket(uint16_t port, QString key_file, QString cert_file, QObject *parent = nullptr);
|
||||||
|
/**
|
||||||
|
* @brief Destroy the Websocket object
|
||||||
|
*
|
||||||
|
*/
|
||||||
~Websocket();
|
~Websocket();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Broadcast a message to all connected clients
|
||||||
|
*
|
||||||
|
* @param message The message to send
|
||||||
|
*/
|
||||||
void broadcast(QString message);
|
void broadcast(QString message);
|
||||||
|
/**
|
||||||
|
* @brief Send a message to a specific client
|
||||||
|
*
|
||||||
|
* @param conn The client connection
|
||||||
|
* @param message The message to send
|
||||||
|
*/
|
||||||
void send(QWebSocket *conn, QString message);
|
void send(QWebSocket *conn, QString message);
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when a message is received from a client
|
||||||
|
*
|
||||||
|
* @param conn The client connection
|
||||||
|
* @param message The received message
|
||||||
|
*/
|
||||||
void on_message(QWebSocket *conn, QString message);
|
void on_message(QWebSocket *conn, QString message);
|
||||||
|
/**
|
||||||
|
* @brief Signal emitted when the server is closed
|
||||||
|
*
|
||||||
|
*/
|
||||||
void closed();
|
void closed();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
/**
|
||||||
|
* @brief Private Slot called when a new client connection is established
|
||||||
|
*
|
||||||
|
*/
|
||||||
void onNewConnection();
|
void onNewConnection();
|
||||||
|
/**
|
||||||
|
* @brief Private Slot called when a text message is received from a client
|
||||||
|
*
|
||||||
|
* @param message The received message
|
||||||
|
*/
|
||||||
void processTextMessage(QString message);
|
void processTextMessage(QString message);
|
||||||
|
/**
|
||||||
|
* @brief Private Slot called when a client disconnects
|
||||||
|
*
|
||||||
|
*/
|
||||||
void socketDisconnected();
|
void socketDisconnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user