* @brief Shows a dialog to pick and load a built-in template. */
| 337 | * @brief Shows a dialog to pick and load a built-in template. |
| 338 | */ |
| 339 | void 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. |