ui: function for setting toggle confirmation settings (#26516)

function for setting confirmation settings
pull/26514/head^2
Shane Smiskol 2 years ago committed by GitHub
parent f2d97da9b4
commit b3f75b0c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      selfdrive/ui/qt/offroad/settings.cc
  2. 10
      selfdrive/ui/qt/widgets/controls.h

@ -90,7 +90,7 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
};
for (auto &[param, title, desc, icon] : toggle_defs) {
auto toggle = new ParamControl(param, title, desc, icon, false, this);
auto toggle = new ParamControl(param, title, desc, icon, this);
bool locked = params.getBool((param + "Lock").toStdString());
toggle->setEnabled(!locked);
@ -100,9 +100,8 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
}
// Toggles with confirmation dialogs
toggles["ExperimentalMode"]->confirm = true;
toggles["ExperimentalMode"]->store_confirm = true;
toggles["ExperimentalLongitudinalEnabled"]->confirm = true;
toggles["ExperimentalMode"]->setConfirmation(true, true);
toggles["ExperimentalLongitudinalEnabled"]->setConfirmation(true, false);
connect(toggles["ExperimentalLongitudinalEnabled"], &ToggleControl::toggleFlipped, [=]() {
updateToggles();

@ -139,7 +139,7 @@ class ParamControl : public ToggleControl {
Q_OBJECT
public:
ParamControl(const QString &param, const QString &title, const QString &desc, const QString &icon, const bool _confirm, QWidget *parent = nullptr) : confirm(_confirm), ToggleControl(title, desc, icon, false, parent) {
ParamControl(const QString &param, const QString &title, const QString &desc, const QString &icon, QWidget *parent = nullptr) : ToggleControl(title, desc, icon, false, parent) {
key = param.toStdString();
QObject::connect(this, &ParamControl::toggleFlipped, [=](bool state) {
QString content("<body><h2 style=\"text-align: center;\">" + title + "</h2><br>"
@ -156,8 +156,10 @@ public:
});
}
bool confirm = false;
bool store_confirm = false;
void setConfirmation(bool _confirm, bool _store_confirm) {
confirm = _confirm;
store_confirm = _store_confirm;
};
void refresh() {
if (params.getBool(key) != toggle.on) {
@ -172,6 +174,8 @@ public:
private:
std::string key;
Params params;
bool confirm = false;
bool store_confirm = false;
};
class ListWidget : public QWidget {

Loading…
Cancel
Save