Skip to content

Commit a4ef927

Browse files
fix: recursive option saving
1 parent 96a67c2 commit a4ef927

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

src/ui/SettingsTab.cpp

+36-27
Original file line numberDiff line numberDiff line change
@@ -109,40 +109,49 @@ namespace fw16led::ui
109109
settings->setValue(QString("panel_%1_preset").arg(panelId), presetKey);
110110
settings->setValue(QString("panel_%1_brightness").arg(panelId), brightnessSlider->value());
111111

112-
// Save dynamic settings
113-
for (int i = 0; i < dynamicSettingsLayout->count(); i++)
112+
// Recursive function to save dynamic settings
113+
std::function<void(QLayout*)> saveSettings = [&](QLayout* layout)
114114
{
115-
QLayoutItem* item = dynamicSettingsLayout->itemAt(i);
116-
if (item->widget() == nullptr)
117-
continue;
118-
119-
QWidget* widget = item->widget();
120-
if (widget->property("controlsSetting").isValid())
115+
for (int i = 0; i < layout->count(); i++)
121116
{
122-
QString controlsSetting = widget->property("controlsSetting").toString();
123-
if (QCheckBox* checkbox = qobject_cast<QCheckBox*>(widget))
124-
{
125-
settings->setValue(controlsSetting, checkbox->isChecked());
126-
}
127-
else if (QLineEdit* textEdit = qobject_cast<QLineEdit*>(widget))
117+
QLayoutItem* item = layout->itemAt(i);
118+
if (item->widget())
128119
{
129-
settings->setValue(controlsSetting, textEdit->text());
130-
}
131-
else if (QComboBox* dropdown = qobject_cast<QComboBox*>(widget))
132-
{
133-
auto selectedKey = dropdown->currentData().value<int>();
134-
settings->setValue(controlsSetting, selectedKey);
135-
}
136-
else if (QSpinBox* spinBox = qobject_cast<QSpinBox*>(widget))
137-
{
138-
settings->setValue(controlsSetting, spinBox->value());
120+
QWidget* widget = item->widget();
121+
if (widget->property("controlsSetting").isValid())
122+
{
123+
QString controlsSetting = widget->property("controlsSetting").toString();
124+
if (QCheckBox* checkbox = qobject_cast<QCheckBox*>(widget))
125+
{
126+
settings->setValue(controlsSetting, checkbox->isChecked());
127+
}
128+
else if (QLineEdit* textEdit = qobject_cast<QLineEdit*>(widget))
129+
{
130+
settings->setValue(controlsSetting, textEdit->text());
131+
}
132+
else if (QComboBox* dropdown = qobject_cast<QComboBox*>(widget))
133+
{
134+
settings->setValue(controlsSetting, dropdown->currentData().value<int>());
135+
}
136+
else if (QSpinBox* spinBox = qobject_cast<QSpinBox*>(widget))
137+
{
138+
settings->setValue(controlsSetting, spinBox->value());
139+
}
140+
else if (QDoubleSpinBox* doubleSpinBox = qobject_cast<QDoubleSpinBox*>(widget))
141+
{
142+
settings->setValue(controlsSetting, doubleSpinBox->value());
143+
}
144+
}
139145
}
140-
else if (QDoubleSpinBox* doubleSpinBox = qobject_cast<QDoubleSpinBox*>(widget))
146+
else if (item->layout())
141147
{
142-
settings->setValue(controlsSetting, doubleSpinBox->value());
148+
saveSettings(item->layout());
143149
}
144150
}
145-
}
151+
};
152+
153+
// Save dynamic settings
154+
saveSettings(dynamicSettingsLayout);
146155

147156
usb_manager->applyConfig(panelId);
148157
}

0 commit comments

Comments
 (0)