From 80ecce9d81cf068bd1eeb7f0133a4ab97ca44ef1 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sun, 14 Jul 2024 15:43:21 +0200 Subject: [PATCH] Remove "Driving Model" label and adjust item management Eliminated the "Driving Model" label from SoftwarePanel and refactored item management to improve code clarity and functionality. Updated macro naming and added new list widget functions for better handling of UI elements. --- selfdrive/ui/qt/offroad/settings.h | 1 - selfdrive/ui/qt/offroad/software_settings.cc | 10 ++++------ selfdrive/ui/qt/widgets/controls.h | 4 +++- .../ui/sunnypilot/qt/offroad/software_settings_sp.cc | 2 +- selfdrive/ui/sunnypilot/qt/sp_priv_util.h | 8 ++++++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index 4f3f282005..7b8fd52976 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -112,7 +112,6 @@ protected: bool is_onroad = false; QLabel *onroadLbl; - LabelControl *currentModelLbl; LabelControl *versionLbl; ButtonControl *installBtn; ButtonControl *downloadBtn; diff --git a/selfdrive/ui/qt/offroad/software_settings.cc b/selfdrive/ui/qt/offroad/software_settings.cc index 685ca3555d..3045842d91 100644 --- a/selfdrive/ui/qt/offroad/software_settings.cc +++ b/selfdrive/ui/qt/offroad/software_settings.cc @@ -9,7 +9,6 @@ #include "common/params.h" #include "common/util.h" -#include "common/model.h" #include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/controls.h" @@ -22,9 +21,6 @@ void SoftwarePanel::checkForUpdates() { } SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) { - currentModelLbl = new LabelControl(tr("Driving Model"), CURRENT_MODEL); - addItem(currentModelLbl); - onroadLbl = new QLabel(tr("Updates are only downloaded while the car is off.")); onroadLbl->setStyleSheet("font-size: 50px; font-weight: 400; text-align: left; padding-top: 30px; padding-bottom: 30px;"); addItem(onroadLbl); @@ -74,7 +70,9 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) { checkForUpdates(); } }); - addItem(targetBranchBtn); + if (!params.getBool("IsTestedBranch")) { + addItem(targetBranchBtn); + } // uninstall button auto uninstallBtn = new ButtonControl(tr("Uninstall %1").arg(getBrand()), tr("UNINSTALL")); @@ -155,4 +153,4 @@ void SoftwarePanel::updateLabels() { installBtn->setDescription(QString::fromStdString(params.get("UpdaterNewReleaseNotes"))); update(); -} +} \ No newline at end of file diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 3c5766d137..bec83f48d5 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -295,10 +295,12 @@ class ListWidget : public QWidget { inline void addItem(QLayout *layout) { inner_layout.addLayout(layout); } inline void setSpacing(int spacing) { inner_layout.setSpacing(spacing); } +// TODO: move this out of the macros before going public. Looks phishy, and it's harder to debug it... #ifdef SUNNYPILOT LIST_WIDGET_FUNCTION_1 LIST_WIDGET_FUNCTION_2 - LIST_WIDGET_FUCNTION_3 + LIST_WIDGET_FUNCTION_3 + LIST_WIDGET_FUNCTION_4 #endif private: diff --git a/selfdrive/ui/sunnypilot/qt/offroad/software_settings_sp.cc b/selfdrive/ui/sunnypilot/qt/offroad/software_settings_sp.cc index ce6a6712e6..5b00c55e20 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/software_settings_sp.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/software_settings_sp.cc @@ -63,7 +63,7 @@ SoftwarePanelSP::SoftwarePanelSP(QWidget *parent) : SoftwarePanel(parent) { // Connect click event from currentModelLblBtn to local slot connect(currentModelLblBtn, &ButtonControl::clicked, this, &SoftwarePanelSP::handleCurrentModelLblBtnClicked); - ReplaceOrAddWidget(currentModelLbl, currentModelLblBtn); + addItem(currentModelLblBtn, 0); } void SoftwarePanelSP::handleDownloadFailed(const QString &modelType) { diff --git a/selfdrive/ui/sunnypilot/qt/sp_priv_util.h b/selfdrive/ui/sunnypilot/qt/sp_priv_util.h index 3bc4bb7f65..dedec60666 100644 --- a/selfdrive/ui/sunnypilot/qt/sp_priv_util.h +++ b/selfdrive/ui/sunnypilot/qt/sp_priv_util.h @@ -35,12 +35,16 @@ } \ } \ -#define LIST_WIDGET_FUCNTION_3 \ +#define LIST_WIDGET_FUNCTION_3 \ + inline void addItem(QWidget *w, int index) { inner_layout.insertWidget(index, w); } \ + +#define LIST_WIDGET_FUNCTION_4 \ inline void ReplaceOrAddWidget(QWidget *old_widget, QWidget *new_widget) { \ if (const int index = inner_layout.indexOf(old_widget); index != -1) { \ RemoveWidgetAt(index); \ AddWidgetAt(index, new_widget); \ } else { \ - addItem(new_widget); \ + addItem(new_widget, 0); \ } \ } \ +