mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
update ui_combobox
remove ui_x_boxes and put the code in ui_combobox
This commit is contained in:
+14
-5
@@ -1,16 +1,16 @@
|
|||||||
#include "ui_combobox.hpp"
|
#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,
|
UI_combobox::UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected,
|
||||||
QObject *parent)
|
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);
|
from_json(j);
|
||||||
}
|
}
|
||||||
@@ -48,13 +48,22 @@ std::string UI_combobox::selected_text() const
|
|||||||
|
|
||||||
void UI_combobox::from_json(const json &j)
|
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");
|
m_selected = j.at("selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
json UI_combobox::to_json(size_t id) const
|
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;
|
j["selected"] = m_selected;
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ui_item.hpp"
|
#include "ui_item.hpp"
|
||||||
#include "ui_x_boxes.hpp"
|
|
||||||
|
|
||||||
#define UI_COMBOBOX_TYPE std::string("ui_combobox")
|
#define UI_COMBOBOX_TYPE std::string("ui_combobox")
|
||||||
|
|
||||||
class UI_combobox : public UI_x_boxes
|
class UI_combobox : public UI_item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@@ -25,5 +24,6 @@ class UI_combobox : public UI_x_boxes
|
|||||||
void changed(std::string selected);
|
void changed(std::string selected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector<std::string> m_options;
|
||||||
size_t m_selected;
|
size_t m_selected;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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<std::string> 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;
|
|
||||||
}
|
|
||||||
@@ -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<std::string> options,
|
|
||||||
QObject *parent = nullptr);
|
|
||||||
|
|
||||||
void from_json(const json &j) override;
|
|
||||||
json to_json(size_t id) const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::vector<std::string> m_options;
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user