mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
simbase
move setup of ui to push_ui_item
This commit is contained in:
@@ -24,7 +24,6 @@ add_subdirectory(qwt)
|
|||||||
set(PROJECT_SOURCES
|
set(PROJECT_SOURCES
|
||||||
simulators/sim-cvs_i10.h
|
simulators/sim-cvs_i10.h
|
||||||
simulators/sim-cvs_i10.cpp
|
simulators/sim-cvs_i10.cpp
|
||||||
simulators/sim-cvs_i10_helper.cpp
|
|
||||||
simulators/sim-cvs_i10.ui
|
simulators/sim-cvs_i10.ui
|
||||||
|
|
||||||
simulators/sim-can_debugger.h
|
simulators/sim-can_debugger.h
|
||||||
|
|||||||
+44
-5
@@ -73,6 +73,7 @@ void SimulatorBase::on_event_cb(json& j)
|
|||||||
void SimulatorBase::push_ui_item(QWidget* item)
|
void SimulatorBase::push_ui_item(QWidget* item)
|
||||||
{
|
{
|
||||||
ui_lookup.emplace_back(item);
|
ui_lookup.emplace_back(item);
|
||||||
|
setup_ui_item(item, ui_lookup.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::button_update(size_t lookup)
|
void SimulatorBase::button_update(size_t lookup)
|
||||||
@@ -418,11 +419,6 @@ void SimulatorBase::process_ui_led(json& uiItem)
|
|||||||
QColor color = QColor(~bg_color.red(), ~bg_color.green(), ~bg_color.blue());
|
QColor color = QColor(~bg_color.red(), ~bg_color.green(), ~bg_color.blue());
|
||||||
QString text = QString::fromStdString(uiItem["text"]);
|
QString text = QString::fromStdString(uiItem["text"]);
|
||||||
|
|
||||||
if (false == is_read_only(led))
|
|
||||||
{
|
|
||||||
set_read_only(led);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text != led->text())
|
if (text != led->text())
|
||||||
{
|
{
|
||||||
led->setText(text);
|
led->setText(text);
|
||||||
@@ -457,3 +453,46 @@ void SimulatorBase::process_ui_led(json& uiItem)
|
|||||||
set_widget_color(led, color, bg_color);
|
set_widget_color(led, color, bg_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimulatorBase::setup_ui_item(QWidget* item, size_t index)
|
||||||
|
{
|
||||||
|
setup_button(item, index);
|
||||||
|
setup_combobox(item, index);
|
||||||
|
setup_dial(item, index);
|
||||||
|
setup_slider(item, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorBase::setup_button(QWidget* item, size_t index)
|
||||||
|
{
|
||||||
|
QPushButton* button = qobject_cast<QPushButton*>(item);
|
||||||
|
if (button == nullptr)
|
||||||
|
return;
|
||||||
|
connect(button, &QPushButton::clicked, this, [=, this]{button_update(index);});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorBase::setup_combobox(QWidget* item, size_t index)
|
||||||
|
{
|
||||||
|
QComboBox* combobox = qobject_cast<QComboBox*>(item);
|
||||||
|
if (combobox == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect(combobox, &QComboBox::currentIndexChanged, this, [=, this]{combobox_update(index);});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorBase::setup_dial(QWidget* item, size_t index)
|
||||||
|
{
|
||||||
|
QwtDial* dial = qobject_cast<QwtDial*>(item);
|
||||||
|
if (dial == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
create_dial_needle(dial);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorBase::setup_slider(QWidget* item, size_t index)
|
||||||
|
{
|
||||||
|
QwtSlider* slider = qobject_cast<QwtSlider*>(item);
|
||||||
|
if (slider == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect(slider, &QwtSlider::sliderMoved, this, [=, this]{slider_update(index);});
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ class SimulatorBase : public QMainWindow {
|
|||||||
virtual void process_ui_button(json& uiItem);
|
virtual void process_ui_button(json& uiItem);
|
||||||
virtual void process_ui_led(json& uiItem);
|
virtual void process_ui_led(json& uiItem);
|
||||||
|
|
||||||
|
void setup_ui_item(QWidget* item, size_t index);
|
||||||
|
void setup_button(QWidget* item, size_t index);
|
||||||
|
void setup_combobox(QWidget* item, size_t index);
|
||||||
|
void setup_dial(QWidget* item, size_t index);
|
||||||
|
void setup_slider(QWidget* item, size_t index);
|
||||||
|
|
||||||
void showEvent(QShowEvent* event);
|
void showEvent(QShowEvent* event);
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent* event);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user