From a4926ef332aa6102c2bfb581873d7e7a01d0bd1d Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Tue, 16 Jul 2024 23:14:57 +0200 Subject: [PATCH] Rename and remove custom abstracts for map support Refactor class names by renaming AbstractControl to AbstractControlSP_TITLED and LayoutWidget to LayoutWidgetSP. Removed conditional compilation definitions for map support to streamline the code and avoid multiple definition errors. --- selfdrive/ui/qt/offroad_home.h | 1 + .../sunnypilot/qt/widgets/sp_priv_controls.cc | 6 ++--- .../sunnypilot/qt/widgets/sp_priv_controls.h | 27 +++++++------------ 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/selfdrive/ui/qt/offroad_home.h b/selfdrive/ui/qt/offroad_home.h index f277d852c4..be905861e1 100644 --- a/selfdrive/ui/qt/offroad_home.h +++ b/selfdrive/ui/qt/offroad_home.h @@ -21,6 +21,7 @@ #include "selfdrive/ui/sunnypilot/qt/sp_priv_sidebar.h" #define OnroadWindow OnroadWindowSP #define OffroadHomeImp OffroadHomeSP +#define LayoutWidget LayoutWidgetSP #define Sidebar SidebarSP #else #include "selfdrive/ui/qt/widgets/controls.h" diff --git a/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.cc b/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.cc index 4ba1f31c9e..7f9985a70c 100644 --- a/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.cc +++ b/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.cc @@ -15,7 +15,7 @@ QFrame *horizontal_line(QWidget *parent) { return line; } -AbstractControl::AbstractControl(const QString &title, const QString &desc, const QString &icon, QWidget *parent) : QFrame(parent) { +AbstractControlSP_TITLED::AbstractControlSP_TITLED(const QString &title, const QString &desc, const QString &icon, QWidget *parent) : QFrame(parent) { QVBoxLayout *main_layout = new QVBoxLayout(this); main_layout->setMargin(0); @@ -68,7 +68,7 @@ AbstractControl::AbstractControl(const QString &title, const QString &desc, cons main_layout->addStretch(); } -void AbstractControl::hideEvent(QHideEvent *e) { +void AbstractControlSP_TITLED::hideEvent(QHideEvent *e) { if (description != nullptr) { description->hide(); } @@ -121,7 +121,7 @@ void AbstractControlSP::hideEvent(QHideEvent *e) { // controls -ButtonControlSP::ButtonControlSP(const QString &title, const QString &text, const QString &desc, QWidget *parent) : AbstractControl(title, desc, "", parent) { +ButtonControlSP::ButtonControlSP(const QString &title, const QString &text, const QString &desc, QWidget *parent) : AbstractControlSP_TITLED(title, desc, "", parent) { btn.setText(text); btn.setStyleSheet(R"( QPushButton { diff --git a/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.h b/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.h index 2549384e3e..44255b2d99 100644 --- a/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.h +++ b/selfdrive/ui/sunnypilot/qt/widgets/sp_priv_controls.h @@ -25,15 +25,6 @@ #define Toggle ToggleSP #define ToggleControl ToggleControlSP -// To avoid multiple definition errors for AbstractControl and LayoutWidget when ENABLE_MAPS is defined, -// we redefine these classes with custom names (AbstractControlCustomSP and LayoutWidgetSP). -// This ensures that the linker does not encounter duplicate symbols for these classes from different sources. -// This redefinition is only necessary when building with map support; it is not needed if map functionality is not required. -#ifdef ENABLE_MAPS -#define AbstractControl AbstractControlCustomSP -#define LayoutWidget LayoutWidgetSP -#endif - QFrame *horizontal_line(QWidget *parent = nullptr); class ElidedLabelSP : public QLabel { @@ -61,7 +52,7 @@ protected: QString lastText_, elidedText_; }; -class AbstractControl : public QFrame { +class AbstractControlSP_TITLED : public QFrame { Q_OBJECT public: @@ -100,7 +91,7 @@ public: void showDescriptionEvent(); protected: - AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr); + AbstractControlSP_TITLED(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr); void hideEvent(QHideEvent *e) override; QHBoxLayout *hlayout; @@ -153,11 +144,11 @@ private: // widget to display a value -class LabelControlSP : public AbstractControl { +class LabelControlSP : public AbstractControlSP_TITLED { Q_OBJECT public: - LabelControlSP(const QString &title, const QString &text = "", const QString &desc = "", QWidget *parent = nullptr) : AbstractControl(title, desc, "", parent) { + LabelControlSP(const QString &title, const QString &text = "", const QString &desc = "", QWidget *parent = nullptr) : AbstractControlSP_TITLED(title, desc, "", parent) { label.setText(text); label.setAlignment(Qt::AlignRight | Qt::AlignVCenter); hlayout->addWidget(&label); @@ -169,7 +160,7 @@ private: }; // widget for a button with a label -class ButtonControlSP : public AbstractControl { +class ButtonControlSP : public AbstractControlSP_TITLED { Q_OBJECT public: @@ -188,11 +179,11 @@ private: QPushButton btn; }; -class ToggleControlSP : public AbstractControl { +class ToggleControlSP : public AbstractControlSP_TITLED { Q_OBJECT public: - ToggleControlSP(const QString &title, const QString &desc = "", const QString &icon = "", const bool state = false, QWidget *parent = nullptr) : AbstractControl(title, desc, icon, parent) { + ToggleControlSP(const QString &title, const QString &desc = "", const QString &icon = "", const bool state = false, QWidget *parent = nullptr) : AbstractControlSP_TITLED(title, desc, icon, parent) { toggle.setFixedSize(150, 100); if (state) { toggle.togglePosition(); @@ -442,11 +433,11 @@ private: }; // convenience class for wrapping layouts -class LayoutWidget : public QWidget { +class LayoutWidgetSP : public QWidget { Q_OBJECT public: - LayoutWidget(QLayout *l, QWidget *parent = nullptr) : QWidget(parent) { + LayoutWidgetSP(QLayout *l, QWidget *parent = nullptr) : QWidget(parent) { setLayout(l); } };