* @brief Returns the template code currently selected for the source. */
| 235 | * @brief Returns the template code currently selected for the source. |
| 236 | */ |
| 237 | QString 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. |
no test coverage detected