1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Added support for TCX and CSV files

This commit is contained in:
Martin Tůma 2016-10-23 11:09:20 +02:00
parent 94fc5e17d0
commit d7fd40d9d2
27 changed files with 702 additions and 446 deletions

View File

@ -8,8 +8,6 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
HEADERS += src/config.h \
src/icons.h \
src/gui.h \
src/gpx.h \
src/parser.h \
src/poi.h \
src/rtree.h \
src/ll.h \
@ -53,11 +51,14 @@ HEADERS += src/config.h \
src/graph.h \
src/pathitem.h \
src/pathview.h \
src/griditem.h
src/griditem.h \
src/data.h \
src/gpxparser.h \
src/tcxparser.h \
src/parser.h \
src/csvparser.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
src/parser.cpp \
src/poi.cpp \
src/ll.cpp \
src/axisitem.cpp \
@ -93,7 +94,11 @@ SOURCES += src/main.cpp \
src/graphitem.cpp \
src/pathitem.cpp \
src/pathview.cpp \
src/griditem.cpp
src/griditem.cpp \
src/data.cpp \
src/gpxparser.cpp \
src/tcxparser.cpp \
src/csvparser.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx {

View File

@ -132,10 +132,6 @@
</context>
<context>
<name>FileSelectWidget</name>
<message>
<source>Browse...</source>
<translation type="obsolete">Procházet...</translation>
</message>
<message>
<location filename="../src/fileselectwidget.cpp" line="38"/>
<source>Select file</source>
@ -145,260 +141,276 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/gui.cpp" line="529"/>
<location filename="../src/gui.cpp" line="538"/>
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="593"/>
<location filename="../src/gui.cpp" line="602"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="672"/>
<location filename="../src/gui.cpp" line="683"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="209"/>
<location filename="../src/gui.cpp" line="215"/>
<source>Open</source>
<translation>Otevřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="193"/>
<location filename="../src/gui.cpp" line="199"/>
<source>Quit</source>
<translation>Ukončit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="201"/>
<location filename="../src/gui.cpp" line="545"/>
<location filename="../src/gui.cpp" line="546"/>
<location filename="../src/gui.cpp" line="207"/>
<location filename="../src/gui.cpp" line="554"/>
<location filename="../src/gui.cpp" line="555"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="225"/>
<location filename="../src/gui.cpp" line="231"/>
<source>Close</source>
<translation>Zavřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="231"/>
<location filename="../src/gui.cpp" line="237"/>
<source>Reload</source>
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="460"/>
<location filename="../src/gui.cpp" line="466"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="382"/>
<location filename="../src/gui.cpp" line="454"/>
<location filename="../src/gui.cpp" line="388"/>
<location filename="../src/gui.cpp" line="460"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="199"/>
<location filename="../src/gui.cpp" line="568"/>
<location filename="../src/gui.cpp" line="569"/>
<location filename="../src/gui.cpp" line="205"/>
<location filename="../src/gui.cpp" line="577"/>
<location filename="../src/gui.cpp" line="578"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="239"/>
<location filename="../src/gui.cpp" line="245"/>
<source>Load POI file</source>
<translation>Nahrát POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="242"/>
<location filename="../src/gui.cpp" line="248"/>
<source>Close POI files</source>
<translation>Zavřit POI soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="244"/>
<location filename="../src/gui.cpp" line="250"/>
<source>Overlap POIs</source>
<translation>Překrývat POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="248"/>
<location filename="../src/gui.cpp" line="254"/>
<source>Show POI labels</source>
<translation>Zobrazovat názvy POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="253"/>
<location filename="../src/gui.cpp" line="259"/>
<source>Show POIs</source>
<translation>Zobrazit POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="262"/>
<location filename="../src/gui.cpp" line="268"/>
<source>Show map</source>
<translation>Zobrazit mapu</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="268"/>
<location filename="../src/gui.cpp" line="274"/>
<source>Clear tile cache</source>
<translation>Vymazat mezipaměť dlaždic</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="277"/>
<location filename="../src/gui.cpp" line="281"/>
<location filename="../src/gui.cpp" line="555"/>
<location filename="../src/gui.cpp" line="283"/>
<location filename="../src/gui.cpp" line="287"/>
<location filename="../src/gui.cpp" line="564"/>
<source>Next map</source>
<translation>Následující mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="288"/>
<location filename="../src/gui.cpp" line="294"/>
<source>Show tracks</source>
<translation>Zobrazit cesty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="292"/>
<location filename="../src/gui.cpp" line="298"/>
<source>Show routes</source>
<translation>Zobrazit trasy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="296"/>
<location filename="../src/gui.cpp" line="302"/>
<source>Show waypoints</source>
<translation>Zobrazit navigační body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="300"/>
<location filename="../src/gui.cpp" line="306"/>
<source>Waypoint labels</source>
<translation>Názvy navigačních bodů</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="311"/>
<location filename="../src/gui.cpp" line="317"/>
<source>Show graphs</source>
<translation>Zobrazovat grafy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="333"/>
<location filename="../src/gui.cpp" line="339"/>
<source>Show grid</source>
<translation>Zobrazit mřížku</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="339"/>
<location filename="../src/gui.cpp" line="345"/>
<source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="345"/>
<location filename="../src/gui.cpp" line="351"/>
<source>Metric</source>
<translation>Metrické</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="350"/>
<location filename="../src/gui.cpp" line="356"/>
<source>Imperial</source>
<translation>Imperiální</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="356"/>
<location filename="../src/gui.cpp" line="362"/>
<source>Fullscreen mode</source>
<translation>Celoobrazovkový režim</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="364"/>
<location filename="../src/gui.cpp" line="370"/>
<source>Next</source>
<translation>Následující</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="367"/>
<location filename="../src/gui.cpp" line="373"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="371"/>
<location filename="../src/gui.cpp" line="377"/>
<source>Last</source>
<translation>Poslední</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="374"/>
<location filename="../src/gui.cpp" line="380"/>
<source>First</source>
<translation>První</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="396"/>
<location filename="../src/gui.cpp" line="402"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="403"/>
<location filename="../src/gui.cpp" line="409"/>
<source>Graph</source>
<translation>Graf</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="411"/>
<location filename="../src/gui.cpp" line="417"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="412"/>
<location filename="../src/gui.cpp" line="418"/>
<source>POI files</source>
<translation>POI soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="423"/>
<location filename="../src/gui.cpp" line="429"/>
<source>Data</source>
<translation>Data</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="424"/>
<location filename="../src/gui.cpp" line="430"/>
<source>Display</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="432"/>
<location filename="../src/gui.cpp" line="438"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="433"/>
<location filename="../src/gui.cpp" line="439"/>
<source>Units</source>
<translation>Jednotky</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="441"/>
<location filename="../src/gui.cpp" line="447"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="557"/>
<location filename="../src/gui.cpp" line="566"/>
<source>Previous map</source>
<translation>Předchozí mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="674"/>
<location filename="../src/gui.cpp" line="604"/>
<location filename="../src/gui.cpp" line="685"/>
<source>GPX files (*.gpx)</source>
<translation>Soubory GPX (*.gpx)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="674"/>
<location filename="../src/gui.cpp" line="604"/>
<location filename="../src/gui.cpp" line="686"/>
<source>TCX files (*.tcx)</source>
<translation>Soubory TCX (*.tcx)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="671"/>
<source>Error loading data file:
%1</source>
<translation>Datový soubor nelze otevřít:
%1 </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="605"/>
<location filename="../src/gui.cpp" line="685"/>
<source>CSV files (*.csv)</source>
<translation>Soubory CSV (*.csv)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="675"/>
<location filename="../src/gui.cpp" line="605"/>
<location filename="../src/gui.cpp" line="686"/>
<source>All files (*)</source>
<translation>Všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="761"/>
<location filename="../src/gui.cpp" line="764"/>
<location filename="../src/gui.cpp" line="772"/>
<location filename="../src/gui.cpp" line="775"/>
<source>Date</source>
<translation>Datum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="773"/>
<location filename="../src/gui.cpp" line="784"/>
<source>Routes</source>
<translation>Trasy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="961"/>
<location filename="../src/gui.cpp" line="972"/>
<source>No GPX files loaded</source>
<translation>Nejsou načteny žádné GPX soubory</translation>
</message>
<message numerus="yes">
<location filename="../src/gui.cpp" line="965"/>
<location filename="../src/gui.cpp" line="976"/>
<source>%1 files</source>
<translation>
<numerusform>%1 soubor</numerusform>
@ -407,139 +419,128 @@
</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="548"/>
<location filename="../src/gui.cpp" line="557"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="525"/>
<location filename="../src/gui.cpp" line="534"/>
<source>Version </source>
<translation>Verze </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="214"/>
<location filename="../src/gui.cpp" line="220"/>
<source>Print...</source>
<translation>Tisknout...</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="219"/>
<location filename="../src/gui.cpp" line="225"/>
<source>Export to PDF...</source>
<translation>Exportovat do PDF...</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="673"/>
<source>All POI files (*.gpx *.csv)</source>
<translation>Všechny POI soubory (*.gpx *.csv)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="775"/>
<location filename="../src/gui.cpp" line="786"/>
<source>Waypoints</source>
<translation>Navigační body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="549"/>
<location filename="../src/gui.cpp" line="558"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="304"/>
<location filename="../src/gui.cpp" line="310"/>
<source>Route waypoints</source>
<translation>Body tras</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="551"/>
<location filename="../src/gui.cpp" line="560"/>
<source>First file</source>
<translation>První soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="552"/>
<location filename="../src/gui.cpp" line="561"/>
<source>Last file</source>
<translation>Poslední soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="553"/>
<location filename="../src/gui.cpp" line="562"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="572"/>
<location filename="../src/gui.cpp" line="581"/>
<source>Map (tiles) source URLs are read on program startup from the following file:</source>
<translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="575"/>
<location filename="../src/gui.cpp" line="584"/>
<source>The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like:</source>
<translation>Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="583"/>
<location filename="../src/gui.cpp" line="592"/>
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source>
<translation>POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="594"/>
<source>GPX files (*.gpx);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation>
<location filename="../src/gui.cpp" line="603"/>
<location filename="../src/gui.cpp" line="684"/>
<source>All supported files (*.gpx *.tcx *.csv)</source>
<translation>Všechny podporované soubory (*.gpx *.tcx *.csv)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="663"/>
<location filename="../src/gui.cpp" line="692"/>
<location filename="../src/gui.cpp" line="674"/>
<location filename="../src/gui.cpp" line="703"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="771"/>
<location filename="../src/gui.cpp" line="782"/>
<source>Tracks</source>
<translation>Cesty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="204"/>
<location filename="../src/gui.cpp" line="523"/>
<location filename="../src/gui.cpp" line="210"/>
<location filename="../src/gui.cpp" line="532"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="465"/>
<location filename="../src/gui.cpp" line="471"/>
<source>Navigation</source>
<translation>Navigace</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="571"/>
<location filename="../src/gui.cpp" line="580"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="582"/>
<location filename="../src/gui.cpp" line="591"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="319"/>
<location filename="../src/gui.cpp" line="778"/>
<location filename="../src/gui.cpp" line="325"/>
<location filename="../src/gui.cpp" line="789"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="326"/>
<location filename="../src/gui.cpp" line="780"/>
<location filename="../src/gui.cpp" line="332"/>
<location filename="../src/gui.cpp" line="791"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="665"/>
<location filename="../src/gui.cpp" line="693"/>
<location filename="../src/gui.cpp" line="676"/>
<location filename="../src/gui.cpp" line="704"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="660"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="689"/>
<location filename="../src/gui.cpp" line="700"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:

48
src/csvparser.cpp Normal file
View File

@ -0,0 +1,48 @@
#include "csvparser.h"
bool CSVParser::loadFile(QIODevice *device)
{
bool ret;
int ln = 1;
_errorLine = 0;
_errorString.clear();
while (!device->atEnd()) {
QByteArray line = device->readLine();
QList<QByteArray> list = line.split(',');
if (list.size() < 3) {
_errorString = "Parse error.";
_errorLine = ln;
return false;
}
qreal lat = list[0].trimmed().toDouble(&ret);
if (!ret) {
_errorString = "Invalid latitude.";
_errorLine = ln;
return false;
}
qreal lon = list[1].trimmed().toDouble(&ret);
if (!ret) {
_errorString = "Invalid longitude.";
_errorLine = ln;
return false;
}
Waypoint wp(QPointF(lon, lat));
QByteArray ba = list[2].trimmed();
QString name = QString::fromUtf8(ba.data(), ba.size());
wp.setName(name);
if (list.size() > 3) {
ba = list[3].trimmed();
wp.setDescription(QString::fromUtf8(ba.data(), ba.size()));
}
_waypoints.append(wp);
ln++;
}
return true;
}

24
src/csvparser.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef CSVPARSER_H
#define CSVPARSER_H
#include "parser.h"
class CSVParser : public Parser
{
public:
CSVParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {_errorLine = 0;}
~CSVParser() {}
bool loadFile(QIODevice *device);
QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
const char *name() const {return "CSV";}
private:
QString _errorString;
int _errorLine;
};
#endif // CSVPARSER_H

62
src/data.cpp Normal file
View File

@ -0,0 +1,62 @@
#include <QFile>
#include <QLineF>
#include "ll.h"
#include "gpxparser.h"
#include "tcxparser.h"
#include "csvparser.h"
#include "data.h"
Data::Data() : _errorLine(0)
{
_parsers << new GPXParser(_track_data, _route_data, _waypoint_data);
_parsers << new TCXParser(_track_data, _route_data, _waypoint_data);
_parsers << new CSVParser(_track_data, _route_data, _waypoint_data);
}
Data::~Data()
{
for(int i = 0; i < _parsers.count(); i++)
delete _parsers.at(i);
for (int i = 0; i < _tracks.count(); i++)
delete _tracks.at(i);
for (int i = 0; i < _routes.count(); i++)
delete _routes.at(i);
}
bool Data::loadFile(const QString &fileName)
{
QFile file(fileName);
_errorString.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_errorString = qPrintable(file.errorString());
return false;
}
for (int i = 0; i < _parsers.size(); i++) {
if (_parsers.at(i)->loadFile(&file)) {
for (int i = 0; i < _track_data.count(); i++)
_tracks.append(new Track(_track_data.at(i)));
for (int i = 0; i < _route_data.count(); i++)
_routes.append(new Route(_route_data.at(i)));
return true;
}
file.reset();
}
fprintf(stderr, "Error loading data file: %s:\n", qPrintable(fileName));
for (int i = 0; i < _parsers.size(); i++) {
fprintf(stderr, "%s: line %d: %s\n", _parsers.at(i)->name(),
_parsers.at(i)->errorLine(), qPrintable(_parsers.at(i)->errorString()));
if (_parsers.at(i)->errorLine() > _errorLine) {
_errorLine = _parsers.at(i)->errorLine();
_errorString = _parsers.at(i)->errorString();
}
}
return false;
}

