* @brief Appends template-defined datasets to a painter group when the group has fewer than the * spec demands. Existing datasets are preserved. */
| 4448 | * spec demands. Existing datasets are preserved. |
| 4449 | */ |
| 4450 | void DataModel::ProjectModel::ensurePainterDatasets(int groupId, const QVariantList& specs) |
| 4451 | { |
| 4452 | if (groupId < 0 || static_cast<size_t>(groupId) >= m_groups.size()) |
| 4453 | return; |
| 4454 | |
| 4455 | if (specs.isEmpty()) |
| 4456 | return; |
| 4457 | |
| 4458 | auto& grp = m_groups[groupId]; |
| 4459 | const int existing = static_cast<int>(grp.datasets.size()); |
| 4460 | bool changed = false; |
| 4461 | |
| 4462 | for (int i = existing; i < specs.size(); ++i) { |
| 4463 | const auto map = specs.at(i).toMap(); |
| 4464 | DataModel::Dataset ds; |
| 4465 | ds.groupId = groupId; |
| 4466 | ds.datasetId = static_cast<int>(grp.datasets.size()); |
| 4467 | ds.index = nextDatasetIndex(); |
| 4468 | ds.uniqueId = allocateUniqueId(); |
| 4469 | ds.title = map.value(QStringLiteral("title"), tr("Channel %1").arg(i + 1)).toString(); |
| 4470 | ds.units = map.value(QStringLiteral("units")).toString(); |
| 4471 | ds.wgtMin = SerialStudio::toDouble(map.value(QStringLiteral("min"), 0.0)); |
| 4472 | ds.wgtMax = SerialStudio::toDouble(map.value(QStringLiteral("max"), 100.0)); |
| 4473 | grp.datasets.push_back(std::move(ds)); |
| 4474 | changed = true; |
| 4475 | } |
| 4476 | |
| 4477 | if (changed) { |
| 4478 | m_selectedGroup = grp; |
| 4479 | Q_EMIT groupsChanged(); |
| 4480 | setModified(true); |
| 4481 | } |
| 4482 | } |
| 4483 | |
| 4484 | /** |
| 4485 | * @brief Toggles a dataset option flag on the currently selected dataset. |
no test coverage detected