1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 01:35:21 +03:00

[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.
This commit is contained in:
Max Paperno 2018-06-03 17:19:25 -04:00 committed by Bertrand Songis
parent a6afbebc94
commit 9796654816
2 changed files with 15 additions and 20 deletions

View file

@ -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<QStringList> LogsDialog::filterGePoints(const QList<QStringList> & 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 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">\n";
outputStream << "\t<Document>\n\t\t<name>" << logFilename << "</name>\n";
outputStream << "\t\t<Style id=\"multiTrack_n\">\n\t\t\t<IconStyle>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>file://" << geIconFilename << "</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>6</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
outputStream << "\t\t<Style id=\"multiTrack_h\">\n\t\t\t<IconStyle>\n\t\t\t\t<scale>0</scale>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>file://" << geIconFilename << "</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>8</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
outputStream << "\t\t<Style id=\"multiTrack_n\">\n\t\t\t<IconStyle>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>" << geIconFilename << "</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>6</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
outputStream << "\t\t<Style id=\"multiTrack_h\">\n\t\t\t<IconStyle>\n\t\t\t\t<scale>0</scale>\n\t\t\t\t<Icon>\n\t\t\t\t\t<href>" << geIconFilename << "</href>\n\t\t\t\t</Icon>\n\t\t\t</IconStyle>\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>8</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
outputStream << "\t\t<StyleMap id=\"multiTrack\">\n\t\t\t<Pair>\n\t\t\t\t<key>normal</key>\n\t\t\t\t<styleUrl>#multiTrack_n</styleUrl>\n\t\t\t</Pair>\n\t\t\t<Pair>\n\t\t\t\t<key>highlight</key>\n\t\t\t\t<styleUrl>#multiTrack_h</styleUrl>\n\t\t\t</Pair>\n\t\t</StyleMap>\n";
outputStream << "\t\t<Style id=\"lineStyle\">\n\t\t\t<LineStyle>\n\t\t\t\t<color>991081f4</color>\n\t\t\t\t<width>6</width>\n\t\t\t</LineStyle>\n\t\t</Style>\n";
outputStream << "\t\t<Schema id=\"schema\">\n";
@ -423,7 +420,6 @@ void LogsDialog::exportToGoogleEarth()
outputStream << "\t\t\t\t\t\t</SchemaData>\n\t\t\t\t\t</ExtendedData>\n\t\t\t\t</gx:Track>\n\t\t\t</Placemark>\n\t\t</Folder>\n\t</Document>\n</kml>";
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

View file

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