diff --git a/src/UI/UI_checkbox.cpp b/src/UI/UI_checkbox.cpp index 98db114..58bf40d 100644 --- a/src/UI/UI_checkbox.cpp +++ b/src/UI/UI_checkbox.cpp @@ -1,53 +1,51 @@ #include "UI_checkbox.hpp" -UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m_selected() +UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m_checked() { } UI_checkbox::UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent) - : UI_item(UI_CHECKBOX_TYPE, text, 0, fg_color, bg_color, parent), m_selected(false) + : UI_item(UI_CHECKBOX_TYPE, text, 0, fg_color, bg_color, parent), m_checked(false) { } -UI_checkbox::UI_checkbox(const json &j, QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m_selected() +UI_checkbox::UI_checkbox(const json &j, QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m_checked() { from_json(j); } -void UI_checkbox::toggle_selected() +void UI_checkbox::clicked() { - m_selected = !m_selected; + m_checked = !m_checked; emit value_changed(); - emit on_change(m_text); + emit on_change(m_checked); } -bool UI_checkbox::selected() const +void UI_checkbox::set_state(bool state) { - return m_selected; + m_checked = state; + emit value_changed(); + emit on_change(m_checked); } -std::string UI_checkbox::selected_text() const +bool UI_checkbox::state() const { - if (m_selected) - { - return m_text; - } - return ""; + return m_checked; } void UI_checkbox::from_json(const json &j) { UI_item::from_json(j); - if (j.contains("selected")) + if (j.contains("checked")) { - m_selected = j["selected"]; + m_checked = j["checked"]; } } json UI_checkbox::to_json(size_t id) const { json j = UI_item::to_json(id); - j["selected"] = m_selected; + j["checked"] = m_checked; return j; } diff --git a/src/UI/UI_checkbox.hpp b/src/UI/UI_checkbox.hpp index dc129f9..b009f04 100644 --- a/src/UI/UI_checkbox.hpp +++ b/src/UI/UI_checkbox.hpp @@ -11,17 +11,17 @@ class UI_checkbox : public UI_item UI_checkbox(QObject *parent = nullptr); UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); UI_checkbox(const json &j, QObject *parent = nullptr); - - void toggle_selected(); - bool selected() const; - std::string selected_text() const; + + void clicked(); + void set_state(bool state); + bool state() const; void from_json(const json &j) override; json to_json(size_t id) const override; signals: - void on_change(std::string); + void on_change(bool); private: - bool m_selected; + bool m_checked; }; diff --git a/tests/UI_checkbox.cpp b/tests/UI_checkbox.cpp index f5257f1..5eade45 100644 --- a/tests/UI_checkbox.cpp +++ b/tests/UI_checkbox.cpp @@ -8,5 +8,5 @@ TEST(UI_checkbox, to_from_json) EXPECT_EQ(checkbox.text(), checkbox2.text()); EXPECT_EQ(checkbox.fg_color(), checkbox2.fg_color()); EXPECT_EQ(checkbox.bg_color(), checkbox2.bg_color()); - EXPECT_EQ(checkbox.selected(), checkbox2.selected()); -} \ No newline at end of file + EXPECT_EQ(checkbox.state(), checkbox2.state()); +}