diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index c013e2d62..69a232dbf 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -314,31 +314,49 @@ void LogsDialog::exportToGoogleEarth() // filter data points QList dataPoints = filterGePoints(csvlog); int n = dataPoints.count(); // number of points to export - if (n==0) return; + if (n == 0) return; - int gpscol=0, altcol=0, speedcol=0; + int gpscol = 0, altcol = 0, speedcol = 0, datecol = 0, timecol = 0; double altMultiplier = 1.0; - QSet nondataCols; - for (int i=1; i extradataCols; + + for (int i = 1; i < dataPoints.at(0).count(); i++) { + // Date and Time // Long,Lat,Course,GPS Speed,GPS Alt - if (dataPoints.at(0).at(i) == "GPS") { + bool incExtraData = true; + + if (dataPoints.at(0).at(i) == "Date") { + datecol=i; + incExtraData = false; + } else if (dataPoints.at(0).at(i) == "Time") { + timecol=i; + incExtraData = false; + } else if (dataPoints.at(0).at(i) == "GPS") { gpscol=i; - } - if (dataPoints.at(0).at(i).contains("GAlt")) { + incExtraData = false; + } else if (dataPoints.at(0).at(i).contains("GAlt")) { altcol = i; - nondataCols << i; + incExtraData = false; if (dataPoints.at(0).at(i).contains("(ft)")) { altMultiplier = 0.3048; // feet to meters } - } - if (dataPoints.at(0).at(i).contains("GSpd")) { + } else if (dataPoints.at(0).at(i).contains("GSpd")) { speedcol = i; - nondataCols << i; + incExtraData = false; + } + + if (incExtraData) { + for (int j = 0; j < ui->FieldsTW->rowCount(); j++) { + if (ui->FieldsTW->item(j, 0) && ui->FieldsTW->item(j, 0)->isSelected() && + ui->FieldsTW->item(j, 0)->data(Qt::DisplayRole).toString() == dataPoints.at(0).at(i)) { + extradataCols << i; // save data index not selection list index + } + } } } - if (gpscol==0 ) { + if (gpscol == 0 ) { return; } @@ -372,22 +390,20 @@ void LogsDialog::exportToGoogleEarth() outputStream << "\t\t\t\n\t\t\t\tGPS Speed\n\t\t\t\n"; // declare additional fields - for (int i=0; iFieldsTW->item(i, 0) && ui->FieldsTW->item(i, 0)->isSelected() && !nondataCols.contains(i+2)) { - QString origName = dataPoints.at(0).at(i+2); - QString safeName = origName; - safeName.replace(" ","_"); - outputStream << "\t\t\t\n\t\t\t\t" << origName << "\n\t\t\t\n"; - } + for (auto i = extradataCols.cbegin(), end = extradataCols.cend(); i != end; ++i) { + QString origName = dataPoints.at(0).at(*i); + QString safeName = origName; + safeName.replace(" ","_"); + outputStream << "\t\t\t\n\t\t\t\t" << origName << "\n\t\t\t\n"; } QString planeName; - if (logFilename.indexOf("-")>0) { - planeName=logFilename.left(logFilename.indexOf("-")); + if (logFilename.indexOf("-") > 0) { + planeName = logFilename.left(logFilename.indexOf("-")); } else { - planeName=logFilename; + planeName = logFilename; } outputStream << "\t\t\n"; @@ -396,16 +412,17 @@ void LogsDialog::exportToGoogleEarth() outputStream << "\n\t\t\t\t\n"; outputStream << "\n\t\t\t\t\tabsolute\n"; - // time data points - for (int i=1; i"<< tstamp <<"\n"; } // coordinate data points outputStream.setRealNumberNotation(QTextStream::FixedNotation); outputStream.setRealNumberPrecision(8); - for (int i=1; i" << coord.longitude << " " << coord.latitude << " " << altitude << " \n" ; @@ -417,23 +434,24 @@ void LogsDialog::exportToGoogleEarth() if (speedcol) { // gps speed data points outputStream << "\t\t\t\t\t\t\t\n"; - for (int i=1; i"<< dataPoints.at(i).at(speedcol) <<"\n"; } outputStream << "\t\t\t\t\t\t\t\n"; } // add values for additional fields - for (int i=0; iFieldsTW->item(i, 0) && ui->FieldsTW->item(i, 0)->isSelected() && !nondataCols.contains(i+2)) { - QString safeName = dataPoints.at(0).at(i+2);; - safeName.replace(" ","_"); - outputStream << "\t\t\t\t\t\t\t\n"; - for (int j=1; j"<< dataPoints.at(j).at(i+2) <<"\n"; - } - outputStream << "\t\t\t\t\t\t\t\n"; + for (auto i = extradataCols.cbegin(), end = extradataCols.cend(); i != end; ++i) { + QString safeName = dataPoints.at(0).at(*i); + safeName.replace(" ","_"); + outputStream << "\t\t\t\t\t\t\t\n"; + + for (int j = 1; j < n; j++) { + outputStream << "\t\t\t\t\t\t\t\t"<< dataPoints.at(j).at(*i) <<"\n"; } + + outputStream << "\t\t\t\t\t\t\t\n"; } 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";