update ui_combobox

remove ui_x_boxes and put the code in ui_combobox
This commit is contained in:
2026-02-14 14:32:03 +01:00
parent 7c91a64d71
commit 7386a12f1b
4 changed files with 16 additions and 56 deletions
+14 -5
View File
@@ -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<std::string> 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;
}