diff --git a/gpxsee.pro b/gpxsee.pro index 0f4d771a..c5fc7500 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -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 \ diff --git a/src/csvparser.h b/src/csvparser.h index 8fabff88..93ea34d3 100644 --- a/src/csvparser.h +++ b/src/csvparser.h @@ -6,9 +6,9 @@ class CSVParser : public Parser { public: - CSVParser(QList > &tracks, - QList > &routes, QList &waypoints) - : Parser(tracks, routes, waypoints) {_errorLine = 0;} + CSVParser(QList &tracks, QList &routes, + QList &waypoints) : Parser(tracks, routes, waypoints) + {_errorLine = 0;} ~CSVParser() {} bool loadFile(QIODevice *device); diff --git a/src/data.cpp b/src/data.cpp index 55a05d76..e5f75f8a 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -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) diff --git a/src/data.h b/src/data.h index c70f08c2..ecf7abbc 100644 --- a/src/data.h +++ b/src/data.h @@ -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 &tracks() const {return _tracks;} const QList &routes() const {return _routes;} - const QList &waypoints() const {return _waypoint_data;} + const QList &waypoints() const {return _waypointData;} private: void createData(); @@ -36,9 +36,9 @@ private: QList _tracks; QList _routes; - QList > _track_data; - QList > _route_data; - QList _waypoint_data; + QList _trackData; + QList _routeData; + QList _waypointData; }; #endif // DATA_H diff --git a/src/gpxparser.cpp b/src/gpxparser.cpp index 8f1032aa..11487633 100644 --- a/src/gpxparser.cpp +++ b/src/gpxparser.cpp @@ -166,7 +166,7 @@ void GPXParser::waypointData(Waypoint &waypoint) waypoint.setElevation(waypoint.elevation() - gh); } -void GPXParser::trackpoints(QVector &track) +void GPXParser::trackpoints(TrackData &track) { while (_reader.readNextStartElement()) { if (_reader.name() == "trkpt") { @@ -177,23 +177,31 @@ void GPXParser::trackpoints(QVector &track) } } -void GPXParser::routepoints(QVector &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 &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()); + _tracks.append(TrackData()); track(_tracks.back()); } else if (_reader.name() == "rte") { - _routes.append(QVector()); + _routes.append(RouteData()); routepoints(_routes.back()); } else if (_reader.name() == "wpt") { _waypoints.append(Waypoint(coordinates())); diff --git a/src/gpxparser.h b/src/gpxparser.h index 58f62dfe..807f5fc9 100644 --- a/src/gpxparser.h +++ b/src/gpxparser.h @@ -8,9 +8,8 @@ class GPXParser : public Parser { public: - GPXParser(QList > &tracks, - QList > &routes, QList &waypoints) - : Parser(tracks, routes, waypoints) {} + GPXParser(QList &tracks, QList &routes, + QList &waypoints) : Parser(tracks, routes, waypoints) {} ~GPXParser() {} bool loadFile(QIODevice *device); @@ -24,9 +23,9 @@ private: bool parse(); void gpx(); - void track(QVector &track); - void trackpoints(QVector &track); - void routepoints(QVector &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); diff --git a/src/kmlparser.cpp b/src/kmlparser.cpp index 32619568..8d6ee516 100644 --- a/src/kmlparser.cpp +++ b/src/kmlparser.cpp @@ -79,7 +79,7 @@ bool KMLParser::pointCoordinates(Waypoint &waypoint) return true; } -bool KMLParser::lineCoordinates(QVector &track) +bool KMLParser::lineCoordinates(TrackData &track) { QString data = _reader.readElementText(); const QChar *sp, *ep, *cp, *vp; @@ -136,17 +136,21 @@ bool KMLParser::lineCoordinates(QVector &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 &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()); - lineString(_tracks.last()); + _tracks.append(TrackData()); + TrackData &track = _tracks.last(); + track.setName(name); + track.setDescription(desc); + lineString(track); } else _reader.skipCurrentElement(); } diff --git a/src/kmlparser.h b/src/kmlparser.h index e1d71e3b..9e99228c 100644 --- a/src/kmlparser.h +++ b/src/kmlparser.h @@ -8,9 +8,8 @@ class KMLParser : public Parser { public: - KMLParser(QList > &tracks, - QList > &routes, QList &waypoints) - : Parser(tracks, routes, waypoints) {} + KMLParser(QList &tracks, QList &routes, + QList &waypoints) : Parser(tracks, routes, waypoints) {} ~KMLParser() {} bool loadFile(QIODevice *device); @@ -23,11 +22,11 @@ private: void document(); void folder(); void placemark(); - void lineString(QVector &track); + void lineString(TrackData &track); void point(Waypoint &waypoint); bool pointCoordinates(Waypoint &waypoint); - bool lineCoordinates(QVector &track); - void timeStamp(Waypoint &waypoint); + bool lineCoordinates(TrackData &track); + QDateTime timeStamp(); qreal number(); QDateTime time(); diff --git a/src/parser.h b/src/parser.h index 72cec289..2dbc4bce 100644 --- a/src/parser.h +++ b/src/parser.h @@ -3,7 +3,8 @@ #include #include -#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 > &tracks, - QList > &routes, QList &waypoints) - : _tracks(tracks), _routes(routes), _waypoints(waypoints) {} + Parser(QList &tracks, QList &routes, + QList &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 > &_tracks; - QList > &_routes; + QList &_tracks; + QList &_routes; QList &_waypoints; }; diff --git a/src/route.cpp b/src/route.cpp index 8400a2b2..cd052cb3 100644 --- a/src/route.cpp +++ b/src/route.cpp @@ -1,6 +1,6 @@ #include "route.h" -Route::Route(const QVector &data) : _data(data) +Route::Route(const RouteData &data) : _data(data) { qreal dist = 0; diff --git a/src/route.h b/src/route.h index 87366893..6befe2fb 100644 --- a/src/route.h +++ b/src/route.h @@ -2,15 +2,15 @@ #define ROUTE_H #include -#include "waypoint.h" +#include "routedata.h" #include "graph.h" class Route { public: - Route(const QVector &data); + Route(const RouteData &data); - const QVector &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 &_data; + const RouteData &_data; QVector _distance; }; diff --git a/src/routedata.h b/src/routedata.h new file mode 100644 index 00000000..e1470e9b --- /dev/null +++ b/src/routedata.h @@ -0,0 +1,21 @@ +#ifndef ROUTEDATA_H +#define ROUTEDATA_H + +#include +#include +#include "waypoint.h" + +class RouteData : public QVector +{ +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 diff --git a/src/routeitem.cpp b/src/routeitem.cpp index 1a07e4e1..35f73a5d 100644 --- a/src/routeitem.cpp +++ b/src/routeitem.cpp @@ -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 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())); diff --git a/src/routeitem.h b/src/routeitem.h index 62ea4fdd..4ecab949 100644 --- a/src/routeitem.h +++ b/src/routeitem.h @@ -20,6 +20,9 @@ public: private: QString toolTip(); + + QString _name; + QString _desc; }; #endif // ROUTEITEM_H diff --git a/src/tcxparser.cpp b/src/tcxparser.cpp index c51c85a6..f4e96d58 100644 --- a/src/tcxparser.cpp +++ b/src/tcxparser.cpp @@ -83,7 +83,7 @@ void TCXParser::waypointData(Waypoint &waypoint) } } -void TCXParser::trackpoints(QVector &track) +void TCXParser::trackpoints(TrackData &track) { while (_reader.readNextStartElement()) { if (_reader.name() == "Trackpoint") { @@ -94,24 +94,26 @@ void TCXParser::trackpoints(QVector &track) } } -void TCXParser::lap() +void TCXParser::lap(TrackData &track) { while (_reader.readNextStartElement()) { - if (_reader.name() == "Track") { - _tracks.append(QVector()); - 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()); - 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(); } } diff --git a/src/tcxparser.h b/src/tcxparser.h index 6958c62d..c6be3549 100644 --- a/src/tcxparser.h +++ b/src/tcxparser.h @@ -8,9 +8,8 @@ class TCXParser : public Parser { public: - TCXParser(QList > &tracks, - QList > &routes, QList &waypoints) - : Parser(tracks, routes, waypoints) {} + TCXParser(QList &tracks, QList &routes, + QList &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 &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(); diff --git a/src/track.cpp b/src/track.cpp index 2ee0e3a3..84ffcaaf 100644 --- a/src/track.cpp +++ b/src/track.cpp @@ -79,7 +79,7 @@ static QVector filter(const QVector &v, int window) return ret; } -Track::Track(const QVector &data) : _data(data) +Track::Track(const TrackData &data) : _data(data) { qreal dist = 0; diff --git a/src/track.h b/src/track.h index 1b90bd9d..ce5da71f 100644 --- a/src/track.h +++ b/src/track.h @@ -3,15 +3,16 @@ #include #include -#include "trackpoint.h" +#include "trackdata.h" #include "graph.h" + class Track { public: - Track(const QVector &data); + Track(const TrackData &data); - const QVector &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 &_data; + const TrackData &_data; QVector _distance; QVector _time; }; diff --git a/src/trackdata.h b/src/trackdata.h new file mode 100644 index 00000000..26604c62 --- /dev/null +++ b/src/trackdata.h @@ -0,0 +1,21 @@ +#ifndef TRACKDATA_H +#define TRACKDATA_H + +#include +#include +#include "trackpoint.h" + +class TrackData : public QVector +{ +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 diff --git a/src/trackitem.cpp b/src/trackitem.cpp index 831ee124..7116e15b 100644 --- a/src/trackitem.cpp +++ b/src/trackitem.cpp @@ -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 &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(); diff --git a/src/trackitem.h b/src/trackitem.h index d0c1d5dd..12e12901 100644 --- a/src/trackitem.h +++ b/src/trackitem.h @@ -19,6 +19,8 @@ public: private: QString toolTip(); + QString _name; + QString _desc; QDateTime _date; qreal _time; };