From beef2f0be94930108507748f2c5cb8f587d89baf Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sun, 14 Jul 2024 11:15:31 +0200 Subject: [PATCH] Refactor SunnyPilot preprocessor directives in UI code This commit simplifies the conditional preprocessor directives related to SunnyPilot in various parts of the UI code. The previous use of #ifdef SUNNYPILOT has been consolidated to make the code cleaner and easier to read. Also, some unused code blocks have been removed. This refactoring simplifies the management of different configuration setups. --- selfdrive/ui/qt/widgets/controls.h | 9 +++------ selfdrive/ui/qt/widgets/toggle.h | 5 +---- selfdrive/ui/qt/window.cc | 4 ---- selfdrive/ui/qt/window.h | 18 ++++++------------ 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index a68484f905..3c5766d137 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -15,10 +15,9 @@ #ifdef SUNNYPILOT #include "selfdrive/ui/sunnypilot/qt/sp_priv_util.h" #include "selfdrive/ui/sunnypilot/qt/widgets/sp_priv_toggle.h" -#define TOGGLE ToggleSP +#define Toggle ToggleSP #else #include "selfdrive/ui/qt/widgets/toggle.h" -#define TOGGLE Toggle #endif class ElidedLabel : public QLabel { @@ -146,7 +145,7 @@ public: toggle.togglePosition(); } hlayout->addWidget(&toggle); - QObject::connect(&toggle, &TOGGLE::stateChanged, this, &ToggleControl::toggleFlipped); + QObject::connect(&toggle, &Toggle::stateChanged, this, &ToggleControl::toggleFlipped); } void setEnabled(bool enabled) { @@ -158,7 +157,7 @@ signals: void toggleFlipped(bool state); protected: - TOGGLE toggle; + Toggle toggle; }; // widget to toggle params @@ -317,9 +316,7 @@ private: } QVBoxLayout outer_layout; -#ifdef SUNNYPILOT protected: -#endif QVBoxLayout inner_layout; }; diff --git a/selfdrive/ui/qt/widgets/toggle.h b/selfdrive/ui/qt/widgets/toggle.h index 49e0614b10..0c544b917f 100644 --- a/selfdrive/ui/qt/widgets/toggle.h +++ b/selfdrive/ui/qt/widgets/toggle.h @@ -29,10 +29,7 @@ protected: void paintEvent(QPaintEvent*) override; void mouseReleaseEvent(QMouseEvent*) override; void enterEvent(QEvent*) override; - -#ifndef SUNNYPILOT -private: -#endif + QColor circleColor; QColor green; bool enabled = true; diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 4ff91b1748..00b4693822 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -13,11 +13,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { QObject::connect(homeWindow, &HomeWindow::openSettings, this, &MainWindow::openSettings); QObject::connect(homeWindow, &HomeWindow::closeSettings, this, &MainWindow::closeSettings); -#ifdef SUNNYPILOT - settingsWindow = new SettingsWindowSP(this); -#else settingsWindow = new SettingsWindow(this); -#endif main_layout->addWidget(settingsWindow); QObject::connect(settingsWindow, &SettingsWindow::closeSettings, this, &MainWindow::closeSettings); QObject::connect(settingsWindow, &SettingsWindow::reviewTrainingGuide, [=]() { diff --git a/selfdrive/ui/qt/window.h b/selfdrive/ui/qt/window.h index b13b250a9b..016f0fd23d 100644 --- a/selfdrive/ui/qt/window.h +++ b/selfdrive/ui/qt/window.h @@ -4,17 +4,15 @@ #include #include "selfdrive/ui/qt/offroad/onboarding.h" -#ifdef SUNNYPILOT -#include "selfdrive/ui/sunnypilot/qt/offroad/sp_priv_settings.h" -#else -#include "selfdrive/ui/qt/offroad/settings.h" -#endif #ifdef SUNNYPILOT -#include "selfdrive/ui/sunnypilot/qt/sp_priv_home.h" -#define HomeWindow HomeWindowSP + #include "selfdrive/ui/sunnypilot/qt/offroad/sp_priv_settings.h" + #include "selfdrive/ui/sunnypilot/qt/sp_priv_home.h" + #define HomeWindow HomeWindowSP + #define SettingsWindow SettingsWindowSP #else -#include "selfdrive/ui/qt/home.h" + #include "selfdrive/ui/qt/offroad/settings.h" + #include "selfdrive/ui/qt/home.h" #endif class MainWindow : public QWidget { @@ -30,10 +28,6 @@ private: QStackedLayout *main_layout; HomeWindow *homeWindow; -#ifdef SUNNYPILOT - SettingsWindowSP *settingsWindow; -#else SettingsWindow *settingsWindow; -#endif OnboardingWindow *onboardingWindow; };