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

Method groupUpdate

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

* @brief Patch any subset of group fields by id. */

Source from the content-addressed store, hash-verified

4697 * @brief Patch any subset of group fields by id.
4698 */
4699API::CommandResponse API::Handlers::ProjectHandler::groupUpdate(const QString& id,
4700 const QJsonObject& params)
4701{
4702 if (!params.contains(QStringLiteral("groupId")))
4703 return CommandResponse::makeError(
4704 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: groupId"));
4705
4706 const int groupId = params.value(QStringLiteral("groupId")).toInt();
4707 auto& project = DataModel::ProjectModel::instance();
4708 const auto& groups = project.groups();
4709 if (groupId < 0 || static_cast<size_t>(groupId) >= groups.size())
4710 return CommandResponse::makeError(
4711 id, ErrorCode::InvalidParam, QStringLiteral("Group id not found: %1").arg(groupId));
4712
4713 DataModel::Group g = groups[groupId];
4714 bool rebuildTree = false;
4715 QSet<QString> consumed{QStringLiteral("groupId")};
4716 const auto identityKeyCount = consumed.size();
4717
4718 const auto take = [&](const QString& key) -> bool {
4719 if (!params.contains(key))
4720 return false;
4721
4722 consumed.insert(key);
4723 return true;
4724 };
4725
4726 if (take(QStringLiteral("title"))) {
4727 g.title = params.value(QStringLiteral("title")).toString();
4728 rebuildTree = true;
4729 }
4730 if (take(QStringLiteral("widget"))) {
4731 g.widget = params.value(QStringLiteral("widget")).toString();
4732 rebuildTree = true;
4733 }
4734 if (take(QStringLiteral("columns")))
4735 g.columns = params.value(QStringLiteral("columns")).toInt();
4736
4737 if (take(Keys::SourceId))
4738 g.sourceId = params.value(Keys::SourceId).toInt();
4739
4740 if (take(QStringLiteral("painterCode")))
4741 g.painterCode = params.value(QStringLiteral("painterCode")).toString();
4742
4743 if (consumed.size() > identityKeyCount)
4744 rebuildTree = true;
4745
4746 project.updateGroup(groupId, g, rebuildTree);
4747
4748 QJsonObject result;
4749 result[QStringLiteral("groupId")] = groupId;
4750 result[QStringLiteral("updated")] = true;
4751 appendUnknownFieldsWarning(result, params, consumed, QStringLiteral("project.group.update"));
4752 return CommandResponse::makeSuccess(id, result);
4753}
4754
4755/**
4756 * @brief Patch optional dataset fields onto @p d; returns non-empty error string on failure.

Callers

nothing calls this directly

Calls 5

updateGroupMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected