Skip to content

Commit

Permalink
Merge pull request #2201 from psavery/save-description-json
Browse files Browse the repository at this point in the history
Save the description.json alongside the script
  • Loading branch information
psavery committed Oct 11, 2021
2 parents 5994eab + dd65681 commit 71ad44c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tomviz/FxiWorkflowWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,13 @@ class FxiWorkflowWidget::Internal : public QObject
QJsonValueRef parameterNode = parameters[i];
QJsonObject parameterObject = parameterNode.toObject();
QJsonValueRef nameValue = parameterObject["name"];
auto tagValue = parameterObject["tag"];
if (knownParameters.contains(nameValue.toString())) {
// This parameter is already known. Remove it.
parameters.removeAt(i);
} else if (tagValue.toString("") != "") {
// Not the right tag. Remove it.
parameters.removeAt(i);
} else {
i += 1;
}
Expand Down
49 changes: 47 additions & 2 deletions tomviz/operators/OperatorPython.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QMessageBox>
#include <QPointer>
#include <QtDebug>

Expand Down Expand Up @@ -127,15 +128,59 @@ class EditPythonOperatorWidget : public tomviz::EditOperatorWidget
}

if (!file.open(QIODevice::WriteOnly)) {
qDebug() << "Failed to open file: " << name;
auto msg = QString("Failed to open file: %1").arg(name);
QMessageBox::critical(this, "Failed to save script", msg);
qDebug() << msg;
return;
}

if (file.write(m_ui.script->toPlainText().toLatin1()) == -1) {
qDebug() << "Failed to write to file: " << name;
auto msg = QString("Failed to write to file: %1").arg(name);
QMessageBox::critical(this, "Failed to save script", msg);
qDebug() << msg;
file.close();
return;
}

file.close();

// If there is a JSON description, and the file does not exist,
// write that out too.
if (m_op->JSONDescription().isEmpty()) {
return;
}

// Use the same name with a ".json" extension.
QFileInfo info(name);
auto descriptionFilename = info.path() + "/" + info.baseName() + ".json";
QFile descriptionFile(descriptionFilename, this);
if (descriptionFile.exists()) {
// Check if the user wants to overwrite it.
auto title = QString("Overwrite description file?");
auto msg =
QString("%1 exists.\n\nOverwrite it?").arg(descriptionFilename);
auto response = QMessageBox::question(this, title, msg);
if (response == QMessageBox::No) {
// Do not overwrite
return;
}
}

if (!descriptionFile.open(QIODevice::WriteOnly)) {
auto msg = QString("Failed to open %1").arg(descriptionFilename);
QMessageBox::critical(this, "Failed to save description", msg);
qDebug() << msg;
return;
}

if (descriptionFile.write(m_op->JSONDescription().toLatin1()) == -1) {
auto msg =
QString("Failed to write to file: %1").arg(descriptionFilename);
QMessageBox::critical(this, "Failed to save description", msg);
qDebug() << msg;
};

descriptionFile.close();
}

private:
Expand Down

0 comments on commit 71ad44c

Please sign in to comment.