diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index 0f0f68b1..7be0eef7 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -747,11 +747,11 @@ bool GUI::openFile(const QString &fileName) bool GUI::loadFile(const QString &fileName) { - Data data; + Data data(fileName); QList > graphs; QList paths; - if (data.loadFile(fileName)) { + if (data.isValid()) { for (int i = 0; i < data.tracks().count(); i++) { _trackDistance += data.tracks().at(i)->distance(); _time += data.tracks().at(i)->time(); diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index 1ed40fda..0e106568 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -147,7 +147,7 @@ PathItem *MapView::addRoute(const Route &route) return ri; } -void MapView::addWaypoints(const QList &waypoints) +void MapView::addWaypoints(const QVector &waypoints) { for (int i = 0; i < waypoints.count(); i++) { const Waypoint &w = waypoints.at(i); diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index 058d6a06..740049a3 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -78,7 +78,7 @@ private slots: private: PathItem *addTrack(const Track &track); PathItem *addRoute(const Route &route); - void addWaypoints(const QList &waypoints); + void addWaypoints(const QVector &waypoints); void addPOI(const QList &waypoints); void loadPOI(); void clearPOI(); diff --git a/src/data/csvparser.cpp b/src/data/csvparser.cpp index 35efdea6..58a23dfd 100644 --- a/src/data/csvparser.cpp +++ b/src/data/csvparser.cpp @@ -1,7 +1,7 @@ #include "csvparser.h" bool CSVParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(tracks); Q_UNUSED(routes); diff --git a/src/data/csvparser.h b/src/data/csvparser.h index bbb01245..7d967504 100644 --- a/src/data/csvparser.h +++ b/src/data/csvparser.h @@ -9,7 +9,7 @@ public: CSVParser() : _errorLine(0) {} bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); + QVector &waypoints); QString errorString() const {return _errorString;} int errorLine() const {return _errorLine;} diff --git a/src/data/data.cpp b/src/data/data.cpp index 6a7b7703..a26a88ef 100644 --- a/src/data/data.cpp +++ b/src/data/data.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -75,34 +76,35 @@ void Data::processData() } } -bool Data::loadFile(const QString &fileName) +Data::Data(const QString &fileName) { QFile file(fileName); QFileInfo fi(fileName); - - _errorString.clear(); + _valid = false; _errorLine = 0; if (!file.open(QFile::ReadOnly)) { _errorString = qPrintable(file.errorString()); - return false; + return; } QHash::iterator it; if ((it = _parsers.find(fi.suffix().toLower())) != _parsers.end()) { if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) { processData(); - return true; + _valid = true; + return; + } else { + _errorLine = it.value()->errorLine(); + _errorString = it.value()->errorString(); } - - _errorLine = it.value()->errorLine(); - _errorString = it.value()->errorString(); } else { for (it = _parsers.begin(); it != _parsers.end(); it++) { if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) { processData(); - return true; + _valid = true; + return; } file.reset(); } @@ -115,22 +117,24 @@ bool Data::loadFile(const QString &fileName) _errorLine = 0; _errorString = "Unknown format"; } - - return false; } QString Data::formats() { return - tr("Supported files") + qApp->translate("Data", "Supported files") + " (*.csv *.fit *.gpx *.igc *.kml *.loc *.nmea *.plt *.rte *.slf *.tcx *.wpt);;" - + tr("CSV files") + " (*.csv);;" + tr("FIT files") + " (*.fit);;" - + tr("GPX files") + " (*.gpx);;" + tr("IGC files") + " (*.igc);;" - + tr("KML files") + " (*.kml);;" + tr("LOC files") + " (*.loc);;" - + tr("NMEA files") + " (*.nmea);;" - + tr("OziExplorer files") + " (*.plt *.rte *.wpt);;" - + tr("SLF files") + " (*.slf);;" + tr("TCX files") + " (*.tcx);;" - + tr("All files") + " (*)"; + + qApp->translate("Data", "CSV files") + " (*.csv);;" + + qApp->translate("Data", "FIT files") + " (*.fit);;" + + qApp->translate("Data", "GPX files") + " (*.gpx);;" + + qApp->translate("Data", "IGC files") + " (*.igc);;" + + qApp->translate("Data", "KML files") + " (*.kml);;" + + qApp->translate("Data", "LOC files") + " (*.loc);;" + + qApp->translate("Data", "NMEA files") + " (*.nmea);;" + + qApp->translate("Data", "OziExplorer files") + " (*.plt *.rte *.wpt);;" + + qApp->translate("Data", "SLF files") + " (*.slf);;" + + qApp->translate("Data", "TCX files") + " (*.tcx);;" + + qApp->translate("Data", "All files") + " (*)"; } QStringList Data::filter() diff --git a/src/data/data.h b/src/data/data.h index 071cb807..80f8cea7 100644 --- a/src/data/data.h +++ b/src/data/data.h @@ -1,10 +1,8 @@ #ifndef DATA_H #define DATA_H -#include #include #include -#include #include #include #include "waypoint.h" @@ -13,21 +11,19 @@ #include "parser.h" -class Data : public QObject +class Data { - Q_OBJECT - public: - Data(QObject *parent = 0) : QObject(parent), _errorLine(0) {} + Data(const QString &fileName); ~Data(); - bool loadFile(const QString &fileName); + bool isValid() const {return _valid;} const QString &errorString() const {return _errorString;} int errorLine() const {return _errorLine;} const QList &tracks() const {return _tracks;} const QList &routes() const {return _routes;} - const QList &waypoints() const {return _waypoints;} + const QVector &waypoints() const {return _waypoints;} static QString formats(); static QStringList filter(); @@ -37,12 +33,13 @@ public: private: void processData(); + bool _valid; QString _errorString; int _errorLine; QList _tracks; QList _routes; - QList _waypoints; + QVector _waypoints; QList _trackData; QList _routeData; diff --git a/src/data/fitparser.cpp b/src/data/fitparser.cpp index 96ee7af7..ef0f7510 100644 --- a/src/data/fitparser.cpp +++ b/src/data/fitparser.cpp @@ -372,7 +372,7 @@ bool FITParser::parseHeader(CTX &ctx) } bool FITParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(routes); Q_UNUSED(waypoints); diff --git a/src/data/fitparser.h b/src/data/fitparser.h index 95542b44..411712db 100644 --- a/src/data/fitparser.h +++ b/src/data/fitparser.h @@ -9,7 +9,7 @@ class FITParser : public Parser { public: bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); + QVector &waypoints); QString errorString() const {return _errorString;} int errorLine() const {return 0;} diff --git a/src/data/gpxparser.cpp b/src/data/gpxparser.cpp index 296cbe35..037074a3 100644 --- a/src/data/gpxparser.cpp +++ b/src/data/gpxparser.cpp @@ -198,7 +198,7 @@ void GPXParser::track(TrackData &track) } void GPXParser::gpx(QList &tracks, QList &routes, - QList &waypoints) + QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("trk")) { @@ -216,7 +216,7 @@ void GPXParser::gpx(QList &tracks, QList &routes, } bool GPXParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { _reader.clear(); _reader.setDevice(file); diff --git a/src/data/gpxparser.h b/src/data/gpxparser.h index 4a4f57ed..2e7bdb02 100644 --- a/src/data/gpxparser.h +++ b/src/data/gpxparser.h @@ -9,13 +9,13 @@ class GPXParser : public Parser { public: bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints); + QList &routes, QVector &waypoints); QString errorString() const {return _reader.errorString();} int errorLine() const {return _reader.lineNumber();} private: void gpx(QList &tracks, QList &routes, - QList &waypoints); + QVector &waypoints); void track(TrackData &track); void trackpoints(TrackData &track); void routepoints(RouteData &route, QList &tracks); diff --git a/src/data/igcparser.cpp b/src/data/igcparser.cpp index 46fa3887..4cf7aef0 100644 --- a/src/data/igcparser.cpp +++ b/src/data/igcparser.cpp @@ -192,7 +192,7 @@ bool IGCParser::readCRecord(RouteData &route, const char *line, int len) } bool IGCParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(waypoints); qint64 len; diff --git a/src/data/igcparser.h b/src/data/igcparser.h index 372e0170..7356f1fb 100644 --- a/src/data/igcparser.h +++ b/src/data/igcparser.h @@ -12,7 +12,7 @@ public: IGCParser() : _errorLine(0) {} bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints); + QList &routes, QVector &waypoints); QString errorString() const {return _errorString;} int errorLine() const {return _errorLine;} diff --git a/src/data/kmlparser.cpp b/src/data/kmlparser.cpp index 0b1d0da6..b46b952e 100644 --- a/src/data/kmlparser.cpp +++ b/src/data/kmlparser.cpp @@ -381,7 +381,7 @@ void KMLParser::multiTrack(TrackData &t) } void KMLParser::multiGeometry(QList &tracks, - QList &waypoints, const QString &name, const QString &desc, + QVector &waypoints, const QString &name, const QString &desc, const QDateTime timestamp) { while (_reader.readNextStartElement()) { @@ -403,7 +403,7 @@ void KMLParser::multiGeometry(QList &tracks, } } -void KMLParser::placemark(QList &tracks, QList &waypoints) +void KMLParser::placemark(QList &tracks, QVector &waypoints) { QString name, desc; QDateTime timestamp; @@ -448,7 +448,7 @@ void KMLParser::placemark(QList &tracks, QList &waypoints) } } -void KMLParser::folder(QList &tracks, QList &waypoints) +void KMLParser::folder(QList &tracks, QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("Placemark")) @@ -460,7 +460,7 @@ void KMLParser::folder(QList &tracks, QList &waypoints) } } -void KMLParser::document(QList &tracks, QList &waypoints) +void KMLParser::document(QList &tracks, QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("Placemark")) @@ -472,7 +472,7 @@ void KMLParser::document(QList &tracks, QList &waypoints) } } -void KMLParser::kml(QList &tracks, QList &waypoints) +void KMLParser::kml(QList &tracks, QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("Document")) @@ -487,7 +487,7 @@ void KMLParser::kml(QList &tracks, QList &waypoints) } bool KMLParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(routes); diff --git a/src/data/kmlparser.h b/src/data/kmlparser.h index 06c08e0e..f7f0e858 100644 --- a/src/data/kmlparser.h +++ b/src/data/kmlparser.h @@ -9,16 +9,16 @@ class KMLParser : public Parser { public: bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints); + QList &routes, QVector &waypoints); QString errorString() const {return _reader.errorString();} int errorLine() const {return _reader.lineNumber();} private: - void kml(QList &tracks, QList &waypoints); - void document(QList &tracks, QList &waypoints); - void folder(QList &tracks, QList &waypoints); - void placemark(QList &tracks, QList &waypoints); - void multiGeometry(QList &tracks, QList &waypoints, + void kml(QList &tracks, QVector &waypoints); + void document(QList &tracks, QVector &waypoints); + void folder(QList &tracks, QVector &waypoints); + void placemark(QList &tracks, QVector &waypoints); + void multiGeometry(QList &tracks, QVector &waypoints, const QString &name, const QString &desc, const QDateTime timestamp); void track(TrackData &track); void multiTrack(TrackData &t); diff --git a/src/data/locparser.cpp b/src/data/locparser.cpp index 5c081589..8d95fea5 100644 --- a/src/data/locparser.cpp +++ b/src/data/locparser.cpp @@ -46,7 +46,7 @@ void LOCParser::waypoint(Waypoint &waypoint) _reader.raiseError("Missing waypoint coordinates"); } -void LOCParser::loc(QList &waypoints) +void LOCParser::loc(QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("waypoint")) { @@ -58,7 +58,7 @@ void LOCParser::loc(QList &waypoints) } bool LOCParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(tracks); Q_UNUSED(routes); diff --git a/src/data/locparser.h b/src/data/locparser.h index a7593978..8fe52766 100644 --- a/src/data/locparser.h +++ b/src/data/locparser.h @@ -8,12 +8,12 @@ class LOCParser : public Parser { public: bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints); + QList &routes, QVector &waypoints); QString errorString() const {return _reader.errorString();} int errorLine() const {return _reader.lineNumber();} private: - void loc(QList &waypoints); + void loc(QVector &waypoints); void waypoint(Waypoint &waypoint); Coordinates coordinates(); diff --git a/src/data/nmeaparser.cpp b/src/data/nmeaparser.cpp index b1f0d36b..4e563d81 100644 --- a/src/data/nmeaparser.cpp +++ b/src/data/nmeaparser.cpp @@ -372,7 +372,7 @@ bool NMEAParser::readGGA(TrackData &track, const char *line, int len) return true; } -bool NMEAParser::readWPL(QList &waypoints, const char *line, int len) +bool NMEAParser::readWPL(QVector &waypoints, const char *line, int len) { int col = 1; const char *vp = line; @@ -478,7 +478,7 @@ bool NMEAParser::readZDA(const char *line, int len) } bool NMEAParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(routes); qint64 len; diff --git a/src/data/nmeaparser.h b/src/data/nmeaparser.h index 7bb673d1..487cb22b 100644 --- a/src/data/nmeaparser.h +++ b/src/data/nmeaparser.h @@ -11,7 +11,7 @@ public: NMEAParser() : _errorLine(0), _GGA(false) {} bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints); + QList &routes, QVector &waypoints); QString errorString() const {return _errorString;} int errorLine() const {return _errorLine;} @@ -27,7 +27,7 @@ private: bool readRMC(TrackData &track, const char *line, int len); bool readGGA(TrackData &track, const char *line, int len); - bool readWPL(QList &waypoints, const char *line, int len); + bool readWPL(QVector &waypoints, const char *line, int len); bool readZDA(const char *line, int len); int _errorLine; diff --git a/src/data/oziparsers.cpp b/src/data/oziparsers.cpp index eefe365c..da72bf40 100644 --- a/src/data/oziparsers.cpp +++ b/src/data/oziparsers.cpp @@ -27,7 +27,7 @@ static QByteArray &decode(QByteArray &ba) bool PLTParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(waypoints); Q_UNUSED(routes); @@ -113,7 +113,7 @@ bool PLTParser::parse(QFile *file, QList &tracks, } bool RTEParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(waypoints); Q_UNUSED(tracks); @@ -211,7 +211,7 @@ bool RTEParser::parse(QFile *file, QList &tracks, } bool WPTParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(tracks); Q_UNUSED(routes); diff --git a/src/data/oziparsers.h b/src/data/oziparsers.h index 54fccecf..f8a9fcc2 100644 --- a/src/data/oziparsers.h +++ b/src/data/oziparsers.h @@ -9,7 +9,7 @@ public: PLTParser() : _errorLine(0) {} bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); + QVector &waypoints); QString errorString() const {return _errorString;} int errorLine() const {return _errorLine;} @@ -24,7 +24,7 @@ public: RTEParser() : _errorLine(0) {} bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); + QVector &waypoints); QString errorString() const {return _errorString;} int errorLine() const {return _errorLine;} @@ -39,7 +39,7 @@ public: WPTParser() : _errorLine(0) {} bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); + QVector &waypoints); QString errorString() const {return _errorString;} int errorLine() const {return _errorLine;} diff --git a/src/data/parser.h b/src/data/parser.h index 6a0327f9..b910a967 100644 --- a/src/data/parser.h +++ b/src/data/parser.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "trackdata.h" #include "routedata.h" @@ -15,7 +16,7 @@ public: virtual ~Parser() {} virtual bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) = 0; + QList &routes, QVector &waypoints) = 0; virtual QString errorString() const = 0; virtual int errorLine() const = 0; }; diff --git a/src/data/poi.cpp b/src/data/poi.cpp index ab226820..6ef22a5a 100644 --- a/src/data/poi.cpp +++ b/src/data/poi.cpp @@ -14,13 +14,13 @@ POI::POI(QObject *parent) : QObject(parent) bool POI::loadFile(const QString &path, bool dir) { - Data data; + Data data(path); FileIndex index; index.enabled = true; index.start = _data.size(); - if (!data.loadFile(path)) { + if (!data.isValid()) { if (dir) { if (data.errorLine()) _errorString += QString("%1:%2: %3\n").arg(path) diff --git a/src/data/slfparser.cpp b/src/data/slfparser.cpp index 59141ecb..c9563fea 100644 --- a/src/data/slfparser.cpp +++ b/src/data/slfparser.cpp @@ -99,7 +99,7 @@ void SLFParser::activity(TrackData &track) } bool SLFParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(waypoints); Q_UNUSED(routes); diff --git a/src/data/slfparser.h b/src/data/slfparser.h index 601274c3..7f08d0ab 100644 --- a/src/data/slfparser.h +++ b/src/data/slfparser.h @@ -9,7 +9,7 @@ class QDateTime; class SLFParser : public Parser { bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints); + QList &routes, QVector &waypoints); QString errorString() const {return _reader.errorString();} int errorLine() const {return _reader.lineNumber();} diff --git a/src/data/tcxparser.cpp b/src/data/tcxparser.cpp index 5f314e10..fd20aad5 100644 --- a/src/data/tcxparser.cpp +++ b/src/data/tcxparser.cpp @@ -141,7 +141,7 @@ void TCXParser::lap(TrackData &track) } } -void TCXParser::course(QList &waypoints, TrackData &track) +void TCXParser::course(QVector &waypoints, TrackData &track) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("Track")) @@ -174,7 +174,7 @@ void TCXParser::activity(TrackData &track) } } -void TCXParser::courses(QList &tracks, QList &waypoints) +void TCXParser::courses(QList &tracks, QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("Course")) { @@ -220,7 +220,7 @@ void TCXParser::activities(QList &tracks) } } -void TCXParser::tcx(QList &tracks, QList &waypoints) +void TCXParser::tcx(QList &tracks, QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("Courses")) @@ -233,7 +233,7 @@ void TCXParser::tcx(QList &tracks, QList &waypoints) } bool TCXParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) + QList &routes, QVector &waypoints) { Q_UNUSED(routes); diff --git a/src/data/tcxparser.h b/src/data/tcxparser.h index fd23553f..06e628c4 100644 --- a/src/data/tcxparser.h +++ b/src/data/tcxparser.h @@ -9,17 +9,17 @@ class TCXParser : public Parser { public: bool parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints); + QList &routes, QVector &waypoints); QString errorString() const {return _reader.errorString();} int errorLine() const {return _reader.lineNumber();} private: - void tcx(QList &tracks, QList &waypoints); - void courses(QList &tracks, QList &waypoints); + void tcx(QList &tracks, QVector &waypoints); + void courses(QList &tracks, QVector &waypoints); void activities(QList &tracks); void multiSportSession(QList &tracks); void sport(QList &tracks); - void course(QList &waypoints, TrackData &track); + void course(QVector &waypoints, TrackData &track); void activity(TrackData &track); void lap(TrackData &track); void trackpoints(TrackData &track);