1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +01:00

Added support for track/route names and descriptions

This commit is contained in:
Martin Tůma 2016-10-28 14:33:36 +02:00
parent 9a0d304e8d
commit 10b903c129
21 changed files with 182 additions and 97 deletions

View File

@ -60,7 +60,9 @@ HEADERS += src/config.h \
src/tile.h \
src/rd.h \
src/wgs84.h \
src/kmlparser.h
src/kmlparser.h \
src/trackdata.h \
src/routedata.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/poi.cpp \

View File

@ -6,9 +6,9 @@
class CSVParser : public Parser
{
public:
CSVParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {_errorLine = 0;}
CSVParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
{_errorLine = 0;}
~CSVParser() {}
bool loadFile(QIODevice *device);

View File

@ -10,14 +10,14 @@
Data::Data() : _errorLine(0)
{
_parsers.insert("gpx", new GPXParser(_track_data, _route_data,
_waypoint_data));
_parsers.insert("tcx", new TCXParser(_track_data, _route_data,
_waypoint_data));
_parsers.insert("kml", new KMLParser(_track_data, _route_data,
_waypoint_data));
_parsers.insert("csv", new CSVParser(_track_data, _route_data,
_waypoint_data));
_parsers.insert("gpx", new GPXParser(_trackData, _routeData,
_waypointData));
_parsers.insert("tcx", new TCXParser(_trackData, _routeData,
_waypointData));
_parsers.insert("kml", new KMLParser(_trackData, _routeData,
_waypointData));
_parsers.insert("csv", new CSVParser(_trackData, _routeData,
_waypointData));
}
Data::~Data()
@ -35,10 +35,10 @@ Data::~Data()
void Data::createData()
{
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)));
for (int i = 0; i < _trackData.count(); i++)
_tracks.append(new Track(_trackData.at(i)));
for (int i = 0; i < _routeData.count(); i++)
_routes.append(new Route(_routeData.at(i)));
}
bool Data::loadFile(const QString &fileName)

View File

@ -9,8 +9,8 @@
#include "waypoint.h"
#include "track.h"
#include "route.h"
#include "parser.h"
class Parser;
class Data
{
@ -24,7 +24,7 @@ public:
const QList<Track*> &tracks() const {return _tracks;}
const QList<Route*> &routes() const {return _routes;}
const QList<Waypoint> &waypoints() const {return _waypoint_data;}
const QList<Waypoint> &waypoints() const {return _waypointData;}
private:
void createData();
@ -36,9 +36,9 @@ private:
QList<Track*> _tracks;
QList<Route*> _routes;
QList<QVector<Trackpoint> > _track_data;
QList<QVector<Waypoint> > _route_data;
QList<Waypoint> _waypoint_data;
QList<TrackData> _trackData;
QList<RouteData> _routeData;
QList<Waypoint> _waypointData;
};
#endif // DATA_H

View File