View File

@ -1,5 +1,5 @@
#ifndef GPX_H
#define GPX_H
#ifndef DATA_H
#define DATA_H
#include <QVector>
#include <QList>
@ -8,16 +8,17 @@
#include "waypoint.h"
#include "track.h"
#include "route.h"
#include "parser.h"
class GPX
class Parser;
class Data
{
public:
GPX();
~GPX();
Data();
~Data();
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
const QString &errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
const QList<Track*> &tracks() const {return _tracks;}
@ -25,9 +26,9 @@ public:
const QList<Waypoint> &waypoints() const {return _waypoint_data;}
private:
Parser _parser;
QString _error;
QString _errorString;
int _errorLine;
QList<Parser*> _parsers;
QList<Track*> _tracks;
QList<Route*> _routes;
@ -37,4 +38,4 @@ private:
QList<Waypoint> _waypoint_data;
};
#endif // GPX_H
#endif // DATA_H

View File

@ -1,6 +1,6 @@
#include <cmath>
#include "config.h"
#include "gpx.h"
#include "data.h"
#include "elevationgraph.h"
@ -107,14 +107,14 @@ void ElevationGraph::loadGraph(const Graph &graph, Type type, PathItem *path)
GraphView::loadGraph(graph, path, type);
}
void ElevationGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
void ElevationGraph::loadData(const Data &data, const QList<PathItem *> &paths)
{
int p = 0;
for (int i = 0; i < gpx.tracks().count(); i++)
loadGraph(gpx.tracks().at(i)->elevation(), Track, paths.at(p++));
for (int i = 0; i < gpx.routes().count(); i++)
loadGraph(gpx.routes().at(i)->elevation(), Route, paths.at(p++));
for (int i = 0; i < data.tracks().count(); i++)
loadGraph(data.tracks().at(i)->elevation(), Track, paths.at(p++));
for (int i = 0; i < data.routes().count(); i++)
loadGraph(data.routes().at(i)->elevation(), Route, paths.at(p++));
setInfo();

View File

@ -11,7 +11,7 @@ public:
ElevationGraph(QWidget *parent = 0);
QString label() const {return tr("Elevation");}
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void loadData(const Data &data, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);

View File

@ -1,47 +0,0 @@
#include <QFile>
#include <QLineF>
#include "ll.h"
#include "gpx.h"
GPX::GPX() : _parser(_track_data, _route_data, _waypoint_data), _errorLine(0)
{
}
GPX::~GPX()
{
for (int i = 0; i < _tracks.count(); i++)
delete _tracks.at(i);
for (int i = 0; i < _routes.count(); i++)
delete _routes.at(i);
}
bool GPX::loadFile(const QString &fileName)
{
bool ret;
QFile file(fileName);
_error.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
return false;
}
ret = _parser.loadFile(&file);
file.close();
if (ret == false) {
_error = _parser.errorString();
_errorLine = _parser.errorLine();
return false;
}
for (int i = 0; i < _track_data.count(); i++)
_tracks.append(new Track(_track_data.at(i)));
for (int i = 0; i < _route_data.count(); i++)
_routes.append(new Route(_route_data.at(i)));
return true;
}

