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

Method duplicateSource

app/src/DataModel/ProjectModel.cpp:1600–1626  ·  view source on GitHub ↗

* @brief Duplicates the source with the given @p sourceId. */

Source from the content-addressed store, hash-verified

1598 * @brief Duplicates the source with the given @p sourceId.
1599 */
1600void DataModel::ProjectModel::duplicateSource(int sourceId)
1601{
1602#ifndef BUILD_COMMERCIAL
1603 (void)sourceId;
1604 return;
1605#else
1606 if (sourceId < 0 || sourceId >= static_cast<int>(m_sources.size()))
1607 return;
1608
1609 DataModel::Source copy = m_sources[sourceId];
1610 copy.sourceId = static_cast<int>(m_sources.size());
1611 copy.connectionSettings = QJsonObject();
1612
1613 QStringList existingTitles;
1614 existingTitles.reserve(static_cast<int>(m_sources.size()));
1615 for (const auto& s : m_sources)
1616 existingTitles.append(s.title);
1617
1618 copy.title = nextDuplicateTitle(m_sources[sourceId].title, existingTitles);
1619
1620 m_sources.push_back(copy);
1621 setModified(true);
1622 Q_EMIT sourcesChanged();
1623 Q_EMIT sourceStructureChanged();
1624 Q_EMIT sourceAdded(copy.sourceId);
1625#endif
1626}
1627
1628/**
1629 * @brief Updates the source with the given @p sourceId.

Callers

nothing calls this directly

Calls 4

QJsonObjectClass · 0.85
nextDuplicateTitleFunction · 0.85
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected