/* * Copyright (c) 2010 Greg Lonnon (greg.lonnon@gmail.com) copied from TcxRideFile.cpp * * Copyright (c) 2008 Sean C. Rhea (srhea@srhea.net), * J.T Conklin (jtc@acorntoolworks.com) * * 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 "GpxRideFile.h" #include "GpxParser.h" #include "GcUpgrade.h" #include static int gpxFileReaderRegistered = RideFileFactory::instance().registerReader( "gpx", "GPS Exchange format", new GpxFileReader()); RideFile *GpxFileReader::openRideFile(QFile &file, QStringList &errors, QList*) const { (void) errors; RideFile *rideFile = new RideFile(); rideFile->setRecIntSecs(1.0); //rideFile->setDeviceType("GPS Exchange Format"); rideFile->setFileFormat("GPS Exchange Format (gpx)"); GpxParser handler(rideFile); QXmlInputSource source (&file); QXmlSimpleReader reader; reader.setContentHandler (&handler); reader.parse (source); return rideFile; } QByteArray GpxFileReader::toByteArray(Context *, const RideFile *ride, bool withAlt, bool withWatts, bool withHr, bool withCad) const { // // GPX Standard defined here: http://www.topografix.com/GPX/1/1/ // QDomDocument doc; QDomProcessingInstruction hdr = doc.createProcessingInstruction("xml","version=\"1.0\""); doc.appendChild(hdr); QDomElement gpx = doc.createElementNS("http://www.topografix.com/GPX/1/1", "gpx"); gpx.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); gpx.setAttribute("xmlns:gpxtpx", "http://www.garmin.com/xmlschemas/TrackPointExtension/v1"); gpx.setAttribute("xmlns:gpxpx", "http://www.garmin.com/xmlschemas/PowerExtension/v1"); gpx.setAttribute("xsi:schemaLocation", "http://www.topografix.com/GPX/1/1" " " "http://www.topografix.com/GPX/1/1/gpx.xsd" " " "http://www.garmin.com/xmlschemas/TrackPointExtension/v1" " " "http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" " " "http://www.garmin.com/xmlschemas/PowerExtension/v1" " " "http://www.garmin.com/xmlschemas/PowerExtensionv1.xsd" ); gpx.setAttribute("version", "1.1"); gpx.setAttribute("creator", QString("GoldenCheetah (build %1) with Barometer").arg(VERSION_LATEST)); doc.appendChild(gpx); // If we have data points, we'll have a and in that a and in that a bunch of if (!ride->dataPoints().empty()) { QDomElement trk = doc.createElement("trk"); gpx.appendChild(trk); QDomElement trkseg = doc.createElement("trkseg"); trk.appendChild(trkseg); QLocale cLocale(QLocale::Language::C); foreach (const RideFilePoint *point, ride->dataPoints()) { QDomElement trkpt = doc.createElement("trkpt"); trkseg.appendChild(trkpt); QString strLat = cLocale.toString(point->lat, 'g', 12); trkpt.setAttribute("lat", strLat); QString strLon = cLocale.toString(point->lon, 'g', 12); trkpt.setAttribute("lon", strLon); // GPX standard requires , if present, to be first if (withAlt && ride->areDataPresent()->alt) { QDomElement ele = doc.createElement("ele"); //QDomText text = doc.createTextNode(QString("%1").arg(point->alt, 0, 'f', 1)); //ele.appendChild(text); ele.appendChild(doc.createTextNode(QString("%1").arg(point->alt, 0, 'f', 1))); trkpt.appendChild(ele); } // GPX standard requires