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

Method templateCode

app/src/DataModel/Scripting/FrameParser.cpp:237–260  ·  view source on GitHub ↗

* @brief Returns the template code currently selected for the source. */

Source from the content-addressed store, hash-verified

235 * @brief Returns the template code currently selected for the source.
236 */
237QString DataModel::FrameParser::templateCode(int sourceId) const
238{
239 auto it = m_engines.find(sourceId);
240 const int idx = (it != m_engines.end()) ? it->second->templateIdx : -1;
241 const int lang = languageForSource(sourceId);
242
243 if (lang == SerialStudio::Native) {
244 const auto& templates = nativeTemplates();
245 if (idx < 0 || idx >= templates.size())
246 return {};
247
248 const auto* tmpl = templates.at(idx);
249 return CFrameParser::buildDescriptor(tmpl->id(), nativeTemplateDefaults(*tmpl));
250 }
251
252 if (idx < 0 || idx >= m_templateFiles.count())
253 return {};
254
255 const bool isLua = (lang == SerialStudio::Lua);
256 const auto directory =
257 isLua ? QStringLiteral(":/scripts/parser/lua") : QStringLiteral(":/scripts/parser/js");
258 const auto suffix = isLua ? QStringLiteral(".lua") : QStringLiteral(".js");
259 return readTextResource(templateResourcePath(directory, m_templateFiles.at(idx), suffix));
260}
261
262/**
263 * @brief Returns the template index matching the code in either language.

Callers 1

selectTemplateMethod · 0.80

Calls 4

findMethod · 0.80
sizeMethod · 0.45
idMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected