1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

Fixed export dialog for 'cloud' settings export.

This commit is contained in:
m_thread 2014-10-24 16:24:06 +02:00
parent 9a468beb20
commit 2e7d76cb33
3 changed files with 29 additions and 36 deletions

View File

@ -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();

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()
{
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()

View File

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