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

Method import

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

* @brief Opens a file dialog to import an external JS file. */

Source from the content-addressed store, hash-verified

283 * @brief Opens a file dialog to import an external JS file.
284 */
285void DataModel::OutputCodeEditor::import()
286{
287 auto* dialog = new QFileDialog(
288 nullptr, tr("Select Javascript file to import"), QDir::homePath(), QStringLiteral("*.js"));
289 dialog->setFileMode(QFileDialog::ExistingFile);
290
291 connect(dialog, &QFileDialog::fileSelected, this, [this, dialog](const QString& path) {
292 dialog->deleteLater();
293 if (path.isEmpty())
294 return;
295
296 QMetaObject::invokeMethod(
297 this,
298 [this, path]() {
299 QFile file(path);
300 if (file.open(QFile::ReadOnly)) {
301 m_widget.setPlainText(QString::fromUtf8(file.readAll()));
302 file.close();
303 }
304 },
305 Qt::QueuedConnection);
306 });
307
308 dialog->open();
309}
310
311/**
312 * @brief Loads the transmit function from the currently selected output widget.

Callers

nothing calls this directly

Calls 3

isEmptyMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected