* @brief Rebuilds the Quick Plot frame structure when the channel count changes. */
| 1672 | * @brief Rebuilds the Quick Plot frame structure when the channel count changes. |
| 1673 | */ |
| 1674 | void DataModel::FrameBuilder::buildQuickPlotFrame(const QStringList& channels) |
| 1675 | { |
| 1676 | Q_ASSERT(!channels.isEmpty()); |
| 1677 | Q_ASSERT(AppState::instance().operationMode() == SerialStudio::QuickPlot); |
| 1678 | |
| 1679 | invalidateFramePool(); |
| 1680 | |
| 1681 | #ifdef BUILD_COMMERCIAL |
| 1682 | const auto busType = IO::ConnectionManager::instance().busType(); |
| 1683 | if (busType == SerialStudio::BusType::Audio) { |
| 1684 | buildQuickPlotAudioFrame(channels); |
| 1685 | return; |
| 1686 | } |
| 1687 | #endif |
| 1688 | |
| 1689 | int idx = 1; |
| 1690 | std::vector<DataModel::Dataset> datasets; |
| 1691 | datasets.reserve(channels.count()); |
| 1692 | for (const auto& channel : std::as_const(channels)) { |
| 1693 | DataModel::Dataset dataset; |
| 1694 | dataset.groupId = 0; |
| 1695 | dataset.datasetId = idx - 1; |
| 1696 | dataset.uniqueId = dataset_unique_id(0, 0, idx - 1); |
| 1697 | dataset.index = idx; |
| 1698 | dataset.plt = false; |
| 1699 | dataset.value = channel; |
| 1700 | |
| 1701 | if (m_quickPlotHasHeader && idx > 0 |
| 1702 | && idx - 1 < static_cast<int>(m_quickPlotChannelNames.size())) |
| 1703 | dataset.title = m_quickPlotChannelNames[idx - 1]; |
| 1704 | else |
| 1705 | dataset.title = tr("Channel %1").arg(idx); |
| 1706 | |
| 1707 | dataset.numericValue = SerialStudio::toDouble(dataset.value, &dataset.isNumeric); |
| 1708 | datasets.push_back(dataset); |
| 1709 | |
| 1710 | ++idx; |
| 1711 | } |
| 1712 | |
| 1713 | clear_frame(m_quickPlotFrame); |
| 1714 | m_quickPlotFrame.title = tr("Quick Plot"); |
| 1715 | m_quickPlotFrame.sources.push_back(makeQuickPlotSource()); |
| 1716 | |
| 1717 | DataModel::Group datagrid; |
| 1718 | datagrid.groupId = 0; |
| 1719 | datagrid.uniqueId = runtime_group_unique_id(0); |
| 1720 | datagrid.datasets = datasets; |
| 1721 | datagrid.title = tr("Quick Plot Data"); |
| 1722 | datagrid.widget = QStringLiteral("datagrid"); |
| 1723 | for (size_t i = 0; i < datagrid.datasets.size(); ++i) |
| 1724 | datagrid.datasets[i].plt = true; |
| 1725 | |
| 1726 | m_quickPlotFrame.groups.push_back(datagrid); |
| 1727 | |
| 1728 | if (datasets.size() > 1) { |
| 1729 | DataModel::Group multiplot; |
| 1730 | multiplot.groupId = 1; |
| 1731 | multiplot.uniqueId = runtime_group_unique_id(1); |
nothing calls this directly
no test coverage detected