ui: consolidate panel updates at a single location (#904)

* init

* minimize changes for all brands

* more

* even less diff

* more less

* wow srsly
This commit is contained in:
Jason Wen
2025-05-10 12:46:02 -04:00
committed by GitHub
parent 08efc252ec
commit 8d06444bdd
28 changed files with 51 additions and 248 deletions
@@ -6,3 +6,16 @@
*/
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/brand_settings_interface.h"
BrandSettingsInterface::BrandSettingsInterface(QWidget *parent) : QWidget(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
list = new ListWidget(this, false);
main_layout->addWidget(list);
}
void BrandSettingsInterface::updatePanel(bool _offroad) {
offroad = _offroad;
updateSettings();
}
@@ -7,15 +7,22 @@
#pragma once
#include <QWidget>
#include "selfdrive/ui/sunnypilot/ui.h"
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h"
class BrandSettingsInterface : public QWidget {
Q_OBJECT
public:
explicit BrandSettingsInterface(QWidget *parent = nullptr) : QWidget(parent) {}
explicit BrandSettingsInterface(QWidget *parent = nullptr);
virtual ~BrandSettingsInterface() = default;
virtual void updatePanel(bool offroad) = 0;
void updatePanel(bool _offroad);
virtual void updateSettings() = 0;
protected:
ListWidget *list = nullptr;
Params params;
bool offroad = false;
};
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/chrysler_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
ChryslerSettings::ChryslerSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void ChryslerSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void ChryslerSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class ChryslerSettings : public BrandSettingsInterface {
public:
explicit ChryslerSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/ford_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
FordSettings::FordSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void FordSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void FordSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class FordSettings : public BrandSettingsInterface {
public:
explicit FordSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/gm_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
GMSettings::GMSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void GMSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void GMSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class GMSettings : public BrandSettingsInterface {
public:
explicit GMSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/honda_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
HondaSettings::HondaSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void HondaSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void HondaSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class HondaSettings : public BrandSettingsInterface {
public:
explicit HondaSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/hyundai_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
HyundaiSettings::HyundaiSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void HyundaiSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void HyundaiSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,9 +19,5 @@ class HyundaiSettings : public BrandSettingsInterface {
public:
explicit HyundaiSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
private:
bool offroad = false;
void updateSettings() override;
};
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/mazda_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
MazdaSettings::MazdaSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void MazdaSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void MazdaSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class MazdaSettings : public BrandSettingsInterface {
public:
explicit MazdaSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/nissan_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
NissanSettings::NissanSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void NissanSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void NissanSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class NissanSettings : public BrandSettingsInterface {
public:
explicit NissanSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/rivian_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
RivianSettings::RivianSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void RivianSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void RivianSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class RivianSettings : public BrandSettingsInterface {
public:
explicit RivianSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/subaru_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
SubaruSettings::SubaruSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void SubaruSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void SubaruSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class SubaruSettings : public BrandSettingsInterface {
public:
explicit SubaruSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/tesla_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
TeslaSettings::TeslaSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void TeslaSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void TeslaSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class TeslaSettings : public BrandSettingsInterface {
public:
explicit TeslaSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/toyota_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
ToyotaSettings::ToyotaSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void ToyotaSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void ToyotaSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class ToyotaSettings : public BrandSettingsInterface {
public:
explicit ToyotaSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -7,25 +7,8 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/volkswagen_settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
VolkswagenSettings::VolkswagenSettings(QWidget *parent) : BrandSettingsInterface(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
ListWidget *list = new ListWidget(this, false);
main_layout->addWidget(new ScrollViewSP(list, this));
}
void VolkswagenSettings::updatePanel(bool _offroad) {
updateSettings();
offroad = _offroad;
}
void VolkswagenSettings::updateSettings() {
if (!isVisible()) {
return;
}
}
@@ -19,8 +19,7 @@ class VolkswagenSettings : public BrandSettingsInterface {
public:
explicit VolkswagenSettings(QWidget *parent = nullptr);
void updatePanel(bool _offroad);
void updateSettings();
void updateSettings() override;
private:
bool offroad = false;
@@ -12,26 +12,27 @@
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
VehiclePanel::VehiclePanel(QWidget *parent) : QFrame(parent) {
main_layout = new QStackedLayout(this);
ListWidget *list = new ListWidget(this);
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(50, 20, 50, 20);
vehicleScreen = new QWidget(this);
QVBoxLayout *vlayout = new QVBoxLayout(vehicleScreen);
vlayout->setContentsMargins(50, 20, 50, 20);
ListWidget *list = new ListWidget(this);
platformSelector = new PlatformSelector();
QObject::connect(platformSelector, &PlatformSelector::refreshPanel, this, &VehiclePanel::updateBrandSettings);
list->addItem(platformSelector);
brandSettingsContainer = new QWidget(this);
brandSettingsContainerLayout = new QVBoxLayout(brandSettingsContainer);
brandSettingsContainerLayout->setContentsMargins(0, 0, 0, 0);
brandSettingsContainerLayout->setSpacing(0);
list->addItem(brandSettingsContainer);
ScrollViewSP *scroller = new ScrollViewSP(list, this);
vlayout->addWidget(scroller);
main_layout->addWidget(scroller);
currentBrandSettings = nullptr;
QObject::connect(uiState(), &UIState::offroadTransition, this, &VehiclePanel::updatePanel);
main_layout->addWidget(vehicleScreen);
main_layout->setCurrentWidget(vehicleScreen);
}
void VehiclePanel::showEvent(QShowEvent *event) {
@@ -39,9 +40,9 @@ void VehiclePanel::showEvent(QShowEvent *event) {
}
void VehiclePanel::updatePanel(bool _offroad) {
offroad = _offroad;
platformSelector->refresh(_offroad);
updateBrandSettings();
offroad = _offroad;
}
void VehiclePanel::updateBrandSettings() {
@@ -50,7 +51,7 @@ void VehiclePanel::updateBrandSettings() {
}
if (currentBrandSettings) {
vehicleScreen->layout()->removeWidget(currentBrandSettings);
brandSettingsContainerLayout->removeWidget(currentBrandSettings);
delete currentBrandSettings;
currentBrandSettings = nullptr;
}
@@ -58,7 +59,8 @@ void VehiclePanel::updateBrandSettings() {
if (BrandSettingsFactory::isBrandSupported(platformSelector->brand)) {
currentBrandSettings = BrandSettingsFactory::createBrandSettings(platformSelector->brand, this);
if (currentBrandSettings) {
vehicleScreen->layout()->addWidget(currentBrandSettings);
currentBrandSettings->setContentsMargins(0, 0, 0, 0);
brandSettingsContainerLayout->addWidget(currentBrandSettings);
currentBrandSettings->updatePanel(offroad);
}
}
@@ -23,10 +23,10 @@ public slots:
void updatePanel(bool _offroad);
private:
QStackedLayout* main_layout = nullptr;
QWidget* vehicleScreen = nullptr;
PlatformSelector* platformSelector = nullptr;
BrandSettingsInterface* currentBrandSettings = nullptr;
QWidget* brandSettingsContainer = nullptr;
QVBoxLayout* brandSettingsContainerLayout = nullptr;
bool offroad = false;
private slots: