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

Method outputWidgetAdd

app/src/API/Handlers/ProjectHandler.cpp:2695–2719  ·  view source on GitHub ↗

* @brief Add an output widget to the specified group. */

Source from the content-addressed store, hash-verified

2693 * @brief Add an output widget to the specified group.
2694 */
2695API::CommandResponse API::Handlers::ProjectHandler::outputWidgetAdd(const QString& id,
2696 const QJsonObject& params)
2697{
2698 if (!params.contains(QStringLiteral("groupId")))
2699 return CommandResponse::makeError(
2700 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: groupId"));
2701
2702 const int groupId = params.value(QStringLiteral("groupId")).toInt();
2703 const int type = params.value(QStringLiteral("type")).toInt(0);
2704 auto& project = DataModel::ProjectModel::instance();
2705 const auto& groups = project.groups();
2706 if (groupId < 0 || static_cast<size_t>(groupId) >= groups.size())
2707 return CommandResponse::makeError(
2708 id, ErrorCode::InvalidParam, QStringLiteral("Group id not found: %1").arg(groupId));
2709
2710 project.setSelectedGroup(groups[groupId]);
2711 project.addOutputControl(static_cast<SerialStudio::OutputWidgetType>(
2712 qBound(0, type, static_cast<int>(SerialStudio::OutputKnob))));
2713
2714 QJsonObject result;
2715 result[QStringLiteral("groupId")] = groupId;
2716 result[QStringLiteral("type")] = type;
2717 result[QStringLiteral("added")] = true;
2718 return CommandResponse::makeSuccess(id, result);
2719}
2720
2721/**
2722 * @brief Delete an output widget by id.

Callers

nothing calls this directly

Calls 5

setSelectedGroupMethod · 0.80
addOutputControlMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected