mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Add ability to export all csv
.. for batch export
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "Athlete.h"
|
||||
#include "RideCache.h"
|
||||
#include "HelpWhatsThis.h"
|
||||
#include "CsvRideFile.h"
|
||||
|
||||
BatchExportDialog::BatchExportDialog(Context *context) : QDialog(context->mainWindow), context(context)
|
||||
{
|
||||
@@ -82,6 +83,7 @@ BatchExportDialog::BatchExportDialog(Context *context) : QDialog(context->mainWi
|
||||
format = new QComboBox(this);
|
||||
|
||||
const RideFileFactory &rff = RideFileFactory::instance();
|
||||
format->addItem(tr("Export all data (CSV)"));
|
||||
foreach(QString suffix, rff.writeSuffixes()) format->addItem(rff.description(suffix));
|
||||
format->setCurrentIndex(appsettings->value(this, GC_BE_LASTFMT, "0").toInt());
|
||||
|
||||
@@ -191,7 +193,7 @@ void
|
||||
BatchExportDialog::exportFiles()
|
||||
{
|
||||
// what format to export as?
|
||||
QString type = RideFileFactory::instance().writeSuffixes().at(format->currentIndex());
|
||||
QString type = format->currentIndex() > 0 ? RideFileFactory::instance().writeSuffixes().at(format->currentIndex()-1) : "csv";
|
||||
|
||||
// loop through the table and export all selected
|
||||
for(int i=0; i<files->invisibleRootItem()->childCount(); i++) {
|
||||
@@ -241,7 +243,14 @@ BatchExportDialog::exportFiles()
|
||||
|
||||
current->setText(4, tr("Writing...")); QApplication::processEvents();
|
||||
QFile out(filename);
|
||||
bool success = RideFileFactory::instance().writeRideFile(context, ride, out, type);
|
||||
|
||||
bool success = false;
|
||||
if (format->currentIndex() > 0)
|
||||
success = RideFileFactory::instance().writeRideFile(context, ride, out, type);
|
||||
else {
|
||||
CsvFileReader writer;
|
||||
success = writer.writeRideFile(context, ride, out, CsvFileReader::gc);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
exports++;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
static int csvFileReaderRegistered =
|
||||
RideFileFactory::instance().registerReader(
|
||||
"csv","Comma-Separated Values", new CsvFileReader());
|
||||
"csv","Poweragent / PowerTap (CSV)", new CsvFileReader());
|
||||
|
||||
int static periMonth(QString month)
|
||||
{
|
||||
@@ -836,7 +836,7 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
|
||||
}
|
||||
|
||||
bool
|
||||
CsvFileReader::writeRideFile(Context *, const RideFile *ride, QFile &file) const
|
||||
CsvFileReader::writeRideFile(Context *, const RideFile *ride, QFile &file, CsvType format) const
|
||||
{
|
||||
if (!file.open(QIODevice::WriteOnly)) return(false);
|
||||
|
||||
@@ -847,8 +847,6 @@ CsvFileReader::writeRideFile(Context *, const RideFile *ride, QFile &file) const
|
||||
double convertUnit;
|
||||
QTextStream out(&file);
|
||||
|
||||
CsvType format = powertap;
|
||||
|
||||
if (format == gc) {
|
||||
// CSV File header
|
||||
out << "secs, cad, hr, km, kph, nm, watts, alt, lon, lat, headwind, slope, temp, interval, lrbalance, lte, rte, lps, rps, smo2, thb, o2hb, hhb\n";
|
||||
|
||||
@@ -22,12 +22,18 @@
|
||||
|
||||
#include "RideFile.h"
|
||||
|
||||
enum csvtypes { generic, gc, powertap, joule, ergomo, motoactv, ibike, moxy, freemotion, peripedal, cpexport };
|
||||
typedef enum csvtypes CsvType;
|
||||
|
||||
struct CsvFileReader : public RideFileReader {
|
||||
enum csvtypes { generic, gc, powertap, joule, ergomo, motoactv, ibike, moxy, freemotion, peripedal, cpexport };
|
||||
typedef enum csvtypes CsvType;
|
||||
|
||||
virtual RideFile *openRideFile(QFile &file, QStringList &errors, QList<RideFile*>* = 0) const;
|
||||
bool writeRideFile(Context *context, const RideFile *ride, QFile &file) const;
|
||||
|
||||
// standard calling semantics - will write as powertap csv
|
||||
bool writeRideFile(Context *context, const RideFile *ride, QFile &file) const
|
||||
{ return writeRideFile(context, ride, file, powertap); }
|
||||
|
||||
// write but able to select format
|
||||
bool writeRideFile(Context *context, const RideFile *ride, QFile &file, CsvType format) const;
|
||||
bool hasWrite() const { return true; }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user