Files
remote-ui/UI/ui_plot.cpp
T
sani7 2a76e13305 Removes JSON constructor from UI elements
This fixes the error: clang:optin.cplusplus.VirtualCall
When virtual methods are called during construction and destruction the polymorphism is restricted to the class that’s being constructed or destructed because the more derived contexts are either not yet initialized or already destructed.
2026-02-14 14:32:16 +01:00

79 lines
1.4 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 = 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 = 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();
}
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;
}