mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-29 23:43:47 +08:00
ui: Detect and sync param changes with ButtonParamControl (#262)
This commit is contained in:
@@ -131,6 +131,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
|
||||
});
|
||||
|
||||
connect(new SPControlsPanel(), &SPControlsPanel::updateStockToggles, this, &TogglesPanel::updateToggles);
|
||||
|
||||
param_watcher = new ParamWatcher(this);
|
||||
|
||||
QObject::connect(param_watcher, &ParamWatcher::paramChanged, [=](const QString ¶m_name, const QString ¶m_value) {
|
||||
updateButtons();
|
||||
});
|
||||
}
|
||||
|
||||
void TogglesPanel::expandToggleDescription(const QString ¶m) {
|
||||
@@ -139,6 +145,7 @@ void TogglesPanel::expandToggleDescription(const QString ¶m) {
|
||||
|
||||
void TogglesPanel::showEvent(QShowEvent *event) {
|
||||
updateToggles();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void TogglesPanel::updateToggles() {
|
||||
@@ -220,6 +227,14 @@ void TogglesPanel::updateToggles() {
|
||||
}
|
||||
}
|
||||
|
||||
void TogglesPanel::updateButtons() {
|
||||
param_watcher->addParam("LongitudinalPersonality");
|
||||
|
||||
if (!isVisible()) return;
|
||||
|
||||
long_personality_setting->setButton("LongitudinalPersonality");
|
||||
}
|
||||
|
||||
DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
|
||||
setSpacing(50);
|
||||
addItem(new LabelControl(tr("Dongle ID"), getDongleId().value_or(tr("N/A"))));
|
||||
|
||||
@@ -77,6 +77,9 @@ private:
|
||||
Params params;
|
||||
std::map<std::string, ParamControl*> toggles;
|
||||
ButtonParamControl *long_personality_setting;
|
||||
|
||||
ParamWatcher *param_watcher;
|
||||
void updateButtons();
|
||||
};
|
||||
|
||||
class SoftwarePanel : public ListWidget {
|
||||
|
||||
@@ -1125,13 +1125,28 @@ DynamicLaneProfile::DynamicLaneProfile(QWidget *parent) : QWidget(parent), outer
|
||||
|
||||
addItem(dynamicLaneProfile);
|
||||
addItem(dlp_settings);
|
||||
|
||||
param_watcher = new ParamWatcher(this);
|
||||
|
||||
QObject::connect(param_watcher, &ParamWatcher::paramChanged, [=](const QString ¶m_name, const QString ¶m_value) {
|
||||
updateButtons();
|
||||
});
|
||||
}
|
||||
|
||||
void DynamicLaneProfile::showEvent(QShowEvent *event) {
|
||||
updateToggles();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void DynamicLaneProfile::updateToggles() {
|
||||
// toggle names to update when DynamicLaneProfile is flipped
|
||||
dlp_settings->setVisible(params.getBool("DynamicLaneProfileToggle"));
|
||||
}
|
||||
|
||||
void DynamicLaneProfile::updateButtons() {
|
||||
param_watcher->addParam("DynamicLaneProfile");
|
||||
|
||||
if (!isVisible()) return;
|
||||
|
||||
dlp_settings->setButton("DynamicLaneProfile");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QStackedWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "selfdrive/ui/qt/widgets/controls.h"
|
||||
|
||||
class SPOptionControl : public AbstractControl {
|
||||
@@ -308,6 +309,9 @@ private:
|
||||
|
||||
ParamControl *dynamicLaneProfile;
|
||||
ButtonParamControl *dlp_settings;
|
||||
|
||||
ParamWatcher *param_watcher;
|
||||
void updateButtons();
|
||||
};
|
||||
|
||||
class SPGeneralPanel : public ListWidget {
|
||||
|
||||
@@ -252,6 +252,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void setButton(QString param) {
|
||||
key = param.toStdString();
|
||||
int value = atoi(params.get(key).c_str());
|
||||
for (int i = 0; i < button_group->buttons().size(); i++) {
|
||||
button_group->buttons()[i]->setChecked(i == value);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::string key;
|
||||
Params params;
|
||||
|
||||
Reference in New Issue
Block a user