Update UI

This commit is contained in:
2026-08-20 13:27:31 +02:00
parent ecbd8bf8a9
commit cb41ac2aa2
40 changed files with 773 additions and 1436 deletions
+58 -41
View File
@@ -1,88 +1,105 @@
#include "ui_plot.hpp"
UI_plot::UI_plot(QObject *parent) : UI_item{UI_enum::ui_plot, parent}
UI_plot::UI_plot(QObject *parent) : UI_item{UI_typeGadget::UI_type::ui_plot, parent}
{
m_ui_item.setPlot(UI_plot_m());
}
UI_plot::UI_plot(std::string text, std::string x_label, std::string y_label, QObject *parent)
: UI_item(UI_enum::ui_plot, parent), m_x_label(x_label), m_y_label(y_label)
UI_plot::UI_plot(QString text, QString x_label, QString y_label, QObject *parent)
: UI_item(UI_typeGadget::UI_type::ui_plot, parent)
{
set_text(text);
m_ui_item.setPlot(UI_plot_m());
m_ui_item.plot().setText(text);
m_ui_item.plot().setXLabel(x_label);
m_ui_item.plot().setYLabel(y_label);
}
void UI_plot::set_x_label(std::string name)
void UI_plot::set_x_label(QString name)
{
m_x_label = std::move(name);
m_ui_item.plot().setXLabel(name);
emit ui_changed();
}
std::string UI_plot::x_label() const &
QString UI_plot::x_label() const &
{
return m_x_label;
return m_ui_item.plot().xLabel();
}
void UI_plot::set_y_label(std::string name)
void UI_plot::set_y_label(QString name)
{
m_y_label = std::move(name);
m_ui_item.plot().setYLabel(name);
emit ui_changed();
}
std::string UI_plot::y_label() const &
QString UI_plot::y_label() const &
{
return m_y_label;
return m_ui_item.plot().yLabel();
}
void UI_plot::set_fg_color(Color color)
{
m_ui_item.plot().mutColor().setFgColor(color.color());
emit ui_changed();
}
Color UI_plot::fg_color() const&
{
return Color(m_ui_item.plot().color().fgColor());
}
void UI_plot::set_bg_color(Color color)
{
m_ui_item.plot().mutColor().setBgColor(color.color());
emit ui_changed();
}
Color UI_plot::bg_color() const
{
return Color(m_ui_item.plot().color().bgColor());
}
void UI_plot::add_value(double y)
{
m_x_vals.push_back((double)m_x_vals.size());
m_y_vals.push_back(y);
auto x_vals = m_ui_item.plot().xVals();
auto y_vals = m_ui_item.plot().yVals();
x_vals.push_back((double)x_vals.size());
y_vals.push_back(y);
m_ui_item.plot().setXVals(x_vals);
m_ui_item.plot().setYVals(y_vals);
emit ui_changed();
}
void UI_plot::add_value(double x, double y)
{
m_x_vals.push_back(x);
m_y_vals.push_back(y);
auto x_vals = m_ui_item.plot().xVals();
auto y_vals = m_ui_item.plot().yVals();
x_vals.push_back(x);
y_vals.push_back(y);
m_ui_item.plot().setXVals(x_vals);
m_ui_item.plot().setYVals(y_vals);
emit ui_changed();
}
const std::vector<double> &UI_plot::x_vals() const &
const QList<double> &UI_plot::x_vals() const &
{
return m_x_vals;
return m_ui_item.plot().xVals();
}
const std::vector<double> &UI_plot::y_vals() const &
const QList<double> &UI_plot::y_vals() const &
{
return m_y_vals;
return m_ui_item.plot().yVals();
}
void UI_plot::clean_vals()
{
m_x_vals.clear();
m_y_vals.clear();
m_ui_item.plot().setXVals(QList<double>());
m_ui_item.plot().setYVals(QList<double>());
emit ui_changed();
}
void UI_plot::from_json(const json &j)
{
UI_item::from_json(j);
this->m_x_label = j.at("x_label");
this->m_y_label = j.at("y_label");
this->m_x_vals = (std::vector<double>)j.at("x_vals");
this->m_y_vals = (std::vector<double>)j.at("y_vals");
}
json UI_plot::to_json(size_t id) const
{
json j = UI_item::to_json(id);
j["x_label"] = m_x_label;
j["y_label"] = m_y_label;
j["x_vals"] = m_x_vals;
j["y_vals"] = m_y_vals;
return j;
}