View File

@ -1,18 +1,18 @@
#include "parser.h"
#include "gpxparser.h"
void Parser::handleTrackpointData(DataType type, const QString &value)
void GPXParser::handleTrackpointData(DataType type, const QString &value)
{
switch (type) {
case Elevation:
_track->last().setElevation(value.toLatin1().toDouble());
_track->last().setElevation(value.toDouble());
break;
case Time:
_track->last().setTimestamp(QDateTime::fromString(value.toLatin1(),
_track->last().setTimestamp(QDateTime::fromString(value,
Qt::ISODate));
break;
case Geoidheight:
_track->last().setGeoidHeight(value.toLatin1().toDouble());
_track->last().setGeoidHeight(value.toDouble());
break;
case Speed:
_track->last().setSpeed(value.toDouble());
@ -28,7 +28,7 @@ void Parser::handleTrackpointData(DataType type, const QString &value)
}
}
void Parser::handleWaypointData(DataType type, const QString &value)
void GPXParser::handleWaypointData(DataType type, const QString &value)
{
switch (type) {
case Name:
@ -37,22 +37,22 @@ void Parser::handleWaypointData(DataType type, const QString &value)
case Description:
_waypoints.last().setDescription(value);
break;
case Time:
_waypoints.last().setTimestamp(QDateTime::fromString(
value.toLatin1(), Qt::ISODate));
break;
case Elevation:
_waypoints.last().setElevation(value.toLatin1().toDouble());
break;
case Geoidheight:
_waypoints.last().setGeoidHeight(value.toLatin1().toDouble());
break;
case Time:
_waypoints.last().setTimestamp(QDateTime::fromString(value,
Qt::ISODate));
break;
case Elevation:
_waypoints.last().setElevation(value.toDouble());
break;
case Geoidheight:
_waypoints.last().setGeoidHeight(value.toDouble());
break;
default:
break;
}
}
void Parser::handleRoutepointData(DataType type, const QString &value)
void GPXParser::handleRoutepointData(DataType type, const QString &value)
{
switch (type) {
case Name:
@ -62,42 +62,42 @@ void Parser::handleRoutepointData(DataType type, const QString &value)
_route->last().setDescription(value);
break;
case Time:
_route->last().setTimestamp(QDateTime::fromString(
value.toLatin1(), Qt::ISODate));
_route->last().setTimestamp(QDateTime::fromString(value,
Qt::ISODate));
break;
case Elevation:
_route->last().setElevation(value.toLatin1().toDouble());
_route->last().setElevation(value.toDouble());
break;
case Geoidheight:
_route->last().setGeoidHeight(value.toLatin1().toDouble());
_route->last().setGeoidHeight(value.toDouble());
break;
default:
break;
}
}
void Parser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
void GPXParser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
{
_track->last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
attr.value("lon").toDouble(),
attr.value("lat").toDouble()));
}
void Parser::handleRoutepointAttributes(const QXmlStreamAttributes &attr)
void GPXParser::handleRoutepointAttributes(const QXmlStreamAttributes &attr)
{
_route->last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
attr.value("lon").toDouble(),
attr.value("lat").toDouble()));
}
void Parser::handleWaypointAttributes(const QXmlStreamAttributes &attr)
void GPXParser::handleWaypointAttributes(const QXmlStreamAttributes &attr)
{
_waypoints.last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
attr.value("lon").toDouble(),
attr.value("lat").toDouble()));
}
void Parser::tpExtension()
void GPXParser::tpExtension()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "hr")
@ -109,7 +109,7 @@ void Parser::tpExtension()
}
}
void Parser::extensions()
void GPXParser::extensions()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "speed")
@ -125,7 +125,7 @@ void Parser::extensions()
}
}
void Parser::trackpointData()
void GPXParser::trackpointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "ele")
@ -141,7 +141,7 @@ void Parser::trackpointData()
}
}
void Parser::routepointData()
void GPXParser::routepointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
@ -159,41 +159,7 @@ void Parser::routepointData()
}
}
void Parser::trackpoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") {
_track->append(Trackpoint());
handleTrackpointAttributes(_reader.attributes());
trackpointData();
} else
_reader.skipCurrentElement();
}
}
void Parser::routepoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") {
_route->append(Waypoint());
handleRoutepointAttributes(_reader.attributes());
routepointData();
} else
_reader.skipCurrentElement();
}
}
void Parser::track()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkseg") {
trackpoints();
} else
_reader.skipCurrentElement();
}
}
void Parser::waypointData()
void GPXParser::waypointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
@ -211,7 +177,41 @@ void Parser::waypointData()
}
}
void Parser::gpx()
void GPXParser::trackpoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") {
_track->append(Trackpoint());
handleTrackpointAttributes(_reader.attributes());
trackpointData();
} else
_reader.skipCurrentElement();
}
}
void GPXParser::routepoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") {
_route->append(Waypoint());
handleRoutepointAttributes(_reader.attributes());
routepointData();
} else
_reader.skipCurrentElement();
}
}
void GPXParser::track()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkseg") {
trackpoints();
} else
_reader.skipCurrentElement();
}
}
void GPXParser::gpx()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trk") {
@ -231,7 +231,7 @@ void Parser::gpx()
}
}
bool Parser::parse()
bool GPXParser::parse()
{
if (_reader.readNextStartElement()) {
if (_reader.name() == "gpx")
@ -243,7 +243,7 @@ bool Parser::parse()
return !_reader.error();
}
bool Parser::loadFile(QIODevice *device)
bool GPXParser::loadFile(QIODevice *device)
{
_reader.clear();
_reader.setDevice(device);

51
src/gpxparser.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef GPXPARSER_H
#define GPXPARSER_H
#include <QXmlStreamReader>
#include <QVector>
#include "parser.h"
class GPXParser : public Parser
{
public:
GPXParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {_track = 0; _route = 0;}
~GPXParser() {}
bool loadFile(QIODevice *device);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
const char *name() const {return "GPX";}
private:
enum DataType {
Name, Description, Elevation, Time, Geoidheight, Speed, HeartRate,
Temperature
};
bool parse();
void gpx();
void track();
void trackpoints();
void routepoints();
void tpExtension();
void extensions();
void trackpointData();
void routepointData();
void waypointData();
void handleWaypointAttributes(const QXmlStreamAttributes &attr);
void handleWaypointData(DataType type, const QString &value);
void handleTrackpointAttributes(const QXmlStreamAttributes &attr);
void handleTrackpointData(DataType type, const QString &value);
void handleRoutepointAttributes(const QXmlStreamAttributes &attr);
void handleRoutepointData(DataType type, const QString &value);
QXmlStreamReader _reader;
QVector<Trackpoint> *_track;
QVector<Waypoint> *_route;
};
#endif // GPXPARSER_H

View File

@ -5,7 +5,7 @@
#include "graphview.h"
#include "units.h"
class GPX;
class Data;
class PathItem;
class GraphTab : public GraphView
@ -17,7 +17,7 @@ public:
{setFrameShape(QFrame::NoFrame);}
virtual QString label() const = 0;
virtual void loadGPX(const GPX &gpx, const QList<PathItem *> &paths) = 0;
virtual void loadData(const Data &data, const QList<PathItem *> &paths) = 0;
virtual void clear() = 0;
virtual void setUnits(enum Units units) = 0;
virtual void showTracks(bool show) = 0;

View File

@ -26,7 +26,7 @@
#include "icons.h"
#include "keys.h"
#include "settings.h"
#include "gpx.h"
#include "data.h"
#include "map.h"
#include "maplist.h"
#include "elevationgraph.h"
@ -55,8 +55,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
createMenus();
createToolBars();
_browser = new FileBrowser(this);
_browser->setFilter(QStringList("*.gpx"));
createBrowser();
QSplitter *splitter = new QSplitter();
splitter->setOrientation(Qt::Vertical);
@ -105,6 +104,14 @@ GUI::~GUI()
}
}
void GUI::createBrowser()
{
QStringList filter;
filter << "*.gpx" << "*.tcx" << "*.csv";
_browser = new FileBrowser(this);
_browser->setFilter(filter);
}
void GUI::loadMaps()
{
if (QFile::exists(USER_MAP_FILE))
@ -593,7 +600,9 @@ void GUI::dataSources()
void GUI::openFile()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"),
QString(), tr("GPX files (*.gpx);;All files (*)"));
QString(), tr("All supported files (*.gpx *.tcx *.csv)") + ";;"
+ tr("GPX files (*.gpx)") + ";;" + tr("TCX files (*.tcx)") + ";;"
+ tr("CSV files (*.csv)") + ";;" + tr("All files (*)"));
QStringList list = files;
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
@ -629,40 +638,40 @@ bool GUI::openFile(const QString &fileName)
bool GUI::loadFile(const QString &fileName)
{
GPX gpx;
Data data;
QList<PathItem*> paths;
if (gpx.loadFile(fileName)) {
paths = _pathView->loadGPX(gpx);
if (data.loadFile(fileName)) {
paths = _pathView->loadData(data);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->loadGPX(gpx, paths);
_tabs.at(i)->loadData(data, paths);
updateGraphTabs();
_pathView->setHidden(false);
for (int i = 0; i < gpx.tracks().count(); i++) {
_trackDistance += gpx.tracks().at(i)->distance();
_time += gpx.tracks().at(i)->time();
const QDate &date = gpx.tracks().at(i)->date().date();
for (int i = 0; i < data.tracks().count(); i++) {
_trackDistance += data.tracks().at(i)->distance();
_time += data.tracks().at(i)->time();
const QDate &date = data.tracks().at(i)->date().date();
if (_dateRange.first.isNull() || _dateRange.first > date)
_dateRange.first = date;
if (_dateRange.second.isNull() || _dateRange.second < date)
_dateRange.second = date;
}
_trackCount += gpx.tracks().count();
_trackCount += data.tracks().count();
for (int i = 0; i < gpx.routes().count(); i++)
_routeDistance += gpx.routes().at(i)->distance();
_routeCount += gpx.routes().count();
for (int i = 0; i < data.routes().count(); i++)
_routeDistance += data.routes().at(i)->distance();
_routeCount += data.routes().count();
_waypointCount += gpx.waypoints().count();
_waypointCount += data.waypoints().count();
return true;
} else {
QString error = fileName + QString("\n\n")
+ tr("Error loading GPX file:\n%1").arg(gpx.errorString())
+ tr("Error loading data file:\n%1").arg(data.errorString())
+ QString("\n");
if (gpx.errorLine())
error.append(tr("Line: %1").arg(gpx.errorLine()));
if (data.errorLine())
error.append(tr("Line: %1").arg(data.errorLine()));
QMessageBox::critical(this, tr("Error"), error);
return false;
@ -672,9 +681,9 @@ bool GUI::loadFile(const QString &fileName)
void GUI::openPOIFile()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open POI file"),
QString(), tr("All POI files (*.gpx *.csv)") + ";;"
QString(), tr("All supported files (*.gpx *.tcx *.csv)") + ";;"
+ tr("GPX files (*.gpx)") + ";;" + tr("CSV files (*.csv)") + ";;"
+ tr("All files (*)"));
+ tr("TCX files (*.tcx)") + ";;" + tr("All files (*)"));
QStringList list = files;
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)

View File

@ -89,6 +89,7 @@ private:
void createStatusBar();
void createPathView();
void createGraphTabs();
void createBrowser();
bool openPOIFile(const QString &fileName);
bool loadFile(const QString &fileName);

View File

@ -1,4 +1,4 @@
#include "gpx.h"
#include "data.h"
#include "heartrategraph.h"
@ -24,10 +24,10 @@ void HeartRateGraph::setInfo()
clearInfo();
}
void HeartRateGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
void HeartRateGraph::loadData(const Data &data, const QList<PathItem *> &paths)
{
for (int i = 0; i < gpx.tracks().count(); i++) {
const Graph &graph = gpx.tracks().at(i)->heartRate();
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->heartRate();
qreal sum = 0, w = 0;
if (graph.size() < 2) {
@ -40,12 +40,12 @@ void HeartRateGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
sum += graph.at(j).y() * ds;
w += ds;
}
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
GraphView::loadGraph(graph, paths.at(i));
}
for (int i = 0; i < gpx.routes().count(); i++)
for (int i = 0; i < data.routes().count(); i++)
skipColor();
setInfo();

View File

@ -11,7 +11,7 @@ public:
HeartRateGraph(QWidget *parent = 0);
QString label() const {return tr("Heart rate");}
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void loadData(const Data &data, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units) {}
void showTracks(bool show);

View File

@ -1,55 +1,30 @@
#ifndef PARSER_H
#define PARSER_H
#include <QXmlStreamReader>
#include <QVector>
#include <QString>
#include <QList>
#include "trackpoint.h"
#include "waypoint.h"
class QIODevice;
class Parser
{
public:
Parser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: _tracks(tracks), _routes(routes), _waypoints(waypoints)
{_track = 0; _route = 0;}
: _tracks(tracks), _routes(routes), _waypoints(waypoints) {}
virtual ~Parser() {}
bool loadFile(QIODevice *device);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
virtual bool loadFile(QIODevice *device) = 0;
virtual QString errorString() const = 0;
virtual int errorLine() const = 0;
virtual const char *name() const = 0;
private:
enum DataType {
Name, Description, Elevation, Time, Geoidheight, Speed, HeartRate,
Temperature
};
bool parse();
void gpx();
void track();
void trackpoints();
void routepoints();
void tpExtension();
void extensions();
void trackpointData();
void routepointData();
void waypointData();
void handleWaypointAttributes(const QXmlStreamAttributes &attr);
void handleWaypointData(DataType type, const QString &value);
void handleTrackpointAttributes(const QXmlStreamAttributes &attr);
void handleTrackpointData(DataType type, const QString &value);
void handleRoutepointAttributes(const QXmlStreamAttributes &attr);
void handleRoutepointData(DataType type, const QString &value);
QXmlStreamReader _reader;
protected:
QList<QVector<Trackpoint> > &_tracks;
QList<QVector<Waypoint> > &_routes;
QList<Waypoint> &_waypoints;
QVector<Trackpoint> *_track;
QVector<Waypoint> *_route;
};
#endif // PARSER_H

View File

@ -3,7 +3,7 @@
#include <QWheelEvent>
#include "ll.h"
#include "poi.h"
#include "gpx.h"
#include "data.h"
#include "map.h"
#include "trackitem.h"
#include "routeitem.h"
@ -124,17 +124,17 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
_scale = mapScale(_zoom);
}
QList<PathItem *> PathView::loadGPX(const GPX &gpx)
QList<PathItem *> PathView::loadData(const Data &data)
{
QList<PathItem *> paths;
int zoom = _zoom;
for (int i = 0; i < gpx.tracks().count(); i++)
paths.append(addTrack(*(gpx.tracks().at(i))));
for (int i = 0; i < gpx.routes().count(); i++)
paths.append(addRoute(*(gpx.routes().at(i))));
addWaypoints(gpx.waypoints());
for (int i = 0; i < data.tracks().count(); i++)
paths.append(addTrack(*(data.tracks().at(i))));
for (int i = 0; i < data.routes().count(); i++)
paths.append(addRoute(*(data.routes().at(i))));
addWaypoints(data.waypoints());
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
return paths;

View File

@ -9,7 +9,7 @@
#include "palette.h"
#include "waypoint.h"
class GPX;
class Data;
class POI;
class Map;
class Track;
@ -28,7 +28,7 @@ public:
PathView(QWidget *parent = 0);
~PathView();
QList<PathItem*> loadGPX(const GPX &gpx);
QList<PathItem*> loadData(const Data &data);
void setPOI(POI *poi);
void setMap(Map *map);

View File

@ -4,7 +4,7 @@
#include "pathitem.h"
#include "waypointitem.h"
#include "ll.h"
#include "gpx.h"
#include "data.h"
#include "poi.h"
@ -16,119 +16,23 @@ POI::POI(QObject *parent) : QObject(parent)
bool POI::loadFile(const QString &fileName)
{
QString error;
int errorLine;
Data data;
FileIndex index;
_error.clear();
_errorString.clear();
_errorLine = 0;
if (loadCSVFile(fileName)) {
emit pointsChanged();
return true;
} else {
error = _error;
errorLine = _errorLine;
}
if (loadGPXFile(fileName)) {
emit pointsChanged();
return true;
}
fprintf(stderr, "Error loading POI file: %s:\n", qPrintable(fileName));
fprintf(stderr, "CSV: line %d: %s\n", errorLine, qPrintable(error));
fprintf(stderr, "GPX: line %d: %s\n", _errorLine, qPrintable(_error));
if (errorLine > _errorLine) {
_errorLine = errorLine;
_error = error;
}
return false;
}
bool POI::loadGPXFile(const QString &fileName)
{
GPX gpx;
FileIndex index;
index.enabled = true;
index.start = _data.size();
if (gpx.loadFile(fileName)) {
for (int i = 0; i < gpx.waypoints().size(); i++)
_data.append(gpx.waypoints().at(i));
index.end = _data.size() - 1;
for (int i = index.start; i <= index.end; i++) {
const QPointF &p = _data.at(i).coordinates();
qreal c[2];
c[0] = p.x();
c[1] = p.y();
_tree.Insert(c, c, i);
}
_files.append(fileName);
_indexes.append(index);
return true;
} else {
_error = gpx.errorString();
_errorLine = gpx.errorLine();
}
return false;
}
bool POI::loadCSVFile(const QString &fileName)
{
QFile file(fileName);
FileIndex index;
bool ret;
int ln = 1;
index.enabled = true;
index.start = _data.size();
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
if (!data.loadFile(fileName)) {
_errorString = data.errorString();
_errorLine = data.errorLine();
return false;
}
while (!file.atEnd()) {
QByteArray line = file.readLine();
QList<QByteArray> list = line.split(',');
if (list.size() < 3) {
_error = "Parse error.";
_errorLine = ln;
return false;
}
qreal lat = list[0].trimmed().toDouble(&ret);
if (!ret) {
_error = "Invalid latitude.";
_errorLine = ln;
return false;
}
qreal lon = list[1].trimmed().toDouble(&ret);
if (!ret) {
_error = "Invalid longitude.";
_errorLine = ln;
return false;
}
Waypoint wp(QPointF(lon, lat));
QByteArray ba = list[2].trimmed();
QString name = QString::fromUtf8(ba.data(), ba.size());
wp.setName(name);
if (list.size() > 3) {
ba = list[3].trimmed();
wp.setDescription(QString::fromUtf8(ba.data(), ba.size()));
}
_data.append(wp);
ln++;
}
for (int i = 0; i < data.waypoints().size(); i++)
_data.append(data.waypoints().at(i));
index.end = _data.size() - 1;
for (int i = index.start; i <= index.end; i++) {
@ -142,6 +46,8 @@ bool POI::loadCSVFile(const QString &fileName)
_files.append(fileName);
_indexes.append(index);
emit pointsChanged();
return true;
}

View File

@ -19,7 +19,7 @@ public:
POI(QObject *parent = 0);
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
const QString &errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
qreal radius() const {return _radius;}
@ -44,9 +44,6 @@ private:
bool enabled;
} FileIndex;
bool loadCSVFile(const QString &fileName);
bool loadGPXFile(const QString &fileName);
POITree _tree;
QVector<Waypoint> _data;
QStringList _files;
@ -54,7 +51,7 @@ private:
qreal _radius;
QString _error;
QString _errorString;
int _errorLine;
};

