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

Function loadTemplateBodyById

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

* @brief Loads a template body file by id. Returns empty doc when not found. */

Source from the content-addressed store, hash-verified

5506 * @brief Loads a template body file by id. Returns empty doc when not found.
5507 */
5508static QJsonDocument loadTemplateBodyById(const QString& templateId)
5509{
5510 const auto manifest = loadTemplateManifest().object();
5511 const auto entries = manifest.value(QStringLiteral("templates")).toArray();
5512 for (const auto& v : entries) {
5513 const auto entry = v.toObject();
5514 if (entry.value(QStringLiteral("id")).toString() != templateId)
5515 continue;
5516
5517 const auto file = entry.value(QStringLiteral("file")).toString();
5518 QFile body(QStringLiteral(":/ai/templates/") + file);
5519 if (!body.open(QIODevice::ReadOnly | QIODevice::Text))
5520 return {};
5521
5522 return QJsonDocument::fromJson(body.readAll());
5523 }
5524 return {};
5525}
5526
5527/**
5528 * @brief Register project.template.* commands.

Callers 1

templateApplyMethod · 0.85

Calls 4

loadTemplateManifestFunction · 0.85
fromJsonFunction · 0.85
valueMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected