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

Method selectTemplate

app/src/DataModel/Editors/OutputCodeEditor.cpp:339–368  ·  view source on GitHub ↗

* @brief Shows a dialog to pick and load a built-in template. */

Source from the content-addressed store, hash-verified

337 * @brief Shows a dialog to pick and load a built-in template.
338 */
339void DataModel::OutputCodeEditor::selectTemplate()
340{
341 if (m_templateNames.isEmpty())
342 return;
343
344 bool ok;
345 const auto name = QInputDialog::getItem(nullptr,
346 tr("Select Output Widget Template"),
347 tr("Choose a template to load:"),
348 m_templateNames,
349 0,
350 false,
351 &ok);
352
353 if (!ok)
354 return;
355
356 const int idx = m_templateNames.indexOf(name);
357 if (idx < 0 || idx >= m_templateFiles.size())
358 return;
359
360 QFile file(m_templateFiles.at(idx));
361 if (file.open(QFile::ReadOnly)) {
362 m_widget.setPlainText(QString::fromUtf8(file.readAll()));
363 m_widget.document()->clearUndoRedoStacks();
364 m_widget.document()->setModified(false);
365 Q_EMIT modifiedChanged();
366 file.close();
367 }
368}
369
370/**
371 * @brief Opens the transmit test dialog with the current editor code.

Callers

nothing calls this directly

Calls 6

isEmptyMethod · 0.80
setModifiedMethod · 0.80
indexOfMethod · 0.45
sizeMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected