mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
remove XmlRideFile and "Export to XML"
These were part of an earlier attempt at a GC-specific ride file format. They aren't in use now, and they'll be replaced by the new one when it's done.
This commit is contained in:
@@ -256,8 +256,6 @@ MainWindow::MainWindow(const QDir &home) :
|
||||
SLOT(downloadRide()), tr("Ctrl+D"));
|
||||
rideMenu->addAction(tr("&Export to CSV..."), this,
|
||||
SLOT(exportCSV()), tr("Ctrl+E"));
|
||||
rideMenu->addAction(tr("&Export to XML..."), this,
|
||||
SLOT(exportXML()));
|
||||
rideMenu->addAction(tr("&Import from File..."), this,
|
||||
SLOT (importFile()), tr ("Ctrl+I"));
|
||||
rideMenu->addAction(tr("Find &best intervals..."), this,
|
||||
@@ -463,32 +461,6 @@ MainWindow::currentRide()
|
||||
return ((RideItem*) treeWidget->selectedItems().first())->ride;
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::exportXML()
|
||||
{
|
||||
if ((treeWidget->selectedItems().size() != 1)
|
||||
|| (treeWidget->selectedItems().first()->type() != RIDE_TYPE)) {
|
||||
QMessageBox::critical(this, tr("Select Ride"), tr("No ride selected!"));
|
||||
return;
|
||||
}
|
||||
|
||||
RideItem *ride = (RideItem*) treeWidget->selectedItems().first();
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
this, tr("Export XML"), QDir::homePath(), tr("XML (*.xml)"));
|
||||
if (fileName.length() == 0)
|
||||
return;
|
||||
|
||||
QString err;
|
||||
QFile file(fileName);
|
||||
ride->ride->writeAsXml(file, err);
|
||||
if (err.length() > 0) {
|
||||
QMessageBox::critical(this, tr("Export XML"),
|
||||
tr("Error writing %1: %2").arg(fileName).arg(err));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::exportCSV()
|
||||
{
|
||||
|
||||
@@ -68,7 +68,6 @@ class MainWindow : public QMainWindow
|
||||
void downloadRide();
|
||||
void manualRide();
|
||||
void exportCSV();
|
||||
void exportXML();
|
||||
void importFile();
|
||||
void findBestIntervals();
|
||||
void splitRide();
|
||||
|
||||
@@ -23,89 +23,6 @@
|
||||
#include <QtXml/QtXml>
|
||||
#include <assert.h>
|
||||
|
||||
static void
|
||||
markInterval(QDomDocument &doc, QDomNode &xride, QDomNode &xintervals,
|
||||
double &startSecs, double prevSecs,
|
||||
int &thisInterval, RideFilePoint *sample)
|
||||
{
|
||||
if (xintervals.isNull()) {
|
||||
xintervals = doc.createElement("intervals");
|
||||
xride.appendChild(xintervals);
|
||||
}
|
||||
QDomElement xint = doc.createElement("interval").toElement();
|
||||
xintervals.appendChild(xint);
|
||||
xint.setAttribute("name", thisInterval);
|
||||
xint.setAttribute("from_secs", QString("%1").arg(startSecs, 0, 'f', 2));
|
||||
xint.setAttribute("thru_secs", QString("%1").arg(prevSecs, 0, 'f', 2));
|
||||
startSecs = sample->secs;
|
||||
thisInterval = sample->interval;
|
||||
}
|
||||
|
||||
static void
|
||||
append_text(QDomDocument &doc, QDomNode &parent,
|
||||
const QString &child_name, const QString &child_value)
|
||||
{
|
||||
QDomNode child = parent.appendChild(doc.createElement(child_name));
|
||||
child.appendChild(doc.createTextNode(child_value));
|
||||
}
|
||||
|
||||
bool
|
||||
RideFile::writeAsXml(QFile &file, QString &err) const
|
||||
{
|
||||
(void) err;
|
||||
QDomDocument doc("GoldenCheetah-1.0");
|
||||
QDomNode xride = doc.appendChild(doc.createElement("ride"));
|
||||
QDomNode xheader = xride.appendChild(doc.createElement("header"));
|
||||
append_text(doc, xheader, "start_time", startTime_.toString("yyyy/MM/dd hh:mm:ss"));
|
||||
append_text(doc, xheader, "device_type", deviceType_);
|
||||
append_text(doc, xheader, "rec_int_secs", QString("%1").arg(recIntSecs_, 0, 'f', 3));
|
||||
QDomNode xintervals;
|
||||
bool hasNm = false;
|
||||
double startSecs = 0.0, prevSecs = 0.0;
|
||||
int thisInterval = 0;
|
||||
QListIterator<RideFilePoint*> i(dataPoints_);
|
||||
RideFilePoint *sample = NULL;
|
||||
while (i.hasNext()) {
|
||||
sample = i.next();
|
||||
if (sample->nm > 0.0)
|
||||
hasNm = true;
|
||||
assert(sample->secs >= 0.0);
|
||||
if (sample->interval != thisInterval) {
|
||||
markInterval(doc, xride, xintervals, startSecs,
|
||||
prevSecs, thisInterval, sample);
|
||||
}
|
||||
prevSecs = sample->secs;
|
||||
}
|
||||
if (sample) {
|
||||
markInterval(doc, xride, xintervals, startSecs,
|
||||
prevSecs, thisInterval, sample);
|
||||
}
|
||||
QDomNode xsamples = doc.createElement("samples");
|
||||
xride.appendChild(xsamples);
|
||||
i.toFront();
|
||||
while (i.hasNext()) {
|
||||
RideFilePoint *sample = i.next();
|
||||
QDomElement xsamp = doc.createElement("sample").toElement();
|
||||
xsamples.appendChild(xsamp);
|
||||
xsamp.setAttribute("secs", QString("%1").arg(sample->secs, 0, 'f', 2));
|
||||
xsamp.setAttribute("cad", QString("%1").arg(sample->cad, 0, 'f', 0));
|
||||
xsamp.setAttribute("hr", QString("%1").arg(sample->hr, 0, 'f', 0));
|
||||
xsamp.setAttribute("km", QString("%1").arg(sample->km, 0, 'f', 3));
|
||||
xsamp.setAttribute("kph", QString("%1").arg(sample->kph, 0, 'f', 1));
|
||||
xsamp.setAttribute("alt", QString("%1").arg(sample->alt, 0, 'f', 1));
|
||||
xsamp.setAttribute("watts", sample->watts);
|
||||
if (hasNm) {
|
||||
double nm = (sample->watts > 0.0) ? sample->nm : 0.0;
|
||||
xsamp.setAttribute("nm", QString("%1").arg(nm, 0,'f', 1));
|
||||
}
|
||||
}
|
||||
file.open(QFile::WriteOnly);
|
||||
QTextStream ts(&file);
|
||||
doc.save(ts, 4);
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void RideFile::writeAsCsv(QFile &file, bool bIsMetric) const
|
||||
{
|
||||
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Sean C. Rhea (srhea@srhea.net),
|
||||
* Justin F. Knotzke (jknotzke@shampoo.ca)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "XmlRideFile.h"
|
||||
#include <QRegExp>
|
||||
#include <QtXml/QtXml>
|
||||
#include <QVector>
|
||||
#include <assert.h>
|
||||
|
||||
static int xmlFileReaderRegistered =
|
||||
RideFileFactory::instance().registerReader(
|
||||
"xml", "XML Ride Files", new XmlFileReader());
|
||||
|
||||
struct Interval {
|
||||
double from_secs, thru_secs;
|
||||
int number;
|
||||
Interval() : from_secs(0.0), thru_secs(0.0), number(0) {}
|
||||
Interval(double f, double t, int n)
|
||||
: from_secs(f), thru_secs(t), number(n) {}
|
||||
};
|
||||
|
||||
RideFile *XmlFileReader::openRideFile(QFile &file, QStringList &errors) const
|
||||
{
|
||||
QVector<Interval> intervals;
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
errors << ("Could not open ride file: \"" + file.fileName() + "\"");
|
||||
return NULL;
|
||||
}
|
||||
QDomDocument doc("GoldenCheetah-1.0");
|
||||
QString errMsg;
|
||||
int errLine, errCol;
|
||||
if (!doc.setContent(&file, false, &errMsg, &errLine, &errCol)) {
|
||||
errors << (QString("xml parsing error line %1, col %2: ").arg(errLine).arg(errCol) + errMsg);
|
||||
return NULL;
|
||||
}
|
||||
file.close();
|
||||
QDomElement xride = doc.documentElement();
|
||||
if (xride.tagName() != "ride") {
|
||||
errors << "root should be <ride>";
|
||||
return NULL;
|
||||
}
|
||||
RideFile *rideFile = new RideFile();
|
||||
QRegExp re("^.*/(\\d\\d\\d\\d)_(\\d\\d)_(\\d\\d)_"
|
||||
"(\\d\\d)_(\\d\\d)_(\\d\\d)\\.xml$");
|
||||
if (re.indexIn(file.fileName()) >= 0) {
|
||||
QDateTime dt(QDate(re.cap(1).toInt(), re.cap(2).toInt(), re.cap(3).toInt()),
|
||||
QTime(re.cap(4).toInt(), re.cap(5).toInt(), re.cap(6).toInt()));
|
||||
rideFile->setStartTime(dt);
|
||||
}
|
||||
QDomNode n = xride.firstChild();
|
||||
while (!n.isNull()) {
|
||||
QDomElement e = n.toElement();
|
||||
if (!e.isNull()) {
|
||||
if (e.tagName() == "header") {
|
||||
QDomNode m = e.firstChild();
|
||||
while (!m.isNull()) {
|
||||
QDomElement f = m.toElement();
|
||||
if (f.tagName() == "start_time") {
|
||||
QRegExp re("^ *(\\d\\d\\d\\d)/(\\d\\d)/(\\d\\d) "
|
||||
"(\\d\\d):(\\d\\d):(\\d\\d) *$");
|
||||
if (re.indexIn(f.text()) < 0) {
|
||||
errors << ("can't parse start time \"" + f.text() + "\"");
|
||||
}
|
||||
else {
|
||||
QDateTime dt(QDate(re.cap(1).toInt(), re.cap(2).toInt(), re.cap(3).toInt()),
|
||||
QTime(re.cap(4).toInt(), re.cap(5).toInt(), re.cap(6).toInt()));
|
||||
if (dt != rideFile->startTime()) {
|
||||
errors << "encoded start time differs from file name";
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (f.tagName() == "rec_int_secs") {
|
||||
rideFile->setRecIntSecs(f.text().toDouble());
|
||||
}
|
||||
else if (f.tagName() == "device_type") {
|
||||
rideFile->setDeviceType(f.text());
|
||||
}
|
||||
else {
|
||||
errors << ("unexpected element <" + e.tagName() + ">");
|
||||
}
|
||||
m = m.nextSibling();
|
||||
}
|
||||
}
|
||||
else if (e.tagName() == "intervals") {
|
||||
QDomNode m = e.firstChild();
|
||||
while (!m.isNull()) {
|
||||
QDomElement f = m.toElement();
|
||||
if (f.tagName() == "interval") {
|
||||
double from_secs = f.attribute("from_secs", "0.0").toDouble();
|
||||
double thru_secs = f.attribute("thru_secs", "0.0").toDouble();
|
||||
int number = intervals.size();
|
||||
intervals.append(Interval(from_secs, thru_secs, number));
|
||||
}
|
||||
else {
|
||||
errors << ("unexpected element <" + e.tagName() + ">");
|
||||
}
|
||||
m = m.nextSibling();
|
||||
}
|
||||
}
|
||||
else if (e.tagName() == "samples") {
|
||||
QDomNode m = e.firstChild();
|
||||
while (!m.isNull()) {
|
||||
QDomElement f = m.toElement();
|
||||
if (f.tagName() == "sample") {
|
||||
double cad = f.attribute("cad", "0.0").toDouble();
|
||||
double hr = f.attribute("hr", "0.0").toDouble();
|
||||
double km = f.attribute("km", "0.0").toDouble();
|
||||
double kph = f.attribute("kph", "0.0").toDouble();
|
||||
double nm = f.attribute("nm", "0.0").toDouble();
|
||||
double secs = f.attribute("secs", "0.0").toDouble();
|
||||
double watts = f.attribute("watts", "0.0").toDouble();
|
||||
double alt = f.attribute("alt", "0.0").toDouble();
|
||||
int interval = 0;
|
||||
for (int i = 0; i < intervals.size(); ++i) {
|
||||
if ((secs >= intervals[i].from_secs)
|
||||
&& (secs <= intervals[i].thru_secs)) {
|
||||
interval = intervals[i].number;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rideFile->appendPoint(secs, cad, hr, km, kph, nm, watts, alt, interval);
|
||||
}
|
||||
else {
|
||||
errors << ("unexpected element <" + e.tagName() + ">");
|
||||
}
|
||||
m = m.nextSibling();
|
||||
}
|
||||
}
|
||||
else {
|
||||
errors << ("unexpected element <" + e.tagName() + ">");
|
||||
}
|
||||
}
|
||||
n = n.nextSibling();
|
||||
}
|
||||
return rideFile;
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Sean C. Rhea (srhea@srhea.net)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _XmlRideFile_h
|
||||
#define _XmlRideFile_h
|
||||
|
||||
#include "RideFile.h"
|
||||
|
||||
struct XmlFileReader : public RideFileReader {
|
||||
virtual RideFile *openRideFile(QFile &file, QStringList &errors) const;
|
||||
};
|
||||
|
||||
#endif // _XmlRideFile_h
|
||||
|
||||
@@ -96,7 +96,6 @@ HEADERS += \
|
||||
Units.h \
|
||||
WeeklySummaryWindow.h \
|
||||
WkoRideFile.h \
|
||||
XmlRideFile.h \
|
||||
Zones.h \
|
||||
srm.h \
|
||||
|
||||
@@ -153,7 +152,6 @@ SOURCES += \
|
||||
ToolsDialog.cpp \
|
||||
WeeklySummaryWindow.cpp \
|
||||
WkoRideFile.cpp \
|
||||
XmlRideFile.cpp \
|
||||
Zones.cpp \
|
||||
main.cpp \
|
||||
srm.cpp \
|
||||
|
||||
Reference in New Issue
Block a user