@ -166,7 +166,7 @@ void GPXParser::waypointData(Waypoint &waypoint)
waypoint.setElevation(waypoint.elevation() - gh);
}
void GPXParser::trackpoints(QVector<Trackpoint> &track)
void GPXParser::trackpoints(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") {
@ -177,23 +177,31 @@ void GPXParser::trackpoints(QVector<Trackpoint> &track)
}
}
void GPXParser::routepoints(QVector<Waypoint> &route)
void GPXParser::routepoints(RouteData &route)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") {
route.append(Waypoint(coordinates()));
waypointData(route.last());
} else
} else if (_reader.name() == "name")
route.setName(_reader.readElementText());
else if (_reader.name() == "desc")
route.setDescription(_reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void GPXParser::track(QVector<Trackpoint> &track)
void GPXParser::track(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkseg") {
if (_reader.name() == "trkseg")
trackpoints(track);
} else
else if (_reader.name() == "name")
track.setName(_reader.readElementText());
else if (_reader.name() == "desc")
track.setDescription(_reader.readElementText());
else
_reader.skipCurrentElement();
}
}
@ -202,10 +210,10 @@ void GPXParser::gpx()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trk") {
_tracks.append(QVector<Trackpoint>());
_tracks.append(TrackData());
track(_tracks.back());
} else if (_reader.name() == "rte") {
_routes.append(QVector<Waypoint>());
_routes.append(RouteData());
routepoints(_routes.back());
} else if (_reader.name() == "wpt") {
_waypoints.append(Waypoint(coordinates()));

View File

@ -8,9 +8,8 @@
class GPXParser : public Parser
{
public:
GPXParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {}
GPXParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
~GPXParser() {}
bool loadFile(QIODevice *device);
@ -24,9 +23,9 @@ private:
bool parse();
void gpx();
void track(QVector<Trackpoint> &track);
void trackpoints(QVector<Trackpoint> &track);
void routepoints(QVector<Waypoint> &route);
void track(TrackData &track);
void trackpoints(TrackData &track);
void routepoints(RouteData &route);
void tpExtension(Trackpoint &trackpoint);
void extensions(Trackpoint &trackpoint);
void trackpointData(Trackpoint &trackpoint);

View File

@ -79,7 +79,7 @@ bool KMLParser::pointCoordinates(Waypoint &waypoint)
return true;
}
bool KMLParser::lineCoordinates(QVector<Trackpoint> &track)
bool KMLParser::lineCoordinates(TrackData &track)
{
QString data = _reader.readElementText();
const QChar *sp, *ep, *cp, *vp;
@ -136,17 +136,21 @@ bool KMLParser::lineCoordinates(QVector<Trackpoint> &track)
return true;
}
void KMLParser::timeStamp(Waypoint &waypoint)
QDateTime KMLParser::timeStamp()
{
QDateTime ts;
while (_reader.readNextStartElement()) {
if (_reader.name() == "when")
waypoint.setTimestamp(time());
ts = time();
else
_reader.skipCurrentElement();
}
return ts;
}
void KMLParser::lineString(QVector<Trackpoint> &track)
void KMLParser::lineString(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "coordinates") {
@ -170,21 +174,29 @@ void KMLParser::point(Waypoint &waypoint)
void KMLParser::placemark()
{
Waypoint waypoint;
QString name, desc;
QDateTime timestamp;
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
waypoint.setName(_reader.readElementText());
name = _reader.readElementText();
else if (_reader.name() == "description")
waypoint.setDescription(_reader.readElementText());
desc = _reader.readElementText();
else if (_reader.name() == "TimeStamp")
timeStamp(waypoint);
timestamp = timeStamp();
else if (_reader.name() == "Point") {
_waypoints.append(waypoint);
point(_waypoints.last());
_waypoints.append(Waypoint());
Waypoint &waypoint = _waypoints.last();
waypoint.setName(name);
waypoint.setDescription(desc);
waypoint.setTimestamp(timestamp);
point(waypoint);
} else if (_reader.name() == "LineString") {
_tracks.append(QVector<Trackpoint>());
lineString(_tracks.last());
_tracks.append(TrackData());
TrackData &track = _tracks.last();
track.setName(name);
track.setDescription(desc);
lineString(track);
} else
_reader.skipCurrentElement();
}

View File

@ -8,9 +8,8 @@
class KMLParser : public Parser
{
public:
KMLParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {}
KMLParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
~KMLParser() {}
bool loadFile(QIODevice *device);
@ -23,11 +22,11 @@ private:
void document();
void folder();
void placemark();
void lineString(QVector<Trackpoint> &track);
void lineString(TrackData &track);
void point(Waypoint &waypoint);
bool pointCoordinates(Waypoint &waypoint);
bool lineCoordinates(QVector<Trackpoint> &track);
void timeStamp(Waypoint &waypoint);
bool lineCoordinates(TrackData &track);
QDateTime timeStamp();
qreal number();
QDateTime time();

View File

@ -3,7 +3,8 @@
#include <QString>
#include <QList>
#include "trackpoint.h"
#include "trackdata.h"
#include "routedata.h"
#include "waypoint.h"
class QIODevice;
@ -11,9 +12,9 @@ class QIODevice;
class Parser
{
public:
Parser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: _tracks(tracks), _routes(routes), _waypoints(waypoints) {}
Parser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : _tracks(tracks), _routes(routes),
_waypoints(waypoints) {}
virtual ~Parser() {}
virtual bool loadFile(QIODevice *device) = 0;
@ -21,8 +22,8 @@ public:
virtual int errorLine() const = 0;
protected:
QList<QVector<Trackpoint> > &_tracks;
QList<QVector<Waypoint> > &_routes;
QList<TrackData> &_tracks;
QList<RouteData> &_routes;
QList<Waypoint> &_waypoints;
};

View File

@ -1,6 +1,6 @@
#include "route.h"
Route::Route(const QVector<Waypoint> &data) : _data(data)
Route::Route(const RouteData &data) : _data(data)
{
qreal dist = 0;

View File

@ -2,15 +2,15 @@
#define ROUTE_H
#include <QVector>
#include "waypoint.h"
#include "routedata.h"
#include "graph.h"
class Route
{
public:
Route(const QVector<Waypoint> &data);
Route(const RouteData &data);
const QVector<Waypoint> &route() const {return _data;}
const RouteData &route() const {return _data;}
Graph elevation() const;
qreal distance() const;
@ -18,7 +18,7 @@ public:
bool isNull() const {return (_data.count() < 2);}
private:
const QVector<Waypoint> &_data;
const RouteData &_data;
QVector<qreal> _distance;
};

21
src/routedata.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef ROUTEDATA_H
#define ROUTEDATA_H
#include <QVector>
#include <QString>
#include "waypoint.h"
class RouteData : public QVector<Waypoint>
{
public:
const QString& name() const {return _name;}
const QString& description() const {return _desc;}
void setName(const QString &name) {_name = name;}
void setDescription(const QString &desc) {_desc = desc;}
private:
QString _name;
QString _desc;
};
#endif // ROUTEDATA_H

View File

@ -11,6 +11,10 @@ QString RouteItem::toolTip()
{
ToolTip tt;
if (!_name.isEmpty())
tt.insert(qApp->translate("RouteItem", "Name"), _name);
if (!_desc.isEmpty())
tt.insert(qApp->translate("RouteItem", "Description"), _desc);
tt.insert(qApp->translate("RouteItem", "Distance"),
::distance(_distance, _units));
@ -20,10 +24,13 @@ QString RouteItem::toolTip()
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
: PathItem(parent)
{
QVector<Waypoint> r = route.route();
const RouteData &r = route.route();
Q_ASSERT(r.count() >= 2);
QPointF p;
_name = r.name();
_desc = r.description();
new WaypointItem(r.at(0), this);
p = r.at(0).coordinates().toMercator();
_path.moveTo(QPointF(p.x(), -p.y()));

View File

@ -20,6 +20,9 @@ public:
private:
QString toolTip();
QString _name;
QString _desc;
};
#endif // ROUTEITEM_H

View File

@ -83,7 +83,7 @@ void TCXParser::waypointData(Waypoint &waypoint)
}
}
void TCXParser::trackpoints(QVector<Trackpoint> &track)
void TCXParser::trackpoints(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Trackpoint") {
@ -94,24 +94,26 @@ void TCXParser::trackpoints(QVector<Trackpoint> &track)
}
}
void TCXParser::lap()
void TCXParser::lap(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Track") {
_tracks.append(QVector<Trackpoint>());
trackpoints(_tracks.back());
} else
if (_reader.name() == "Track")
trackpoints(track);
else
_reader.skipCurrentElement();
}
}
void TCXParser::course()
void TCXParser::course(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Track") {
_tracks.append(QVector<Trackpoint>());
trackpoints(_tracks.back());
} else if (_reader.name() == "CoursePoint") {
if (_reader.name() == "Track")
trackpoints(track);
else if (_reader.name() == "Name")
track.setName(_reader.readElementText());
else if (_reader.name() == "Notes")
track.setDescription(_reader.readElementText());
else if (_reader.name() == "CoursePoint") {
_waypoints.append(Waypoint());
waypointData(_waypoints.back());
} else
@ -119,11 +121,11 @@ void TCXParser::course()
}
}
void TCXParser::activity()
void TCXParser::activity(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Lap")
lap();
lap(track);
else
_reader.skipCurrentElement();
}
@ -132,9 +134,10 @@ void TCXParser::activity()
void TCXParser::courses()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Course")
course();
else
if (_reader.name() == "Course") {
_tracks.append(TrackData());
course(_tracks.back());
} else
_reader.skipCurrentElement();
}
}
@ -142,9 +145,10 @@ void TCXParser::courses()
void TCXParser::activities()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Activity")
activity();
else
if (_reader.name() == "Activity") {
_tracks.append(TrackData());
activity(_tracks.back());
} else
_reader.skipCurrentElement();
}
}

