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.
This commit is contained in:
DevTekVE
2024-07-14 11:15:31 +02:00
parent e3939247a7
commit beef2f0be9
4 changed files with 10 additions and 26 deletions
+3 -6
View File
@@ -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;
};
+1 -4
View File
@@ -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;
-4
View File
@@ -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, [=]() {
+6 -12
View File
@@ -4,17 +4,15 @@
#include <QWidget>
#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;
};