MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / duplicateCurrentGroup

Method duplicateCurrentGroup

app/src/DataModel/ProjectModel.cpp:3524–3559  ·  view source on GitHub ↗

* @brief Appends a copy of the currently selected group to the project. */

Source from the content-addressed store, hash-verified

3522 * @brief Appends a copy of the currently selected group to the project.
3523 */
3524void DataModel::ProjectModel::duplicateCurrentGroup()
3525{
3526 DataModel::Group group = m_selectedGroup;
3527 group.groupId = m_groups.size();
3528 group.uniqueId = allocateUniqueId();
3529 group.datasets.clear();
3530 group.outputWidgets.clear();
3531
3532 QStringList existingTitles;
3533 existingTitles.reserve(static_cast<int>(m_groups.size()));
3534 for (const auto& g : m_groups)
3535 existingTitles.append(g.title);
3536
3537 group.title = nextDuplicateTitle(m_selectedGroup.title, existingTitles);
3538
3539 for (size_t i = 0; i < m_selectedGroup.datasets.size(); ++i) {
3540 auto dataset = m_selectedGroup.datasets[i];
3541 dataset.groupId = group.groupId;
3542 dataset.index = nextDatasetIndex() + static_cast<int>(i);
3543 dataset.uniqueId = allocateUniqueId();
3544 group.datasets.push_back(dataset);
3545 }
3546
3547 for (const auto& ow : m_selectedGroup.outputWidgets) {
3548 auto copy = ow;
3549 copy.groupId = group.groupId;
3550 group.outputWidgets.push_back(copy);
3551 }
3552
3553 m_groups.push_back(group);
3554 m_selectedGroup = m_groups.back();
3555
3556 Q_EMIT groupsChanged();
3557 Q_EMIT groupAdded(static_cast<int>(m_groups.size()) - 1);
3558 setModified(true);
3559}
3560
3561/**
3562 * @brief Appends a copy of the currently selected action to the project.

Callers

nothing calls this directly

Calls 4

nextDuplicateTitleFunction · 0.85
sizeMethod · 0.45
clearMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected