diff --git a/Qt/helpers.h b/Qt/helpers.h index 9daf2ba..cc46c25 100644 --- a/Qt/helpers.h +++ b/Qt/helpers.h @@ -9,6 +9,7 @@ #include #include #include +#include #include void create_dial_needle(QwtDial* dial); diff --git a/Qt/simulatorbase.cpp b/Qt/simulatorbase.cpp index a7e9bfa..facd048 100644 --- a/Qt/simulatorbase.cpp +++ b/Qt/simulatorbase.cpp @@ -81,6 +81,16 @@ void SimulatorBase::UI_item_parser(json& input) process_ui_slider(uiItem); continue; } + if (uiItem["type"] == "UI_dial") + { + process_ui_dial(uiItem); + continue; + } + if (uiItem["type"] == "UI_thermo") + { + process_ui_thermo(uiItem); + continue; + } if (uiItem["type"] == "UI_textbox") { process_ui_textbox(uiItem); @@ -157,6 +167,66 @@ void SimulatorBase::process_ui_slider(json& uiItem) return; } +void SimulatorBase::process_ui_dial(json& uiItem) +{ + QwtDial* dial = id_to_dial(QString::fromStdString(uiItem["id"])); + QLabel* label = id_to_dial_label(QString::fromStdString(uiItem["id"])); + if (dial == nullptr) + { + QD << "id_to_dial returned null on " << QString::fromStdString(uiItem["id"]); + return; + } + + double value = uiItem["value"]; + bool visible = uiItem["visible"]; + + if (dial->value() != value) + { + if (label != nullptr) + { + label->setText(format_slider_value(QString::fromStdString(uiItem["id"]), value)); + } + dial->setValue(value); + } + + + if (dial->isVisible() != visible) + { + dial->setVisible(visible); + } + return; +} + +void SimulatorBase::process_ui_thermo(json& uiItem) +{ + QwtThermo* thermo = id_to_thermo(QString::fromStdString(uiItem["id"])); + QLabel* label = id_to_thermo_label(QString::fromStdString(uiItem["id"])); + if (thermo == nullptr) + { + QD << "id_to_dial returned null on " << QString::fromStdString(uiItem["id"]); + return; + } + + double value = uiItem["value"]; + bool visible = uiItem["visible"]; + + if (thermo->value() != value) + { + if (label != nullptr) + { + label->setText(format_slider_value(QString::fromStdString(uiItem["id"]), value)); + } + thermo->setValue(value); + } + + + if (thermo->isVisible() != visible) + { + thermo->setVisible(visible); + } + return; +} + void SimulatorBase::process_ui_textbox(json& uiItem) { QD << "Not implemented"; diff --git a/Qt/simulatorbase.h b/Qt/simulatorbase.h index fbfa6a7..56904ab 100644 --- a/Qt/simulatorbase.h +++ b/Qt/simulatorbase.h @@ -29,6 +29,9 @@ class SimulatorBase : public QMainWindow { virtual QwtDial* id_to_dial(QString name) {return nullptr;} virtual QLabel* id_to_dial_label(QString name) {return nullptr;} virtual QString format_dial_value(QString name, double val) {return QString();} + virtual QwtThermo* id_to_thermo(QString name) {return nullptr;} + virtual QLabel* id_to_thermo_label(QString name) {return nullptr;} + virtual QString format_thermo_label(QString name) {return QString();} virtual QComboBox* id_to_combobox(QString name) {return nullptr;} virtual QTextEdit* id_to_textbox(QString name) {return nullptr;} @@ -40,6 +43,8 @@ class SimulatorBase : public QMainWindow { void UI_item_parser(json& input); virtual void process_ui_label(json& uiItem); virtual void process_ui_slider(json& uiItem); + virtual void process_ui_dial(json& uiItem); + virtual void process_ui_thermo(json& uiItem); virtual void process_ui_textbox(json& uiItem); virtual void process_ui_combobox(json& uiItem); virtual void process_ui_radiobutton(json& uiItem);