1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Merge branch 'rel-14.10' of ssh://git.openpilot.org/OpenPilot into rel-14.10

This commit is contained in:
Laurent Lalanne 2014-10-24 21:40:17 +02:00
commit 0c7264cd19
4 changed files with 30 additions and 37 deletions

View File

@ -170,14 +170,20 @@ void AirframeInitialTuningPage::loadValidFiles()
if (file.open(QFile::ReadOnly)) { if (file.open(QFile::ReadOnly)) {
QByteArray jsonData = file.readAll(); QByteArray jsonData = file.readAll();
QJsonDocument templateDoc = QJsonDocument::fromJson(jsonData); QJsonParseError error;
QJsonObject json = templateDoc.object(); QJsonDocument templateDoc = QJsonDocument::fromJson(jsonData, &error);
if (json["type"].toInt() == getWizard()->getVehicleType() && if (error.error == QJsonParseError::NoError) {
json["subtype"].toInt() == getWizard()->getVehicleSubType()) { QJsonObject json = templateDoc.object();
QString uuid = json["uuid"].toString(); if (json["type"].toInt() == getWizard()->getVehicleType() &&
if (!m_templates.contains(uuid)) { json["subtype"].toInt() == getWizard()->getVehicleSubType()) {
m_templates[json["uuid"].toString()] = new QJsonObject(json); 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(); file.close();

View File

@ -377,7 +377,7 @@ void OutputCalibrationPage::on_motorNeutralButton_toggled(bool checked)
ui->motorNeutralSlider->setEnabled(checked); ui->motorNeutralSlider->setEnabled(checked);
quint16 channel = getCurrentChannel(); quint16 channel = getCurrentChannel();
quint16 safeValue = m_actuatorSettings[channel].channelNeutral; 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) void OutputCalibrationPage::onStartButtonToggle(QAbstractButton *button, quint16 channel, quint16 value, quint16 safeValue, QSlider *slider)

View File

@ -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() void VehicleTemplateExportDialog::accept()
{ {
QJsonObject exportObject; QJsonObject exportObject;
@ -211,24 +200,23 @@ void VehicleTemplateExportDialog::accept()
QJsonDocument saveDoc(exportObject); QJsonDocument saveDoc(exportObject);
QString fileName = QString("%1/%2/%3-%4-%5.optmpl") const char *fileType = ".optmpl";
.arg(EXPORT_BASE_NAME) QString fileName = QFileDialog::getSaveFileName(this, tr("Export settings"), "fileName""", QString("%1 (*%2)").arg(tr("OPTemplates", fileType)));
.arg(getTypeDirectory())
.arg(fixFilenameString(ui->Name->text(), 20)) if (!fileName.isEmpty()) {
.arg(fixFilenameString(ui->Type->text(), 30)) if (!fileName.endsWith(fileType)) {
.arg(fixFilenameString(uuid.toString().right(12))); fileName.append(fileType);
QFile saveFile(fileName); }
QDir dir; QFile saveFile(fileName);
dir.mkpath(QFileInfo(saveFile).absoluteDir().absolutePath()); if (saveFile.open(QIODevice::WriteOnly)) {
if (saveFile.open(QIODevice::WriteOnly)) { saveFile.write(saveDoc.toJson());
saveFile.write(saveDoc.toJson()); saveFile.close();
saveFile.close(); } else {
QMessageBox::information(this, "Export", tr("Settings were exported to \n%1").arg(QFileInfo(saveFile).absoluteFilePath()), QMessageBox::Ok); QMessageBox::information(this, "Export", tr("Settings could not be exported to \n%1(%2).\nPlease try again.")
} else { .arg(QFileInfo(saveFile).absoluteFilePath(), saveFile.error()), QMessageBox::Ok);
QMessageBox::information(this, "Export", tr("Settings could not be exported to \n%1.\nPlease try again.") }
.arg(QFileInfo(saveFile).absoluteFilePath()), QMessageBox::Ok); QDialog::accept();
} }
QDialog::accept();
} }
void VehicleTemplateExportDialog::importImage() void VehicleTemplateExportDialog::importImage()

View File

@ -68,7 +68,6 @@ private:
QString getTypeDirectory(); QString getTypeDirectory();
QString setupVehicleType(); QString setupVehicleType();
QString fixFilenameString(QString input, int truncate = 100);
}; };
#endif // VEHICLETEMPLATEEXPORTDIALOG_H #endif // VEHICLETEMPLATEEXPORTDIALOG_H