From 9796654816d1e3605f0ff44c6e4d7181a0beba43 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Sun, 3 Jun 2018 17:19:25 -0400 Subject: [PATCH] [Companion] Log viewer Google Earth fixes (#5937) * [Companion][LogsDialog] Use relative path for Google Earth track icon (fixes #5080); Use detached process to launch GE (does not restart GE for every export, does not keep handle to GE process); Fix typo in warning message. * [LogsDialog] Use GE export file path as base for icon path (don't assume TempDir); Fix auto-connection warning from Qt due to misnamed function; Remove redundant check for existing GE file. --- companion/src/logsdialog.cpp | 33 ++++++++++++++------------------- companion/src/logsdialog.h | 2 +- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index f7494f5eb..681dda39d 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -118,7 +118,7 @@ LogsDialog::LogsDialog(QWidget *parent) : connect(ui->FieldsTW, SIGNAL(itemSelectionChanged()), this, SLOT(plotLogs())); connect(ui->logTable, SIGNAL(itemSelectionChanged()), this, SLOT(plotLogs())); connect(ui->Reset_PB, SIGNAL(clicked()), this, SLOT(plotLogs())); - connect(ui->SaveSession_PB, SIGNAL(clicked()), this, SLOT(on_saveSession_BT_clicked())); + connect(ui->SaveSession_PB, SIGNAL(clicked()), this, SLOT(saveSession())); } LogsDialog::~LogsDialog() @@ -252,7 +252,7 @@ QList LogsDialog::filterGePoints(const QList & input) } } if (gpscol == 0) { - QMessageBox::critical(this, tr("Error: no GPS data not found"), + QMessageBox::critical(this, tr("Error: no GPS data found"), tr("The column containing GPS coordinates must be named \"GPS\".\n\n\ The columns for altitude \"GAlt\" and for speed \"GSpd\" are optional")); return result; @@ -324,18 +324,9 @@ void LogsDialog::exportToGoogleEarth() } // qDebug() << "gpscol" << gpscol << "altcol" << altcol << "speedcol" << speedcol << "altMultiplier" << altMultiplier; - QString geIconFilename = generateProcessUniqueTempFileName("track0.png"); - if (QFile::exists(geIconFilename)) { - QFile::remove(geIconFilename); - } - QFile::copy(":/images/track0.png", geIconFilename); - - QString geFilename = generateProcessUniqueTempFileName("flight.kml"); - if (QFile::exists(geFilename)) { - QFile::remove(geFilename); - } + const QString geFilename = generateProcessUniqueTempFileName("flight.kml"); QFile geFile(geFilename); - if (!geFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + if (!geFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { QMessageBox::warning(this, CPN_STR_TTL_ERROR, tr("Cannot write file %1:\n%2.") .arg(geFilename) @@ -343,13 +334,19 @@ void LogsDialog::exportToGoogleEarth() return; } + const QString geIconFilename = QStringLiteral("track0.png"); + const QString geIconPath = QFileInfo(geFile).absolutePath() + "/" + geIconFilename; + if (!QFile::exists(geIconPath)) { + QFile::copy(":/images/" + geIconFilename, geIconPath); + } + QTextStream outputStream(&geFile); // file header outputStream << "\n\n"; outputStream << "\t\n\t\t" << logFilename << "\n"; - outputStream << "\t\t\n"; - outputStream << "\t\t\n"; + outputStream << "\t\t\n"; + outputStream << "\t\t\n"; outputStream << "\t\t\n\t\t\t\n\t\t\t\tnormal\n\t\t\t\t#multiTrack_n\n\t\t\t\n\t\t\t\n\t\t\t\thighlight\n\t\t\t\t#multiTrack_h\n\t\t\t\n\t\t\n"; outputStream << "\t\t\n"; outputStream << "\t\t\n"; @@ -423,7 +420,6 @@ void LogsDialog::exportToGoogleEarth() outputStream << "\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\n"; geFile.close(); - QString gePath = g.gePath(); QStringList parameters; #ifdef __APPLE__ parameters << "-a"; @@ -431,8 +427,7 @@ void LogsDialog::exportToGoogleEarth() gePath = "/usr/bin/open"; #endif parameters << geFilename; - QProcess *process = new QProcess(this); - process->start(gePath, parameters); + QProcess::startDetached(g.gePath(), parameters); } void LogsDialog::on_mapsButton_clicked() @@ -613,7 +608,7 @@ void LogsDialog::on_fileOpen_BT_clicked() } } -void LogsDialog::on_saveSession_BT_clicked() +void LogsDialog::saveSession() { int index = ui->sessions_CB->currentIndex(); // ignore index 0 is its all sessions combined diff --git a/companion/src/logsdialog.h b/companion/src/logsdialog.h index 4ea3ce1dd..f3c86eda7 100644 --- a/companion/src/logsdialog.h +++ b/companion/src/logsdialog.h @@ -78,7 +78,7 @@ private slots: void removeAllGraphs(); void plotLogs(); void on_fileOpen_BT_clicked(); - void on_saveSession_BT_clicked(); + void saveSession(); void on_sessions_CB_currentIndexChanged(int index); void on_mapsButton_clicked(); void yAxisChangeRanges(QCPRange range);