diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp index 7f381b1fa..9ed768642 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp @@ -170,14 +170,20 @@ void AirframeInitialTuningPage::loadValidFiles() if (file.open(QFile::ReadOnly)) { QByteArray jsonData = file.readAll(); - QJsonDocument templateDoc = QJsonDocument::fromJson(jsonData); - QJsonObject json = templateDoc.object(); - if (json["type"].toInt() == getWizard()->getVehicleType() && - json["subtype"].toInt() == getWizard()->getVehicleSubType()) { - QString uuid = json["uuid"].toString(); - if (!m_templates.contains(uuid)) { - m_templates[json["uuid"].toString()] = new QJsonObject(json); + QJsonParseError error; + QJsonDocument templateDoc = QJsonDocument::fromJson(jsonData, &error); + if (error.error == QJsonParseError::NoError) { + QJsonObject json = templateDoc.object(); + if (json["type"].toInt() == getWizard()->getVehicleType() && + json["subtype"].toInt() == getWizard()->getVehicleSubType()) { + QString uuid = json["uuid"].toString(); + if (!m_templates.contains(uuid)) { + m_templates[json["uuid"].toString()] = new QJsonObject(json); + } } + } else { + qDebug() << "Error parsing json file: " + << fileName << ". Error was:" << error.errorString(); } } file.close(); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp index 051fbb45f..54c3708e3 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp @@ -377,7 +377,7 @@ void OutputCalibrationPage::on_motorNeutralButton_toggled(bool checked) ui->motorNeutralSlider->setEnabled(checked); quint16 channel = getCurrentChannel(); quint16 safeValue = m_actuatorSettings[channel].channelNeutral; - onStartButtonToggle(ui->motorNeutralButton, channel, m_actuatorSettings[channel].channelNeutral, safeValue, ui->motorNeutralSlider); + onStartButtonToggle(ui->motorNeutralButton, channel, m_actuatorSettings[channel].channelNeutral, 0, ui->motorNeutralSlider); } void OutputCalibrationPage::onStartButtonToggle(QAbstractButton *button, quint16 channel, quint16 value, quint16 safeValue, QSlider *slider) diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp index 9e85e5158..0f8b6f111 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp @@ -162,17 +162,6 @@ QString VehicleTemplateExportDialog::setupVehicleType() } } -QString VehicleTemplateExportDialog::fixFilenameString(QString input, int truncate) -{ - return input.replace(' ', "").replace('|', "").replace('/', "") - .replace('\\', "").replace(':', "").replace('"', "") - .replace('\'', "").replace('?', "").replace('*', "") - .replace('>', "").replace('<', "") - .replace('}', "").replace('{', "") - .left(truncate); -} - - void VehicleTemplateExportDialog::accept() { QJsonObject exportObject; @@ -211,24 +200,23 @@ void VehicleTemplateExportDialog::accept() QJsonDocument saveDoc(exportObject); - QString fileName = QString("%1/%2/%3-%4-%5.optmpl") - .arg(EXPORT_BASE_NAME) - .arg(getTypeDirectory()) - .arg(fixFilenameString(ui->Name->text(), 20)) - .arg(fixFilenameString(ui->Type->text(), 30)) - .arg(fixFilenameString(uuid.toString().right(12))); - QFile saveFile(fileName); - QDir dir; - dir.mkpath(QFileInfo(saveFile).absoluteDir().absolutePath()); - if (saveFile.open(QIODevice::WriteOnly)) { - saveFile.write(saveDoc.toJson()); - saveFile.close(); - QMessageBox::information(this, "Export", tr("Settings were exported to \n%1").arg(QFileInfo(saveFile).absoluteFilePath()), QMessageBox::Ok); - } else { - QMessageBox::information(this, "Export", tr("Settings could not be exported to \n%1.\nPlease try again.") - .arg(QFileInfo(saveFile).absoluteFilePath()), QMessageBox::Ok); + const char *fileType = ".optmpl"; + QString fileName = QFileDialog::getSaveFileName(this, tr("Export settings"), "fileName""", QString("%1 (*%2)").arg(tr("OPTemplates", fileType))); + + if (!fileName.isEmpty()) { + if (!fileName.endsWith(fileType)) { + fileName.append(fileType); + } + QFile saveFile(fileName); + if (saveFile.open(QIODevice::WriteOnly)) { + saveFile.write(saveDoc.toJson()); + saveFile.close(); + } else { + QMessageBox::information(this, "Export", tr("Settings could not be exported to \n%1(%2).\nPlease try again.") + .arg(QFileInfo(saveFile).absoluteFilePath(), saveFile.error()), QMessageBox::Ok); + } + QDialog::accept(); } - QDialog::accept(); } void VehicleTemplateExportDialog::importImage() diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h index 61f627be9..9812fa05d 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h @@ -68,7 +68,6 @@ private: QString getTypeDirectory(); QString setupVehicleType(); - QString fixFilenameString(QString input, int truncate = 100); }; #endif // VEHICLETEMPLATEEXPORTDIALOG_H