| 194 | } |
| 195 | |
| 196 | void ParameterForm::setValues(const nlohmann::json& values) { |
| 197 | silent_ = true; |
| 198 | for (Row& r : rows_) { |
| 199 | if (!values.contains(r.spec.name)) { |
| 200 | continue; |
| 201 | } |
| 202 | const nlohmann::json& v = values.at(r.spec.name); |
| 203 | switch (r.spec.type) { |
| 204 | case ParamType::kInteger: |
| 205 | if (v.is_number()) { |
| 206 | qobject_cast<QSpinBox*>(r.editor)->setValue(v.get<int>()); |
| 207 | } |
| 208 | break; |
| 209 | case ParamType::kNumber: |
| 210 | if (v.is_number()) { |
| 211 | qobject_cast<QLineEdit*>(r.editor)->setText(QString::number(v.get<double>(), 'g', 17)); |
| 212 | } |
| 213 | break; |
| 214 | case ParamType::kBoolean: |
| 215 | if (v.is_boolean()) { |
| 216 | qobject_cast<ToggleSwitch*>(r.editor)->setChecked(v.get<bool>(), false); |
| 217 | } |
| 218 | break; |
| 219 | case ParamType::kEnum: { |
| 220 | auto* cb = qobject_cast<ComboBox*>(r.editor); |
| 221 | for (std::size_t i = 0; i < r.spec.values.size(); ++i) { |
| 222 | if (r.spec.values[i].value == v) { |
| 223 | cb->setCurrentIndex(static_cast<int>(i)); |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | break; |
| 228 | } |
| 229 | case ParamType::kString: |
| 230 | if (v.is_string()) { |
| 231 | qobject_cast<QLineEdit*>(r.editor)->setText(QString::fromStdString(v.get<std::string>())); |
| 232 | } |
| 233 | break; |
| 234 | case ParamType::kText: |
| 235 | if (v.is_string()) { |
| 236 | qobject_cast<QPlainTextEdit*>(r.editor)->setPlainText(QString::fromStdString(v.get<std::string>())); |
| 237 | } |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | silent_ = false; |
| 242 | updateConditionalVisibility(); |
| 243 | } |
| 244 | |
| 245 | void ParameterForm::updateConditionalVisibility() { |
| 246 | const nlohmann::json current = values(); |