mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
2.0 KiB
2.0 KiB
Client UI
To create a new simulator ui follow these steps
- Make sure the client folder is folded down
- Right click on unisim_client and select Add new
- Choose Qt in files and classes and then select Qt widgets designer form class + Choose
- Select Mainwindow + Next
- Change the classname to the name of your sim use underscores as spaces, don't forget classnames always start with a capital letter
- Select the path by clicking browse, and make sure it is in the client/simulators folder + Next
- Set add to project to None + Finished
- Refresh CMake by right clicking on the project name + Run Cmake, it should show your sim as ui_ + filename
- Change the hpp file as following. This is an example out of test sim
OPTIONAL Add id_to_label is optional if you want to use value labels
#pragma once
#include "simulator_base.hpp"
namespace Ui
{
class Test_Sim;
}
class Test_Sim : public Simulator_base
{
Q_OBJECT
public:
explicit Test_Sim(Web_socket_wrapper *web_socket = nullptr, QWidget *parent = nullptr);
~Test_Sim();
// Optional
QLabel *id_to_label(QWidget* widget) override;
private:
Ui::Test_Sim *ui;
};
- Change the cpp file as following. This is an example out of test sim. PUSH_UI_ITEM is the method to add new QWidgets to the similator UI
OPTIONAL Add id_to_label is optional if you want to use value labels switch case is also an option instead of if
#include "test.hpp"
#include "ui_test.h"
EXPORT_UI(Test_Sim);
Test_Sim::Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent)
: Simulator_base("Test Sim", web_socket, parent), ui(new Ui::Test_Sim)
{
ui->setupUi(this);
PUSH_UI_ITEM(item);
}
Test_Sim::~Test_Sim()
{
delete ui;
}
QLabel *Test_Sim::id_to_label(QWidget* widget)
{
if (widget == ui->slider)
return ui->slider_label;
if (widget == ui->thermo)
return ui->thermo_label;
if (widget == ui->dial)
return ui->dial_label;
return nullptr;
}
For extra examples look at the existing simulators