View File

@ -8,9 +8,8 @@
class TCXParser : public Parser
{
public:
TCXParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {}
TCXParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
~TCXParser() {}
bool loadFile(QIODevice *device);
@ -22,10 +21,10 @@ private:
void tcx();
void courses();
void activities();
void course();
void activity();
void lap();
void trackpoints(QVector<Trackpoint> &track);
void course(TrackData &track);
void activity(TrackData &track);
void lap(TrackData &track);
void trackpoints(TrackData &track);
void trackpointData(Trackpoint &trackpoint);
void waypointData(Waypoint &waypoint);
Coordinates position();

View File

@ -79,7 +79,7 @@ static QVector<GraphPoint> filter(const QVector<GraphPoint> &v, int window)
return ret;
}
Track::Track(const QVector<Trackpoint> &data) : _data(data)
Track::Track(const TrackData &data) : _data(data)
{
qreal dist = 0;

View File

@ -3,15 +3,16 @@
#include <QVector>
#include <QDateTime>
#include "trackpoint.h"
#include "trackdata.h"
#include "graph.h"
class Track
{
public:
Track(const QVector<Trackpoint> &data);
Track(const TrackData &data);
const QVector<Trackpoint> &track() const {return _data;}
const TrackData &track() const {return _data;}
Graph elevation() const;
Graph speed() const;
Graph heartRate() const;
@ -24,7 +25,7 @@ public:
bool isNull() const {return (_data.size() < 2);}
private:
const QVector<Trackpoint> &_data;
const TrackData &_data;
QVector<qreal> _distance;
QVector<qreal> _time;
};

21
src/trackdata.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef TRACKDATA_H
#define TRACKDATA_H
#include <QVector>
#include <QString>
#include "trackpoint.h"
class TrackData : public QVector<Trackpoint>
{
public:
const QString& name() const {return _name;}
const QString& description() const {return _desc;}
void setName(const QString &name) {_name = name;}
void setDescription(const QString &desc) {_desc = desc;}
private:
QString _name;
QString _desc;
};
#endif // TRACKDATA_H

View File

@ -10,6 +10,10 @@ QString TrackItem::toolTip()
{
ToolTip tt;
if (!_name.isEmpty())
tt.insert(qApp->translate("TrackItem", "Name"), _name);
if (!_desc.isEmpty())
tt.insert(qApp->translate("TrackItem", "Description"), _desc);
tt.insert(qApp->translate("TrackItem", "Distance"),
::distance(_distance, _units));
if (_time > 0)
@ -25,7 +29,7 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
: PathItem(parent)
{
QPointF p;
const QVector<Trackpoint> &t = track.track();
const TrackData &t = track.track();
Q_ASSERT(t.count() >= 2);
p = t.first().coordinates().toMercator();
@ -37,6 +41,8 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
updateShape();
_name = t.name();
_desc = t.description();
_date = track.date();
_distance = track.distance();
_time = track.time();

View File

@ -19,6 +19,8 @@ public:
private:
QString toolTip();
QString _name;
QString _desc;
QDateTime _date;
qreal _time;
};