diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp index 9ed768642..2567bca10 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp @@ -101,7 +101,7 @@ void AirframeInitialTuningPage::updatePhoto(QJsonObject *templ) if (m_photoItem != NULL) { ui->templateImage->scene()->removeItem(m_photoItem); } - if (templ != NULL) { + if (templ != NULL && !templ->value("photo").isUndefined()) { QByteArray imageData = QByteArray::fromBase64(templ->value("photo").toString().toLatin1()); photo.loadFromData(imageData, "PNG"); } else { diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp index 54c3708e3..68b0f0e93 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputcalibrationpage.cpp @@ -376,8 +376,8 @@ void OutputCalibrationPage::on_motorNeutralButton_toggled(bool checked) ui->motorNeutralButton->setText(checked ? tr("Stop") : tr("Start")); ui->motorNeutralSlider->setEnabled(checked); quint16 channel = getCurrentChannel(); - quint16 safeValue = m_actuatorSettings[channel].channelNeutral; - onStartButtonToggle(ui->motorNeutralButton, channel, m_actuatorSettings[channel].channelNeutral, 0, ui->motorNeutralSlider); + quint16 safeValue = 0; + onStartButtonToggle(ui->motorNeutralButton, channel, m_actuatorSettings[channel].channelNeutral, safeValue, ui->motorNeutralSlider); } void OutputCalibrationPage::onStartButtonToggle(QAbstractButton *button, quint16 channel, quint16 value, quint16 safeValue, QSlider *slider) diff --git a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp index 63cee784a..aa1330aad 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp @@ -56,10 +56,11 @@ SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), VehicleConfigurationSource(), m_controllerType(CONTROLLER_UNKNOWN), - m_vehicleType(VEHICLE_UNKNOWN), m_inputType(INPUT_UNKNOWN), m_escType(ESC_UNKNOWN), - m_servoType(SERVO_UNKNOWN), m_vehicleTemplate(NULL), - m_gpsType(GPS_DISABLED), m_airspeedType(AIRSPEED_DISABLED), - m_calibrationPerformed(false), m_restartNeeded(false), m_connectionManager(0) + m_vehicleType(VEHICLE_UNKNOWN), m_inputType(INPUT_UNKNOWN), + m_escType(ESC_UNKNOWN), m_servoType(SERVO_UNKNOWN), + m_airspeedType(AIRSPEED_DISABLED), m_gpsType(GPS_DISABLED), + m_vehicleTemplate(NULL), m_calibrationPerformed(false), + m_restartNeeded(false), m_connectionManager(NULL) { setWindowTitle(tr("OpenPilot Setup Wizard")); setOption(QWizard::IndependentPages, false); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp index 0f8b6f111..c2c57249c 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp @@ -162,6 +162,16 @@ 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; @@ -191,23 +201,44 @@ void VehicleTemplateExportDialog::accept() QUuid uuid = QUuid::createUuid(); exportObject["uuid"] = uuid.toString(); - QByteArray bytes; - QBuffer buffer(&bytes); - buffer.open(QIODevice::WriteOnly); - m_image.scaled(IMAGE_SCALE_WIDTH, IMAGE_SCALE_HEIGHT, Qt::KeepAspectRatio, - Qt::SmoothTransformation).save(&buffer, "PNG"); - exportObject["photo"] = QString::fromLatin1(bytes.toBase64().data()); + if (!m_image.isNull()) { + QByteArray bytes; + QBuffer buffer(&bytes); + buffer.open(QIODevice::WriteOnly); + m_image.scaled(IMAGE_SCALE_WIDTH, IMAGE_SCALE_HEIGHT, Qt::KeepAspectRatio, + Qt::SmoothTransformation).save(&buffer, "PNG"); + exportObject["photo"] = QString::fromLatin1(bytes.toBase64().data()); + } QJsonDocument saveDoc(exportObject); 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); + QString fileName = QString("%1-%2-%3%4") + .arg(fixFilenameString(ui->Name->text(), 20)) + .arg(fixFilenameString(ui->Type->text(), 30)) + .arg(fixFilenameString(uuid.toString().right(12))) + .arg(fileType); + + QString fullPath = QString("%1%2%3%4%5") + .arg(EXPORT_BASE_NAME) + .arg(QDir::separator()) + .arg(getTypeDirectory()) + .arg(QDir::separator()) + .arg(fileName); + + QDir dir = QFileInfo(QFile(fullPath)).absoluteDir(); + if (!dir.exists()) { + fullPath = QString("%1%2%3").arg(QDir::homePath(), QDir::separator(), fileName); + } + + fullPath = QFileDialog::getSaveFileName(this, tr("Export settings"), fullPath, QString("%1 (*%2)").arg(tr("OPTemplates", fileType))); + + if (!fullPath.isEmpty()) { + if (!fullPath.endsWith(fileType)) { + fullPath.append(fileType); } - QFile saveFile(fileName); + QFile saveFile(fullPath); if (saveFile.open(QIODevice::WriteOnly)) { saveFile.write(saveDoc.toJson()); saveFile.close(); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h index 9812fa05d..02bf48949 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h @@ -66,6 +66,7 @@ private: VehicleConfigurationSource::VEHICLE_SUB_TYPE m_subType; QPixmap m_image; + QString fixFilenameString(QString input, int truncate = 100); QString getTypeDirectory(); QString setupVehicleType(); };