View File

@ -1,5 +1,5 @@
#include "config.h"
#include "gpx.h"
#include "data.h"
#include "speedgraph.h"
@ -25,22 +25,22 @@ void SpeedGraph::setInfo()
clearInfo();
}
void SpeedGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
void SpeedGraph::loadData(const Data &data, const QList<PathItem *> &paths)
{
for (int i = 0; i < gpx.tracks().count(); i++) {
const Graph &graph = gpx.tracks().at(i)->speed();
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->speed();
if (graph.size() < 2) {
skipColor();
continue;
}
_avg.append(QPointF(gpx.tracks().at(i)->distance(),
gpx.tracks().at(i)->distance() / gpx.tracks().at(i)->time()));
_avg.append(QPointF(data.tracks().at(i)->distance(),
data.tracks().at(i)->distance() / data.tracks().at(i)->time()));
GraphView::loadGraph(graph, paths.at(i));
}
for (int i = 0; i < gpx.routes().count(); i++)
for (int i = 0; i < data.routes().count(); i++)
skipColor();
setInfo();

View File

@ -12,7 +12,7 @@ public:
SpeedGraph(QWidget *parent = 0);
QString label() const {return tr("Speed");}
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void loadData(const Data &data, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);

181
src/tcxparser.cpp Normal file
View File

@ -0,0 +1,181 @@
#include "tcxparser.h"
QPointF TCXParser::position()
{
QPointF pos;
while (_reader.readNextStartElement()) {
if (_reader.name() == "LatitudeDegrees")
pos.setY(_reader.readElementText().toDouble());
else if (_reader.name() == "LongitudeDegrees")
pos.setX(_reader.readElementText().toDouble());
else
_reader.skipCurrentElement();
}
return pos;
}
void TCXParser::trackpointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Position")
_track->last().setCoordinates(position());
else if (_reader.name() == "AltitudeMeters")
_track->last().setElevation(_reader.readElementText().toDouble());
else if (_reader.name() == "Time")
_track->last().setTimestamp(QDateTime::fromString(
_reader.readElementText(), Qt::ISODate));
else if (_reader.name() == "HeartRateBpm")
_track->last().setHeartRate(_reader.readElementText().toDouble());
else
_reader.skipCurrentElement();
}
}
void TCXParser::routepointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Position")
_route->last().setCoordinates(position());
else if (_reader.name() == "AltitudeMeters")
_route->last().setElevation(_reader.readElementText().toDouble());
else if (_reader.name() == "Time")
_route->last().setTimestamp(QDateTime::fromString(
_reader.readElementText(), Qt::ISODate));
else
_reader.skipCurrentElement();
}
}
void TCXParser::waypointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Position")
_waypoints.last().setCoordinates(position());
else if (_reader.name() == "Name")
_waypoints.last().setName(_reader.readElementText());
else if (_reader.name() == "Notes")
_waypoints.last().setDescription(_reader.readElementText());
else if (_reader.name() == "AltitudeMeters")
_waypoints.last().setElevation(
_reader.readElementText().toDouble());
else if (_reader.name() == "Time")
_waypoints.last().setTimestamp(QDateTime::fromString(
_reader.readElementText(), Qt::ISODate));
else
_reader.skipCurrentElement();
}
}
void TCXParser::trackpoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Trackpoint") {
_track->append(Trackpoint());
trackpointData();
} else
_reader.skipCurrentElement();
}
}
void TCXParser::routepoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Trackpoint") {
_route->append(Waypoint());
routepointData();
} else
_reader.skipCurrentElement();
}
}
void TCXParser::lap()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Track") {
_tracks.append(QVector<Trackpoint>());
_track = &_tracks.back();
trackpoints();
} else
_reader.skipCurrentElement();
}
}
void TCXParser::course()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Track") {
_routes.append(QVector<Waypoint>());
_route = &_routes.back();
routepoints();
} else if (_reader.name() == "CoursePoint") {
_waypoints.append(Waypoint());
waypointData();
} else
_reader.skipCurrentElement();
}
}
void TCXParser::activity()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Lap")
lap();
else
_reader.skipCurrentElement();
}
}
void TCXParser::courses()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Course")
course();
else
_reader.skipCurrentElement();
}
}
void TCXParser::activities()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Activity")
activity();
else
_reader.skipCurrentElement();
}
}
void TCXParser::tcx()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Courses")
courses();
else if (_reader.name() == "Activities")
activities();
else
_reader.skipCurrentElement();
}
}
bool TCXParser::parse()
{
if (_reader.readNextStartElement()) {
if (_reader.name() == "TrainingCenterDatabase")
tcx();
else
_reader.raiseError("Not a TCX file.");
}
return !_reader.error();
}
bool TCXParser::loadFile(QIODevice *device)
{
_reader.clear();
_reader.setDevice(device);
return parse();
}

