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

Method import

app/src/DataModel/Editors/PainterCodeEditor.cpp:297–321  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

295 * @brief Opens a file dialog to import an external JS file.
296 */
297void DataModel::PainterCodeEditor::import()
298{
299 auto* dialog = new QFileDialog(
300 nullptr, tr("Select Javascript file to import"), QDir::homePath(), QStringLiteral("*.js"));
301 dialog->setFileMode(QFileDialog::ExistingFile);
302
303 connect(dialog, &QFileDialog::fileSelected, this, [this, dialog](const QString& path) {
304 dialog->deleteLater();
305 if (path.isEmpty())
306 return;
307
308 QMetaObject::invokeMethod(
309 this,
310 [this, path]() {
311 QFile file(path);
312 if (file.open(QFile::ReadOnly)) {
313 m_widget.setPlainText(QString::fromUtf8(file.readAll()));
314 file.close();
315 }
316 },
317 Qt::QueuedConnection);
318 });
319
320 dialog->open();
321}
322
323/**
324 * @brief Loads the painter code from the currently selected group.

Callers

nothing calls this directly

Calls 3

isEmptyMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected