mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
Initial plot
add client plot wrapper add initial process function add plot in test ui
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
#include "plot_wrapper.hpp"
|
||||
#include <QPen>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef PLOT_WRAPPER_HPP
|
||||
#define PLOT_WRAPPER_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_text.h>
|
||||
|
||||
class Plot_wrapper : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Plot_wrapper(QWidget *parent = nullptr);
|
||||
QwtPlotCurve *curve() const;
|
||||
|
||||
private:
|
||||
QwtPlotCurve *m_curve;
|
||||
};
|
||||
|
||||
#endif // PLOT_WRAPPER_HPP
|
||||
@@ -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<Plot_wrapper *>(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<QwtPlot *>(item);
|
||||
if (plot == nullptr)
|
||||
return;
|
||||
}
|
||||
|
||||
void Simulator_base::setup_can_ui(QWidget *item, size_t index)
|
||||
{
|
||||
Can_Transceive *can = qobject_cast<Can_Transceive *>(item);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
+40
-24
@@ -15,35 +15,28 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="3">
|
||||
<item row="2" column="4">
|
||||
<widget class="QPushButton" name="button">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<item row="1" column="4">
|
||||
<widget class="Led" name="led">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="slider_label">
|
||||
<item row="1" column="2">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
<string>CheckBox</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QwtSlider" name="slider"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<item row="4" column="4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="dial_label">
|
||||
@@ -70,7 +63,28 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="slider_label">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QwtSlider" name="slider"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="thermo_label">
|
||||
@@ -84,20 +98,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<item row="3" column="4">
|
||||
<widget class="QComboBox" name="combobox"/>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<item row="5" column="1">
|
||||
<widget class="Plot_wrapper" name="plot">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -136,6 +146,12 @@
|
||||
<extends>QPushButton</extends>
|
||||
<header>led.hpp</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Plot_wrapper</class>
|
||||
<extends>QFrame</extends>
|
||||
<header location="global">plot_wrapper.hpp</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Reference in New Issue
Block a user