From 0a1811ea769f73e1696a8c262579732cbef55e27 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Fri, 22 Nov 2024 22:36:00 +0100 Subject: [PATCH] fix rebase errors --- Qt/mainwindow.cpp | 2 +- Qt/simulatorbase.cpp | 26 ++++++++++++++------------ Qt/simulatorbase.h | 10 ++++++---- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index f852d9c..df06780 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -111,7 +111,7 @@ void MainWindow::check_active_sim(QString name) if (name == m_selected_sim_name) { - QD << "Name set and right"; + QD << "Name set and the same"; open_sim_window(); return; } diff --git a/Qt/simulatorbase.cpp b/Qt/simulatorbase.cpp index c3fccbc..98e88e0 100644 --- a/Qt/simulatorbase.cpp +++ b/Qt/simulatorbase.cpp @@ -3,15 +3,16 @@ SimulatorBase::SimulatorBase(Web_socket_wrapper* web_socket, QWidget* parent) : QMainWindow{parent}, m_error_dialog(new NetworkError(this)), + m_timer_update(new QTimer()), m_web_socket(web_socket) { m_error_dialog->set_error("Connection timed out\nCheck if the server is running"); - ui_lookup.reserve(40); + m_ui_lookup.reserve(40); } QWidget* SimulatorBase::id_to_ui(size_t id) { - return ui_lookup.at(id); + return m_ui_lookup.at(id); } void SimulatorBase::showEvent( QShowEvent* event ) @@ -19,21 +20,22 @@ void SimulatorBase::showEvent( QShowEvent* event ) QWidget::showEvent( event ); QD << "Connecting callbacks"; setup_cb(); - this->timer_update->start(refresh_rate); - closed = false; + m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements); + this->m_timer_update->start(m_refresh_rate); + m_open = true; } void SimulatorBase::closeEvent(QCloseEvent* event) { - if (!closed) + if (m_open == true) { QD << "Disconnecting callbacks"; QWidget::closeEvent(event); - this->timer_update->stop(); - disconnect(api, nullptr, nullptr, nullptr); + m_timer_update->stop(); + disconnect(m_web_socket, nullptr, nullptr, nullptr); + m_open = false; this->parentWidget()->show(); } - closed = true; } void SimulatorBase::setup_cb(void) @@ -72,8 +74,8 @@ void SimulatorBase::on_event_cb(json& j) void SimulatorBase::push_ui_item(QWidget* item) { - ui_lookup.emplace_back(item); - setup_ui_item(item, ui_lookup.size()); + m_ui_lookup.emplace_back(item); + setup_ui_item(item, m_ui_lookup.size() - 1); } void SimulatorBase::button_update(size_t lookup) @@ -83,7 +85,7 @@ void SimulatorBase::button_update(size_t lookup) void SimulatorBase::slider_update(size_t lookup) { - QwtSlider* slider = qobject_cast(ui_lookup.at(lookup)); + QwtSlider* slider = qobject_cast(m_ui_lookup.at(lookup)); if (slider == nullptr) return; m_web_socket->send_event(Web_socket_wrapper::Event::value_changed, lookup, @@ -92,7 +94,7 @@ void SimulatorBase::slider_update(size_t lookup) void SimulatorBase::combobox_update(size_t lookup) { - QComboBox* combobox = qobject_cast(ui_lookup.at(lookup)); + QComboBox* combobox = qobject_cast(m_ui_lookup.at(lookup)); if (combobox == nullptr) return; m_web_socket->send_event(Web_socket_wrapper::Event::selected, lookup, diff --git a/Qt/simulatorbase.h b/Qt/simulatorbase.h index 7fa208d..db88bef 100644 --- a/Qt/simulatorbase.h +++ b/Qt/simulatorbase.h @@ -56,12 +56,14 @@ class SimulatorBase : public QMainWindow { void showEvent(QShowEvent* event); void closeEvent(QCloseEvent* event); + private: Web_socket_wrapper* m_web_socket; - QTimer* timer_update; - uint32_t refresh_rate; - NetworkError* error_dialog; - bool closed = false; + QTimer* m_timer_update; + uint32_t m_refresh_rate; + NetworkError* m_error_dialog; + bool m_open = false; + std::vectorm_ui_lookup; }; #endif // SIMULATORBASE_H