ui: ButtonParamControl: Handle out of bound param

This commit is contained in:
Jason Wen
2024-05-23 17:34:29 +00:00
parent 16706bda9c
commit b77d0809bc
2 changed files with 11 additions and 2 deletions
@@ -60,7 +60,7 @@ VisualsPanel::VisualsPanel(QWidget *parent) : ListWidget(parent) {
{
"MapboxFullScreen",
tr("Navigation: Display in Full Screen"),
QString(tr("Enable this will display the built-in navigation in full screen.<br>To switch back to driving view, <font color='yellow'>tap on the border edge</font>.")),
tr("Enable this will display the built-in navigation in full screen.<br>To switch back to driving view, <font color='yellow'>tap on the border edge</font>."),
"../assets/offroad/icon_blank.png",
},
{
+10 -1
View File
@@ -243,7 +243,7 @@ class ButtonParamControl : public SPAbstractControl {
Q_OBJECT
public:
ButtonParamControl(const QString &param, const QString &title, const QString &desc, const QString &icon,
const std::vector<QString> &button_texts, const int minimum_button_width = 300) : SPAbstractControl(title, desc, icon) {
const std::vector<QString> &button_texts, const int minimum_button_width = 300) : SPAbstractControl(title, desc, icon), button_texts(button_texts) {
const QString style = R"(
QPushButton {
border-radius: 20px;
@@ -306,6 +306,14 @@ public:
void refresh() {
int value = atoi(params.get(key).c_str());
if (value >= button_texts.size()) {
value = button_texts.size() - 1;
}
if (value < button_texts.size()) {
value = 0;
}
button_group->button(value)->setChecked(true);
}
@@ -357,6 +365,7 @@ private:
std::string key;
Params params;
QButtonGroup *button_group;
std::vector<QString> button_texts;
bool button_group_enabled = true;
};