Files
remote-ui/UI/ui_plot.cpp
T
sani7 8b1db7af11 UI
optimize by passing by reference
optimize by using std::move
2026-02-14 14:32:47 +01:00

89 lines
1.6 KiB
C++

#include "ui_plot.hpp"
UI_plot::UI_plot(QObject *parent) : UI_item{UI_PLOT_TYPE, parent}
{
}
UI_plot::UI_plot(std::string text, std::string x_label, std::string y_label, QObject *parent)
: UI_item(UI_PLOT_TYPE, parent), m_x_label(x_label), m_y_label(y_label)
{
set_text(text);
}
void UI_plot::set_x_label(std::string name)
{
m_x_label = std::move(name);
emit ui_changed();
}
std::string UI_plot::x_label() const &
{
return m_x_label;
}
void UI_plot::set_y_label(std::string name)
{
m_y_label = std::move(name);
emit ui_changed();
}
std::string UI_plot::y_label() const &
{
return m_y_label;
}
void UI_plot::add_value(double y)
{
m_x_vals.push_back((double)m_x_vals.size());
m_y_vals.push_back(y);
emit ui_changed();
}
void UI_plot::add_value(double x, double y)
{
m_x_vals.push_back(x);
m_y_vals.push_back(y);
emit ui_changed();
}
const std::vector<double> &UI_plot::x_vals() const &
{
return m_x_vals;
}
const std::vector<double> &UI_plot::y_vals() const &
{
return m_y_vals;
}
void UI_plot::clean_vals()
{
m_x_vals.clear();
m_y_vals.clear();
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;
}