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.
This commit is contained in:
DevTekVE
2024-07-14 15:43:21 +02:00
parent ddee284733
commit 80ecce9d81
5 changed files with 14 additions and 11 deletions
-1
View File
@@ -112,7 +112,6 @@ protected:
bool is_onroad = false;
QLabel *onroadLbl;
LabelControl *currentModelLbl;
LabelControl *versionLbl;
ButtonControl *installBtn;
ButtonControl *downloadBtn;
+4 -6
View File
@@ -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();
}
}
+3 -1
View File
@@ -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:
@@ -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) {
+6 -2
View File
@@ -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); \
} \
} \