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

Added support for Sigma SLF files

This commit is contained in:
Martin Tůma 2018-08-10 22:46:04 +02:00
parent 203f44b75a
commit c724bf134c
4 changed files with 155 additions and 4 deletions

View File

@ -138,7 +138,8 @@ HEADERS += src/config.h \
src/map/jnxmap.h \
src/map/krovak.h \
src/GUI/kv.h \
src/data/locparser.h
src/data/locparser.h \
src/data/slfparser.h
SOURCES += src/main.cpp \
src/common/coordinates.cpp \
src/common/rectc.cpp \
@ -240,7 +241,8 @@ SOURCES += src/main.cpp \
src/map/jnxmap.cpp \
src/map/krovak.cpp \
src/map/map.cpp \
src/data/locparser.cpp
src/data/locparser.cpp \
src/data/slfparser.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts \

View File

@ -10,6 +10,7 @@
#include "nmeaparser.h"
#include "oziparsers.h"
#include "locparser.h"
#include "slfparser.h"
#include "data.h"
@ -24,6 +25,7 @@ static PLTParser plt;
static WPTParser wpt;
static RTEParser rte;
static LOCParser loc;
static SLFParser slf;
static QHash<QString, Parser*> parsers()
{
@ -40,6 +42,7 @@ static QHash<QString, Parser*> parsers()
hash.insert("wpt", &wpt);
hash.insert("rte", &rte);
hash.insert("loc", &loc);
hash.insert("slf", &slf);
return hash;
}
@ -111,13 +114,14 @@ QString Data::formats()
{
return
tr("Supported files")
+ " (*.csv *.fit *.gpx *.igc *.kml *.loc *.nmea *.plt *.rte *.tcx *.wpt);;"
+ " (*.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("TCX files") + " (*.tcx);;" + tr("All files") + " (*)";
+ tr("SLF files") + " (*.slf);;" + tr("TCX files") + " (*.tcx);;"
+ tr("All files") + " (*)";
}
QStringList Data::filter()

119
src/data/slfparser.cpp Normal file
View File

@ -0,0 +1,119 @@
#include "slfparser.h"
void SLFParser::warning(const char *text) const
{
const QFile *file = static_cast<QFile *>(_reader.device());
qWarning("%s:%lld: %s\n", qPrintable(file->fileName()),
_reader.lineNumber(), text);
}
bool SLFParser::data(const QXmlStreamAttributes &attr, const char *name,
qreal &val)
{
bool res = false;
if (!attr.hasAttribute(name))
return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val = attr.value(name).toString().toDouble(&res);
#else // QT_VERSION < 5
val = attr.value(name).toDouble(&res);
#endif // QT_VERSION < 5
if (!res)
_reader.raiseError("Invalid " + QString(name));
return res;
}
void SLFParser::entries(const QDateTime &date, TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Entry") {
qreal val, lat, lon;
QXmlStreamAttributes attr(_reader.attributes());
if (!data(attr, "longitude", lon) || !data(attr, "latitude", lat)
|| (lon == 0.0 && lat == 0.0)) {
if (!_reader.error())
warning("Missing coordinates");
_reader.skipCurrentElement();
continue;
}
Trackpoint t(Coordinates(lon, lat));
if (!t.coordinates().isValid()) {
_reader.raiseError("Invalid coordinates");
return;
}
if (data(attr, "altitude", val))
t.setElevation(val / 1000);
if (data(attr, "cadence", val))
t.setCadence(val);
if (data(attr, "heartrate", val))
t.setHeartRate(val);
if (data(attr, "power", val))
t.setPower(val);
if (data(attr, "speed", val))
t.setSpeed(val);
if (data(attr, "trainingTimeAbsolute", val))
t.setTimestamp(date.addMSecs(val * 10));
track.append(t);
}
_reader.skipCurrentElement();
}
}
void SLFParser::generalInformation(QDateTime &date, TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
track.setName(_reader.readElementText());
else if (_reader.name() == "description")
track.setDescription(_reader.readElementText());
else if (_reader.name() == "startDate") {
QString ds(_reader.readElementText());
QLocale locale(QLocale::English);
date = locale.toDateTime(ds.mid(0, ds.indexOf("GMT"))
+ ds.right(4), "ddd MMM d HH:mm:ss yyyy");
} else
_reader.skipCurrentElement();
}
}
void SLFParser::activity(TrackData &track)
{
QDateTime date;
while (_reader.readNextStartElement()) {
if (_reader.name() == "Entries")
entries(date, track);
else if (_reader.name() == "GeneralInformation")
generalInformation(date, track);
else
_reader.skipCurrentElement();
}
}
bool SLFParser::parse(QFile *file, QList<TrackData> &tracks,
QList<RouteData> &routes, QList<Waypoint> &waypoints)
{
Q_UNUSED(waypoints);
Q_UNUSED(routes);
_reader.clear();
_reader.setDevice(file);
if (_reader.readNextStartElement()) {
if (_reader.name() == "Activity") {
tracks.append(TrackData());
activity(tracks.last());
} else
_reader.raiseError("Not a SLF file");
}
return !_reader.error();
}

26
src/data/slfparser.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef SLFPARSER_H
#define SLFPARSER_H
#include <QXmlStreamReader>
#include "parser.h"
class QDateTime;
class SLFParser : public Parser
{
bool parse(QFile *file, QList<TrackData> &tracks,
QList<RouteData> &routes, QList<Waypoint> &waypoints);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
private:
void generalInformation(QDateTime &date, TrackData &track);
void activity(TrackData &track);
void entries(const QDateTime &date, TrackData &track);
bool data(const QXmlStreamAttributes &attr, const char *name, qreal &val);
void warning(const char *text) const;
QXmlStreamReader _reader;
};
#endif // SLFPARSER_H