42
src/tcxparser.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef TCXPARSER_H
#define TCXPARSER_H
#include <QXmlStreamReader>
#include <QVector>
#include "parser.h"
class TCXParser : public Parser
{
public:
TCXParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {_track = 0; _route = 0;}
~TCXParser() {}
bool loadFile(QIODevice *device);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
const char *name() const {return "TCX";}
private:
bool parse();
void tcx();
void courses();
void activities();
void course();
void activity();
void lap();
void trackpoints();
void routepoints();
void trackpointData();
void routepointData();
void waypointData();
QPointF position();
QXmlStreamReader _reader;
QVector<Trackpoint> *_track;
QVector<Waypoint> *_route;
};
#endif // TCXPARSER_H

View File

@ -1,4 +1,4 @@
#include "gpx.h"
#include "data.h"
#include "temperaturegraph.h"
@ -26,10 +26,10 @@ void TemperatureGraph::setInfo()
clearInfo();
}
void TemperatureGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
void TemperatureGraph::loadData(const Data &data, const QList<PathItem *> &paths)
{
for (int i = 0; i < gpx.tracks().count(); i++) {
const Graph &graph = gpx.tracks().at(i)->temperature();
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->temperature();
qreal sum = 0, w = 0;
if (graph.size() < 2) {
@ -42,12 +42,12 @@ void TemperatureGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
sum += graph.at(j).y() * ds;
w += ds;
}
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
GraphView::loadGraph(graph, paths.at(i));
}
for (int i = 0; i < gpx.routes().count(); i++)
for (int i = 0; i < data.routes().count(); i++)
skipColor();
setInfo();

View File

@ -11,7 +11,7 @@ public:
TemperatureGraph(QWidget *parent = 0);
QString label() const {return tr("Temperature");}
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void loadData(const Data &data, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);