Move to id is size_t

This commit is contained in:
2024-10-10 19:47:18 +02:00
parent d02b31ab25
commit 95a21250a6
27 changed files with 132 additions and 148 deletions
+5 -5
View File
@@ -1,7 +1,7 @@
#include "UI_button.hpp"
UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent)
: UI_item(id, UI_BUTTON_TYPE, text, 12, fg_color, bg_color, parrent)
UI_button::UI_button(std::string text, Color fg_color, Color bg_color, QObject *parrent)
: UI_item(UI_BUTTON_TYPE, text, 12, fg_color, bg_color, parrent)
{
}
@@ -15,13 +15,13 @@ void UI_button::from_json(const json &j)
UI_item::from_json(j);
}
json UI_button::to_json() const
json UI_button::to_json(size_t id) const
{
json j = UI_item::to_json();
json j = UI_item::to_json(id);
return j;
}
void UI_button::click()
{
emit on_click(m_id);
emit on_click();
}
+3 -3
View File
@@ -8,14 +8,14 @@ class UI_button : public UI_item
{
Q_OBJECT
public:
UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent = nullptr);
UI_button(std::string text, Color fg_color, Color bg_color, QObject *parrent = nullptr);
UI_button(const json &j, QObject *parrent = nullptr);
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
void click() override;
signals:
void on_click(std::string id);
void on_click();
};
+5 -5
View File
@@ -4,9 +4,9 @@ UI_checkbox::UI_checkbox(QObject *parrent) : UI_x_boxes(UI_CHECKBOX_TYPE, parren
{
}
UI_checkbox::UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color,
UI_checkbox::UI_checkbox(std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options, QObject *parrent)
: UI_x_boxes(id, UI_CHECKBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected()
: UI_x_boxes(UI_CHECKBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected()
{
for (size_t i = 0; i < m_options.size(); i++)
{
@@ -25,7 +25,7 @@ void UI_checkbox::toggle_selected(size_t selected)
return;
m_selected[selected] = !m_selected[selected];
emit value_changed();
emit on_change(m_id, selected_text()[selected]);
emit on_change(selected_text()[selected]);
}
void UI_checkbox::toggle_selected(std::string selected)
@@ -72,9 +72,9 @@ void UI_checkbox::from_json(const json &j)
}
}
json UI_checkbox::to_json() const
json UI_checkbox::to_json(size_t id) const
{
json j = UI_x_boxes::to_json();
json j = UI_x_boxes::to_json(id);
j["selected"] = m_selected;
return j;
}
+3 -3
View File
@@ -10,7 +10,7 @@ class UI_checkbox : public UI_x_boxes
Q_OBJECT
public:
UI_checkbox(QObject *parrent = nullptr);
UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
UI_checkbox(std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
QObject *parrent = nullptr);
UI_checkbox(const json &j, QObject *parrent = nullptr);
@@ -20,10 +20,10 @@ class UI_checkbox : public UI_x_boxes
std::vector<std::string> selected_text() const;
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
signals:
void on_change(std::string, std::string);
void on_change(std::string);
private:
std::vector<bool> m_selected;
+5 -5
View File
@@ -4,9 +4,9 @@ UI_combobox::UI_combobox(QObject *parrent) : UI_x_boxes(UI_COMBOBOX_TYPE, parren
{
}
UI_combobox::UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color,
UI_combobox::UI_combobox(std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options, size_t selected, QObject *parrent)
: UI_x_boxes(id, UI_COMBOBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected(selected)
: UI_x_boxes(UI_COMBOBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected(selected)
{
}
@@ -21,7 +21,7 @@ void UI_combobox::set_selected(size_t selected)
return;
m_selected = selected;
emit value_changed();
emit on_change(m_id, selected_text());
emit on_change(selected_text());
}
void UI_combobox::set_selected(std::string selected)
@@ -60,9 +60,9 @@ void UI_combobox::from_json(const json &j)
}
}
json UI_combobox::to_json() const
json UI_combobox::to_json(size_t id) const
{
json j = UI_x_boxes::to_json();
json j = UI_x_boxes::to_json(id);
j["selected"] = m_options[m_selected];
return j;
}
+3 -3
View File
@@ -11,7 +11,7 @@ class UI_combobox : public UI_x_boxes
Q_OBJECT
public:
UI_combobox(QObject *parrent = nullptr);
UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
UI_combobox(std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
size_t selected = 0, QObject *parrent = nullptr);
UI_combobox(const json &j, QObject *parrent = nullptr);
@@ -21,9 +21,9 @@ class UI_combobox : public UI_x_boxes
std::string selected_text() const;
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
signals:
void on_change(std::string id, std::string selected);
void on_change(std::string selected);
private:
size_t m_selected;
+4 -4
View File
@@ -1,8 +1,8 @@
#include "UI_dial.hpp"
UI_dial::UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
UI_dial::UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
QObject *parrent)
: UI_item(id, UI_DIAL_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
: UI_item(UI_DIAL_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
{
}
@@ -46,9 +46,9 @@ void UI_dial::from_json(const json &j)
this->m_value = j.at("value");
}
json UI_dial::to_json() const
json UI_dial::to_json(size_t id) const
{
json j = UI_item::to_json();
json j = UI_item::to_json(id);
j["min"] = this->m_min;
j["max"] = this->m_max;
j["value"] = this->m_value;
+2 -2
View File
@@ -7,7 +7,7 @@ class UI_dial : public UI_item
{
Q_OBJECT
public:
UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
QObject *parrent = nullptr);
UI_dial(const json &j, QObject *parrent = nullptr);
@@ -18,7 +18,7 @@ class UI_dial : public UI_item
double max() const;
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
private:
double m_min;
+5 -10
View File
@@ -1,14 +1,14 @@
#include "UI_item.hpp"
UI_item::UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color,
UI_item::UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color,
QObject *parrent)
: QObject(parrent), m_id(id), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color),
: QObject(parrent), m_id((size_t)-1), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color),
m_bg_color(bg_color), enabled(true), visible(true)
{
}
UI_item::UI_item(std::string type, QObject *parrent)
: QObject(parrent), m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black),
: QObject(parrent), m_id((size_t)-1), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black),
m_bg_color(Color::White), enabled(true), visible(true)
{
}
@@ -22,11 +22,6 @@ UI_item::~UI_item()
{
}
std::string UI_item::id() const
{
return m_id;
}
std::string UI_item::type() const
{
return m_type;
@@ -142,10 +137,10 @@ void UI_item::from_json(const json &j)
j.at("visible").get_to(visible);
}
json UI_item::to_json() const
json UI_item::to_json(size_t id) const
{
json j;
j["id"] = m_id;
j["id"] = id;
j["type"] = m_type;
j["text"] = m_text;
j["text_size"] = m_text_size;
+3 -4
View File
@@ -16,12 +16,11 @@ class UI_item : public QObject
Q_OBJECT
public:
explicit UI_item(std::string type, QObject *parrent = nullptr);
explicit UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color,
explicit UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color,
Color bg_color, QObject *parrent = nullptr);
explicit UI_item(const json &j, QObject *parrent = nullptr);
~UI_item();
std::string id() const;
std::string type() const;
bool is_type(json j);
@@ -45,7 +44,7 @@ class UI_item : public QObject
virtual void from_json(const json &j);
virtual json to_json() const;
virtual json to_json(size_t id) const;
virtual void click();
virtual void set_selected(std::string selected);
@@ -55,7 +54,7 @@ class UI_item : public QObject
void value_changed();
protected:
std::string m_id;
size_t m_id;
std::string m_type;
std::string m_text;
uint8_t m_text_size;
+4 -4
View File
@@ -1,7 +1,7 @@
#include "UI_label.hpp"
UI_label::UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent)
: UI_item(id, UI_LABEL_TYPE, text, 12, fg_color, bg_color, parrent)
UI_label::UI_label(std::string text, Color fg_color, Color bg_color, QObject *parrent)
: UI_item(UI_LABEL_TYPE, text, 12, fg_color, bg_color, parrent)
{
}
@@ -15,7 +15,7 @@ void UI_label::from_json(const json &j)
UI_item::from_json(j);
}
json UI_label::to_json() const
json UI_label::to_json(size_t id) const
{
return UI_item::to_json();
return UI_item::to_json(id);
}
+2 -2
View File
@@ -8,9 +8,9 @@ class UI_label : public UI_item
{
Q_OBJECT
public:
UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject *parrent = nullptr);
UI_label(std::string text, Color fg_color, Color bg_color, QObject *parrent = nullptr);
UI_label(const json &j, QObject *parrent = nullptr);
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
};
+4 -4
View File
@@ -1,7 +1,7 @@
#include "UI_led.hpp"
UI_led::UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color, QObject *parrent)
: UI_item(id, UI_LED_TYPE, text, 12, fg_color, bg_color, parrent), m_led_color(led_color)
UI_led::UI_led(std::string text, Color fg_color, Color bg_color, Color led_color, QObject *parrent)
: UI_item(UI_LED_TYPE, text, 12, fg_color, bg_color, parrent), m_led_color(led_color)
{
}
@@ -32,9 +32,9 @@ void UI_led::from_json(const json &j)
m_led_color = Color(color);
}
json UI_led::to_json() const
json UI_led::to_json(size_t id) const
{
json j = UI_item::to_json();
json j = UI_item::to_json(id);
j["led_color"] = m_led_color.to_hex();
return j;
}
+2 -2
View File
@@ -8,7 +8,7 @@ class UI_led : public UI_item
{
Q_OBJECT
public:
UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color,
UI_led(std::string text, Color fg_color, Color bg_color, Color led_color,
QObject *parrent = nullptr);
UI_led(const json &j, QObject *parrent = nullptr);
@@ -16,7 +16,7 @@ class UI_led : public UI_item
void set_led_color(Color led_color);
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
private:
Color m_led_color;
+5 -5
View File
@@ -1,8 +1,8 @@
#include "UI_slider.hpp"
UI_slider::UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max,
UI_slider::UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parrent)
: UI_item(id, UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
: UI_item(UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
{
}
@@ -20,7 +20,7 @@ void UI_slider::set_value(double value)
this->m_value = value;
emit value_changed();
emit on_change(m_id, m_value);
emit on_change(m_value);
}
double UI_slider::value() const
@@ -47,9 +47,9 @@ void UI_slider::from_json(const json &j)
this->m_value = j.at("value");
}
json UI_slider::to_json() const
json UI_slider::to_json(size_t id) const
{
json j = UI_item::to_json();
json j = UI_item::to_json(id);
j["min"] = this->m_min;
j["max"] = this->m_max;
j["value"] = this->m_value;
+3 -3
View File
@@ -7,7 +7,7 @@ class UI_slider : public UI_item
{
Q_OBJECT
public:
UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
QObject *parrent = nullptr);
UI_slider(const json &j, QObject *parrent = nullptr);
@@ -18,9 +18,9 @@ class UI_slider : public UI_item
double max() const;
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
signals:
void on_change(std::string id, double value);
void on_change(double value);
private:
double m_min;
+5 -5
View File
@@ -1,7 +1,7 @@
#include "UI_textbox.hpp"
UI_textbox::UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject *parrent)
: UI_item(id, UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color, parrent), m_hint(hint)
UI_textbox::UI_textbox(std::string hint, Color fg_color, Color bg_color, QObject *parrent)
: UI_item(UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color, parrent), m_hint(hint)
{
}
@@ -16,7 +16,7 @@ void UI_textbox::set_text(std::string text)
return;
m_text = text;
emit value_changed();
emit on_change(m_id, m_text);
emit on_change(m_text);
}
void UI_textbox::set_hint(std::string hint)
@@ -36,9 +36,9 @@ void UI_textbox::from_json(const json &j)
m_hint = j.at("hint");
}
json UI_textbox::to_json() const
json UI_textbox::to_json(size_t id) const
{
json j = UI_item::to_json();
json j = UI_item::to_json(id);
j["hint"] = m_hint;
return j;
}
+3 -3
View File
@@ -8,7 +8,7 @@ class UI_textbox : public UI_item
{
Q_OBJECT
public:
UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject *parrent = nullptr);
UI_textbox(std::string hint, Color fg_color, Color bg_color, QObject *parrent = nullptr);
UI_textbox(const json &j, QObject *parrent = nullptr);
void set_text(std::string text) override;
@@ -17,9 +17,9 @@ class UI_textbox : public UI_item
std::string hint() const;
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
signals:
void on_change(std::string id, std::string text);
void on_change(std::string text);
private:
std::string m_hint;
+4 -4
View File
@@ -1,8 +1,8 @@
#include "UI_thermo.hpp"
UI_thermo::UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max,
UI_thermo::UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parrent)
: UI_item(id, UI_THERMO_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
: UI_item(UI_THERMO_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
{
}
@@ -103,9 +103,9 @@ void UI_thermo::from_json(const json &j)
}
}
json UI_thermo::to_json() const
json UI_thermo::to_json(size_t id) const
{
json j = UI_item::to_json();
json j = UI_item::to_json(id);
j["min"] = this->m_min;
j["max"] = this->m_max;
j["value"] = this->m_value;
+2 -2
View File
@@ -8,7 +8,7 @@ class UI_thermo : public UI_item
{
Q_OBJECT
public:
UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
QObject *parrent = nullptr);
UI_thermo(const json &j, QObject *parrent = nullptr);
@@ -26,7 +26,7 @@ class UI_thermo : public UI_item
void remove_color_stop_normalized(double value);
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
private:
double m_min;
+4 -4
View File
@@ -4,9 +4,9 @@ UI_x_boxes::UI_x_boxes(std::string type, QObject *parrent) : UI_item(type, parre
{
}
UI_x_boxes::UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color,
UI_x_boxes::UI_x_boxes(std::string type, std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options, QObject *parrent)
: UI_item(id, type, text, 12, fg_color, bg_color, parrent), m_options(options)
: UI_item(type, text, 12, fg_color, bg_color, parrent), m_options(options)
{
}
@@ -23,9 +23,9 @@ void UI_x_boxes::from_json(const json &j)
}
}
json UI_x_boxes::to_json() const
json UI_x_boxes::to_json(size_t id) const
{
json j = UI_item::to_json();
json j = UI_item::to_json(id);
j["options"] = this->m_options;
return j;
}
+2 -2
View File
@@ -7,11 +7,11 @@ class UI_x_boxes : public UI_item
Q_OBJECT
public:
UI_x_boxes(std::string type, QObject *parrent = nullptr);
UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color,
UI_x_boxes(std::string type, std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options, QObject *parrent = nullptr);
void from_json(const json &j) override;
json to_json() const override;
json to_json(size_t id) const override;
protected:
std::vector<std::string> m_options;