diff --git a/UI/ui_combobox.cpp b/UI/ui_combobox.cpp index f01164e..86f256f 100644 --- a/UI/ui_combobox.cpp +++ b/UI/ui_combobox.cpp @@ -1,16 +1,16 @@ #include "ui_combobox.hpp" -UI_combobox::UI_combobox(QObject *parent) : UI_x_boxes(UI_COMBOBOX_TYPE, parent) +UI_combobox::UI_combobox(QObject *parent) : UI_item(UI_COMBOBOX_TYPE, parent), m_options() { } UI_combobox::UI_combobox(Color fg_color, Color bg_color, std::vector options, size_t selected, QObject *parent) - : UI_x_boxes(UI_COMBOBOX_TYPE, "", fg_color, bg_color, options, parent), m_selected(selected) + : UI_item(UI_COMBOBOX_TYPE, "", 12, fg_color, bg_color, parent), m_options(options), m_selected(selected) { } -UI_combobox::UI_combobox(const json &j, QObject *parent) : UI_x_boxes(UI_COMBOBOX_TYPE, parent) +UI_combobox::UI_combobox(const json &j, QObject *parent) : UI_item(UI_COMBOBOX_TYPE, parent) { from_json(j); } @@ -48,13 +48,22 @@ std::string UI_combobox::selected_text() const void UI_combobox::from_json(const json &j) { - UI_x_boxes::from_json(j); + UI_item::from_json(j); + if (j.contains("options")) + { + this->m_options.clear(); + for (auto option : j["options"]) + { + this->m_options.push_back(option); + } + } m_selected = j.at("selected"); } json UI_combobox::to_json(size_t id) const { - json j = UI_x_boxes::to_json(id); + json j = UI_item::to_json(id); + j["options"] = this->m_options; j["selected"] = m_selected; return j; } diff --git a/UI/ui_combobox.hpp b/UI/ui_combobox.hpp index f742ed3..24c6b07 100644 --- a/UI/ui_combobox.hpp +++ b/UI/ui_combobox.hpp @@ -1,11 +1,10 @@ #pragma once #include "ui_item.hpp" -#include "ui_x_boxes.hpp" #define UI_COMBOBOX_TYPE std::string("ui_combobox") -class UI_combobox : public UI_x_boxes +class UI_combobox : public UI_item { Q_OBJECT public: @@ -25,5 +24,6 @@ class UI_combobox : public UI_x_boxes void changed(std::string selected); private: + std::vector m_options; size_t m_selected; }; diff --git a/UI/ui_x_boxes.cpp b/UI/ui_x_boxes.cpp deleted file mode 100644 index 01d1b09..0000000 --- a/UI/ui_x_boxes.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "ui_x_boxes.hpp" - -UI_x_boxes::UI_x_boxes(std::string type, QObject *parent) : UI_item(type, parent), m_options() -{ -} - -UI_x_boxes::UI_x_boxes(std::string type, std::string text, Color fg_color, Color bg_color, - std::vector options, QObject *parent) - : UI_item(type, text, 12, fg_color, bg_color, parent), m_options(options) -{ -} - -void UI_x_boxes::from_json(const json &j) -{ - UI_item::from_json(j); - if (j.contains("options")) - { - this->m_options.clear(); - for (auto option : j["options"]) - { - this->m_options.push_back(option); - } - } -} - -json UI_x_boxes::to_json(size_t id) const -{ - json j = UI_item::to_json(id); - j["options"] = this->m_options; - return j; -} diff --git a/UI/ui_x_boxes.hpp b/UI/ui_x_boxes.hpp deleted file mode 100644 index ac765c5..0000000 --- a/UI/ui_x_boxes.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "ui_item.hpp" - -class UI_x_boxes : public UI_item -{ - Q_OBJECT - public: - UI_x_boxes(std::string type, QObject *parent = nullptr); - UI_x_boxes(std::string type, std::string text, Color fg_color, Color bg_color, std::vector options, - QObject *parent = nullptr); - - void from_json(const json &j) override; - json to_json(size_t id) const override; - - protected: - std::vector m_options; -};