mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 16:39:57 +00:00
File Export (part 1 of 2)
The export functions in mainwindow are getting quite cumbersome with multiple menu options. This patch creates a single menu option "Export.." which allows the user to select a supported format and a filename. To support this the ridefile reader code needed to be adjusted to allow registered readers to declare capability to write and use a consistent (virtual) method to do so. By modifying the base class for ride file reader we now allow new readers to register both read and write capability.
This commit is contained in:
@@ -350,3 +350,51 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CsvFileReader::writeRideFile(MainWindow *, const RideFile *ride, QFile &file) const
|
||||
{
|
||||
if (!file.open(QIODevice::WriteOnly)) return(false);
|
||||
|
||||
// always save CSV in metric format
|
||||
bool bIsMetric = true;
|
||||
|
||||
// Use the column headers that make WKO+ happy.
|
||||
double convertUnit;
|
||||
QTextStream out(&file);
|
||||
if (!bIsMetric)
|
||||
{
|
||||
out << "Minutes,Torq (N-m),MPH,Watts,Miles,Cadence,Hrate,ID,Altitude (feet)\n";
|
||||
convertUnit = MILES_PER_KM;
|
||||
}
|
||||
else {
|
||||
out << "Minutes,Torq (N-m),Km/h,Watts,Km,Cadence,Hrate,ID,Altitude (m)\n";
|
||||
convertUnit = 1.0;
|
||||
}
|
||||
|
||||
foreach (const RideFilePoint *point, ride->dataPoints()) {
|
||||
if (point->secs == 0.0)
|
||||
continue;
|
||||
out << point->secs/60.0;
|
||||
out << ",";
|
||||
out << ((point->nm >= 0) ? point->nm : 0.0);
|
||||
out << ",";
|
||||
out << ((point->kph >= 0) ? (point->kph * convertUnit) : 0.0);
|
||||
out << ",";
|
||||
out << ((point->watts >= 0) ? point->watts : 0.0);
|
||||
out << ",";
|
||||
out << point->km * convertUnit;
|
||||
out << ",";
|
||||
out << point->cad;
|
||||
out << ",";
|
||||
out << point->hr;
|
||||
out << ",";
|
||||
out << point->interval;
|
||||
out << ",";
|
||||
out << point->alt;
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user