From 2e7d76cb33f97502c0ff118381e1ff49c25e7022 Mon Sep 17 00:00:00 2001 From: m_thread Date: Fri, 24 Oct 2014 16:24:06 +0200 Subject: [PATCH 1/2] Fixed export dialog for 'cloud' settings export. --- .../pages/airframeinitialtuningpage.cpp | 20 ++++++--- .../vehicletemplateexportdialog.cpp | 44 +++++++------------ .../setupwizard/vehicletemplateexportdialog.h | 1 - 3 files changed, 29 insertions(+), 36 deletions(-) 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/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 From 0457e2213289b434f74bdaca3199fef8c1a0455c Mon Sep 17 00:00:00 2001 From: m_thread Date: Fri, 24 Oct 2014 16:35:53 +0200 Subject: [PATCH 2/2] Changed safe actuator value for motors to 0 ( for extra safety ). --- .../src/plugins/setupwizard/pages/outputcalibrationpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)