diff --git a/client/plot_wrapper.cpp b/client/plot_wrapper.cpp new file mode 100644 index 0000000..2c1f2c0 --- /dev/null +++ b/client/plot_wrapper.cpp @@ -0,0 +1,15 @@ +#include "plot_wrapper.hpp" +#include + +Plot_wrapper::Plot_wrapper(QWidget *parent) : QwtPlot(parent) +{ + m_curve = new QwtPlotCurve("Test 1"); + m_curve->setPen(QPen(Qt::white)); + m_curve->attach(this); + this->replot(); +} + +QwtPlotCurve *Plot_wrapper::curve() const +{ + return m_curve; +} diff --git a/client/plot_wrapper.hpp b/client/plot_wrapper.hpp new file mode 100644 index 0000000..41556e9 --- /dev/null +++ b/client/plot_wrapper.hpp @@ -0,0 +1,20 @@ +#ifndef PLOT_WRAPPER_HPP +#define PLOT_WRAPPER_HPP + +#include +#include +#include +#include + +class Plot_wrapper : public QwtPlot +{ + Q_OBJECT + public: + Plot_wrapper(QWidget *parent = nullptr); + QwtPlotCurve *curve() const; + + private: + QwtPlotCurve *m_curve; +}; + +#endif // PLOT_WRAPPER_HPP diff --git a/client/simulator_base.cpp b/client/simulator_base.cpp index 9343d29..336b61a 100644 --- a/client/simulator_base.cpp +++ b/client/simulator_base.cpp @@ -1,5 +1,6 @@ #include "simulator_base.hpp" #include "can_transceive.hpp" +#include "plot_wrapper.hpp" Simulator_base::Simulator_base(QString sim_name, Web_socket_wrapper *web_socket, QWidget *parent) : QMainWindow{parent}, m_error_dialog(new NetworkError(this)), m_timer_update(new QTimer()), @@ -135,6 +136,11 @@ void Simulator_base::UI_item_parser(json &input) process_ui_checkbox(uiItem); continue; } + if (uiItem["type"] == "UI_plot") + { + process_ui_plot(uiItem); + continue; + } if (uiItem["type"] == "UI_can") { process_ui_can(uiItem); @@ -512,6 +518,30 @@ void Simulator_base::process_ui_led(json &uiItem) } } +void Simulator_base::process_ui_plot(json &uiItem) +{ + QWidget *widget = id_to_ui(uiItem["id"]); + if (widget == nullptr) + { + SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString()); + return; + } + + auto plot = qobject_cast(widget); + if (plot == nullptr) + { + SPDLOG_WARN("widget is not of type QwtPlot"); + return; + } + + QString text = QString::fromStdString(uiItem["text"]); + + if (text != plot->title().text()) + { + plot->setTitle(text); + } +} + void Simulator_base::process_ui_can(json &uiItem) { QWidget *widget = id_to_ui(uiItem["id"]); @@ -547,6 +577,7 @@ void Simulator_base::setup_ui_item(QWidget *item, size_t index) setup_checkbox(item, index); setup_dial(item, index); setup_slider(item, index); + setup_qwtplot(item, index); setup_can_ui(item, index); } @@ -599,6 +630,13 @@ void Simulator_base::setup_slider(QWidget *item, size_t index) [=, this] { m_web_socket->send_event(Web_socket_wrapper::Event::value_changed, index, slider->value()); }); } +void Simulator_base::setup_qwtplot(QWidget *item, size_t index) +{ + auto *plot = qobject_cast(item); + if (plot == nullptr) + return; +} + void Simulator_base::setup_can_ui(QWidget *item, size_t index) { Can_Transceive *can = qobject_cast(item); diff --git a/client/simulator_base.hpp b/client/simulator_base.hpp index d7e0fdd..a6b0fdf 100644 --- a/client/simulator_base.hpp +++ b/client/simulator_base.hpp @@ -46,6 +46,7 @@ class Simulator_base : public QMainWindow virtual void process_ui_checkbox(json &uiItem); virtual void process_ui_button(json &uiItem); virtual void process_ui_led(json &uiItem); + virtual void process_ui_plot(json &uiItem); virtual void process_ui_can(json &uiItem); void setup_ui_item(QWidget *item, size_t index); @@ -54,6 +55,7 @@ class Simulator_base : public QMainWindow void setup_checkbox(QWidget *item, size_t index); void setup_dial(QWidget *item, size_t index); void setup_slider(QWidget *item, size_t index); + void setup_qwtplot(QWidget *item, size_t index); void setup_can_ui(QWidget *item, size_t index); void showEvent(QShowEvent *event); diff --git a/client/simulators/test.cpp b/client/simulators/test.cpp index d75696d..e84c57d 100644 --- a/client/simulators/test.cpp +++ b/client/simulators/test.cpp @@ -16,6 +16,7 @@ Test_Sim::Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent) push_ui_item(ui->thermo); push_ui_item(ui->led); push_ui_item(ui->checkBox); + push_ui_item(ui->plot); } Test_Sim::~Test_Sim() diff --git a/client/simulators/test.ui b/client/simulators/test.ui index 88d5d6d..17e3834 100644 --- a/client/simulators/test.ui +++ b/client/simulators/test.ui @@ -15,35 +15,28 @@ - + PushButton - + PushButton - - - - - - 0 - - - - - - - + + + + CheckBox + + - + @@ -70,7 +63,28 @@ + + + + TextLabel + + + + + + + + 0 + + + + + + + + + @@ -84,20 +98,16 @@ - + - - - - TextLabel + + + + QFrame::Shape::StyledPanel - - - - - - CheckBox + + QFrame::Shadow::Raised @@ -136,6 +146,12 @@ QPushButton
led.hpp
+ + Plot_wrapper + QFrame +
plot_wrapper.hpp
+ 1 +