mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 19:49:15 +02:00
Data/map loading code cleanup
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
#include "csvparser.h"
|
||||
|
||||
bool CSVParser::loadFile(QFile *file)
|
||||
bool CSVParser::parse(QFile *file, QList<TrackData> &track,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(track);
|
||||
Q_UNUSED(routes);
|
||||
bool res;
|
||||
|
||||
_errorLine = 1;
|
||||
@ -36,7 +39,7 @@ bool CSVParser::loadFile(QFile *file)
|
||||
wp.setDescription(QString::fromUtf8(ba.data(), ba.size()));
|
||||
}
|
||||
|
||||
_waypoints.append(wp);
|
||||
waypoints.append(wp);
|
||||
_errorLine++;
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,11 @@
|
||||
class CSVParser : public Parser
|
||||
{
|
||||
public:
|
||||
CSVParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
{_errorLine = 0;}
|
||||
CSVParser() : _errorLine(0) {}
|
||||
~CSVParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &track, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
|
64
src/data.cpp
64
src/data.cpp
@ -11,38 +11,32 @@
|
||||
#include "data.h"
|
||||
|
||||
|
||||
Data::Data() : _errorLine(0)
|
||||
static QHash<QString, Parser*> parsers()
|
||||
{
|
||||
_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("fit", new FITParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("csv", new CSVParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("igc", new IGCParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("nmea", new NMEAParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
QHash<QString, Parser*> hash;
|
||||
|
||||
hash.insert("gpx", new GPXParser());
|
||||
hash.insert("tcx", new TCXParser());
|
||||
hash.insert("kml", new KMLParser());
|
||||
hash.insert("fit", new FITParser());
|
||||
hash.insert("csv", new CSVParser());
|
||||
hash.insert("igc", new IGCParser());
|
||||
hash.insert("nmea", new NMEAParser());
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
QHash<QString, Parser*> Data::_parsers = parsers();
|
||||
|
||||
Data::~Data()
|
||||
{
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
delete it.value();
|
||||
|
||||
for (int i = 0; i < _tracks.count(); i++)
|
||||
delete _tracks.at(i);
|
||||
for (int i = 0; i < _routes.count(); i++)
|
||||
delete _routes.at(i);
|
||||
}
|
||||
|
||||
void Data::createData()
|
||||
void Data::processData()
|
||||
{
|
||||
for (int i = 0; i < _trackData.count(); i++)
|
||||
_tracks.append(new Track(_trackData.at(i)));
|
||||
@ -66,8 +60,8 @@ bool Data::loadFile(const QString &fileName)
|
||||
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
if ((it = _parsers.find(fi.suffix().toLower())) != _parsers.end()) {
|
||||
if (it.value()->loadFile(&file)) {
|
||||
createData();
|
||||
if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) {
|
||||
processData();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -75,8 +69,8 @@ bool Data::loadFile(const QString &fileName)
|
||||
_errorString = it.value()->errorString();
|
||||
} else {
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++) {
|
||||
if (it.value()->loadFile(&file)) {
|
||||
createData();
|
||||
if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) {
|
||||
processData();
|
||||
return true;
|
||||
}
|
||||
file.reset();
|
||||
@ -93,3 +87,23 @@ bool Data::loadFile(const QString &fileName)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString Data::formats()
|
||||
{
|
||||
return tr("Supported files (*.csv *.fit *.gpx *.igc *.kml *.nmea *.tcx)")
|
||||
+ ";;" + tr("CSV files (*.csv)") + ";;" + tr("FIT files (*.fit)") + ";;"
|
||||
+ tr("GPX files (*.gpx)") + ";;" + tr("IGC files (*.igc)") + ";;"
|
||||
+ tr("KML files (*.kml)") + ";;" + tr("NMEA files (*.nmea)") + ";;"
|
||||
+ tr("TCX files (*.tcx)") + ";;" + tr("All files (*)");
|
||||
}
|
||||
|
||||
QStringList Data::filter()
|
||||
{
|
||||
QStringList filter;
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
filter << QString("*.%1").arg(it.key());
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
19
src/data.h
19
src/data.h
@ -6,16 +6,19 @@
|
||||
#include <QHash>
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include "waypoint.h"
|
||||
#include "track.h"
|
||||
#include "route.h"
|
||||
#include "parser.h"
|
||||
|
||||
|
||||
class Data
|
||||
class Data : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Data();
|
||||
Data(QObject *parent = 0) : QObject(parent), _errorLine(0) {}
|
||||
~Data();
|
||||
|
||||
bool loadFile(const QString &fileName);
|
||||
@ -24,21 +27,25 @@ public:
|
||||
|
||||
const QList<Track*> &tracks() const {return _tracks;}
|
||||
const QList<Route*> &routes() const {return _routes;}
|
||||
const QList<Waypoint> &waypoints() const {return _waypointData;}
|
||||
const QList<Waypoint> &waypoints() const {return _waypoints;}
|
||||
|
||||
static QString formats();
|
||||
static QStringList filter();
|
||||
|
||||
private:
|
||||
void createData();
|
||||
void processData();
|
||||
|
||||
QString _errorString;
|
||||
int _errorLine;
|
||||
QHash<QString, Parser*> _parsers;
|
||||
|
||||
QList<Track*> _tracks;
|
||||
QList<Route*> _routes;
|
||||
QList<Waypoint> _waypoints;
|
||||
|
||||
QList<TrackData> _trackData;
|
||||
QList<RouteData> _routeData;
|
||||
QList<Waypoint> _waypointData;
|
||||
|
||||
static QHash<QString, Parser*> _parsers;
|
||||
};
|
||||
|
||||
#endif // DATA_H
|
||||
|
@ -10,8 +10,7 @@ const quint32 FIT_MAGIC = 0x5449462E; // .FIT
|
||||
#define TIMESTAMP_FIELD 253
|
||||
|
||||
|
||||
FITParser::FITParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
FITParser::FITParser()
|
||||
{
|
||||
memset(_defs, 0, sizeof(_defs));
|
||||
|
||||
@ -191,7 +190,8 @@ bool FITParser::readField(Field *f, quint32 &val)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool FITParser::parseData(MessageDefinition *def, quint8 offset)
|
||||
bool FITParser::parseData(TrackData &track, MessageDefinition *def,
|
||||
quint8 offset)
|
||||
{
|
||||
Field *field;
|
||||
quint32 timestamp = _timestamp + offset;
|
||||
@ -268,7 +268,7 @@ bool FITParser::parseData(MessageDefinition *def, quint8 offset)
|
||||
if (trackpoint.coordinates().isValid()) {
|
||||
trackpoint.setTimestamp(QDateTime::fromTime_t(timestamp
|
||||
+ 631065600));
|
||||
_tracks.last().append(trackpoint);
|
||||
track.append(trackpoint);
|
||||
} else {
|
||||
if (trackpoint.coordinates().isNull())
|
||||
warning("Missing coordinates");
|
||||
@ -282,21 +282,21 @@ bool FITParser::parseData(MessageDefinition *def, quint8 offset)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FITParser::parseDataMessage(quint8 header)
|
||||
bool FITParser::parseDataMessage(TrackData &track, quint8 header)
|
||||
{
|
||||
int local_id = header & 0xf;
|
||||
MessageDefinition* def = &_defs[local_id];
|
||||
return parseData(def, 0);
|
||||
return parseData(track, def, 0);
|
||||
}
|
||||
|
||||
bool FITParser::parseCompressedMessage(quint8 header)
|
||||
bool FITParser::parseCompressedMessage(TrackData &track, quint8 header)
|
||||
{
|
||||
int local_id = (header >> 5) & 3;
|
||||
MessageDefinition* def = &_defs[local_id];
|
||||
return parseData(def, header & 0x1f);
|
||||
return parseData(track, def, header & 0x1f);
|
||||
}
|
||||
|
||||
bool FITParser::parseRecord()
|
||||
bool FITParser::parseRecord(TrackData &track)
|
||||
{
|
||||
quint8 header;
|
||||
|
||||
@ -304,11 +304,11 @@ bool FITParser::parseRecord()
|
||||
return false;
|
||||
|
||||
if (header & 0x80)
|
||||
return parseCompressedMessage(header);
|
||||
return parseCompressedMessage(track, header);
|
||||
else if (header & 0x40)
|
||||
return parseDefinitionMessage(header);
|
||||
else
|
||||
return parseDataMessage(header);
|
||||
return parseDataMessage(track, header);
|
||||
}
|
||||
|
||||
bool FITParser::parseHeader()
|
||||
@ -337,8 +337,11 @@ bool FITParser::parseHeader()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FITParser::loadFile(QFile *file)
|
||||
bool FITParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(routes);
|
||||
Q_UNUSED(waypoints);
|
||||
bool ret = true;
|
||||
|
||||
_device = file;
|
||||
@ -348,10 +351,11 @@ bool FITParser::loadFile(QFile *file)
|
||||
if (!parseHeader())
|
||||
return false;
|
||||
|
||||
_tracks.append(TrackData());
|
||||
tracks.append(TrackData());
|
||||
TrackData &track = tracks.last();
|
||||
|
||||
while (_len)
|
||||
if ((ret = parseRecord()) == false)
|
||||
if ((ret = parseRecord(track)) == false)
|
||||
break;
|
||||
|
||||
clearDefinitions();
|
||||
|
@ -6,11 +6,11 @@
|
||||
class FITParser : public Parser
|
||||
{
|
||||
public:
|
||||
FITParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
FITParser();
|
||||
~FITParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return 0;}
|
||||
|
||||
@ -47,11 +47,11 @@ private:
|
||||
bool skipValue(size_t size);
|
||||
|
||||
bool parseHeader();
|
||||
bool parseRecord();
|
||||
bool parseRecord(TrackData &track);
|
||||
bool parseDefinitionMessage(quint8 header);
|
||||
bool parseCompressedMessage(quint8 header);
|
||||
bool parseDataMessage(quint8 header);
|
||||
bool parseData(MessageDefinition *def, quint8 offset);
|
||||
bool parseCompressedMessage(TrackData &track, quint8 header);
|
||||
bool parseDataMessage(TrackData &track, quint8 header);
|
||||
bool parseData(TrackData &track, MessageDefinition *def, quint8 offset);
|
||||
bool readField(Field *f, quint32 &val);
|
||||
|
||||
QIODevice *_device;
|
||||
|
@ -167,39 +167,36 @@ void GPXParser::track(TrackData &track)
|
||||
}
|
||||
}
|
||||
|
||||
void GPXParser::gpx()
|
||||
void GPXParser::gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "trk") {
|
||||
_tracks.append(TrackData());
|
||||
track(_tracks.back());
|
||||
tracks.append(TrackData());
|
||||
track(tracks.back());
|
||||
} else if (_reader.name() == "rte") {
|
||||
_routes.append(RouteData());
|
||||
routepoints(_routes.back());
|
||||
routes.append(RouteData());
|
||||
routepoints(routes.back());
|
||||
} else if (_reader.name() == "wpt") {
|
||||
_waypoints.append(Waypoint(coordinates()));
|
||||
waypointData(_waypoints.last());
|
||||
waypoints.append(Waypoint(coordinates()));
|
||||
waypointData(waypoints.last());
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
bool GPXParser::parse()
|
||||
bool GPXParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
if (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "gpx")
|
||||
gpx();
|
||||
gpx(tracks, routes, waypoints);
|
||||
else
|
||||
_reader.raiseError("Not a GPX file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool GPXParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -8,17 +8,16 @@
|
||||
class GPXParser : public Parser
|
||||
{
|
||||
public:
|
||||
GPXParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~GPXParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
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:
|
||||
bool parse();
|
||||
void gpx();
|
||||
void gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
void track(TrackData &track);
|
||||
void trackpoints(TrackData &track);
|
||||
void routepoints(RouteData &route);
|
||||
|
59
src/gui.cpp
59
src/gui.cpp
@ -102,24 +102,6 @@ GUI::~GUI()
|
||||
}
|
||||
}
|
||||
|
||||
const QString GUI::fileFormats() const
|
||||
{
|
||||
return tr("Supported files (*.csv *.fit *.gpx *.igc *.kml *.nmea *.tcx)")
|
||||
+ ";;" + tr("CSV files (*.csv)") + ";;" + tr("FIT files (*.fit)") + ";;"
|
||||
+ tr("GPX files (*.gpx)") + ";;" + tr("IGC files (*.igc)") + ";;"
|
||||
+ tr("KML files (*.kml)") + ";;" + tr("NMEA files (*.nmea)") + ";;"
|
||||
+ tr("TCX files (*.tcx)") + ";;" + tr("All files (*)");
|
||||
}
|
||||
|
||||
void GUI::createBrowser()
|
||||
{
|
||||
QStringList filter;
|
||||
filter << "*.gpx" << "*.tcx" << "*.kml" << "*.fit" << "*.csv" << "*.igc"
|
||||
<< "*.nmea";
|
||||
_browser = new FileBrowser(this);
|
||||
_browser->setFilter(filter);
|
||||
}
|
||||
|
||||
void GUI::loadDatums()
|
||||
{
|
||||
QString ef, df;
|
||||
@ -175,7 +157,7 @@ void GUI::loadMaps()
|
||||
else if (QFile::exists(GLOBAL_MAP_FILE))
|
||||
online = GLOBAL_MAP_FILE;
|
||||
|
||||
if (!online.isNull() && !_ml->loadList(online))
|
||||
if (!online.isNull() && !_ml->loadFile(online))
|
||||
qWarning("%s: %s", qPrintable(online), qPrintable(_ml->errorString()));
|
||||
|
||||
|
||||
@ -187,12 +169,10 @@ void GUI::loadMaps()
|
||||
if (!offline.isNull()) {
|
||||
QDir md(offline);
|
||||
QFileInfoList ml = md.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
QStringList filters;
|
||||
filters << "*.map" << "*.tba" << "*.tar";
|
||||
|
||||
for (int i = 0; i < ml.size(); i++) {
|
||||
QDir dir(ml.at(i).absoluteFilePath());
|
||||
QFileInfoList fl = dir.entryInfoList(filters, QDir::Files);
|
||||
QFileInfoList fl = dir.entryInfoList(MapList::filter(), QDir::Files);
|
||||
|
||||
if (fl.isEmpty())
|
||||
qWarning("%s: no map/atlas file found",
|
||||
@ -201,7 +181,7 @@ void GUI::loadMaps()
|
||||
qWarning("%s: ambiguous directory content",
|
||||
qPrintable(ml.at(i).absoluteFilePath()));
|
||||
else
|
||||
if (!_ml->loadMap(fl.first().absoluteFilePath()))
|
||||
if (!_ml->loadFile(fl.first().absoluteFilePath()))
|
||||
qWarning("%s: %s", qPrintable(fl.first().absoluteFilePath()),
|
||||
qPrintable(_ml->errorString()));
|
||||
}
|
||||
@ -234,6 +214,12 @@ void GUI::loadPOIs()
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::createBrowser()
|
||||
{
|
||||
_browser = new FileBrowser(this);
|
||||
_browser->setFilter(Data::filter());
|
||||
}
|
||||
|
||||
void GUI::createMapActions()
|
||||
{
|
||||
_mapsSignalMapper = new QSignalMapper(this);
|
||||
@ -736,7 +722,7 @@ void GUI::dataSources()
|
||||
void GUI::openFile()
|
||||
{
|
||||
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"),
|
||||
QString(), fileFormats());
|
||||
QString(), Data::formats());
|
||||
QStringList list = files;
|
||||
|
||||
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
|
||||
@ -826,7 +812,7 @@ bool GUI::loadFile(const QString &fileName)
|
||||
void GUI::openPOIFile()
|
||||
{
|
||||
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open POI file"),
|
||||
QString(), fileFormats());
|
||||
QString(), Data::formats());
|
||||
QStringList list = files;
|
||||
|
||||
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
|
||||
@ -1209,22 +1195,25 @@ void GUI::showGraphGrids(bool show)
|
||||
void GUI::loadMap()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"),
|
||||
QString(), tr("Map files (*.map *.tba *.tar)"));
|
||||
QString(), MapList::formats());
|
||||
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
if (_ml->loadMap(fileName)) {
|
||||
QAction *a = new QAction(_ml->maps().last()->name(), this);
|
||||
a->setCheckable(true);
|
||||
a->setActionGroup(_mapsActionGroup);
|
||||
_mapsSignalMapper->setMapping(a, _ml->maps().size() - 1);
|
||||
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
|
||||
_mapActions.append(a);
|
||||
_mapMenu->insertAction(_mapsEnd, a);
|
||||
int count = _ml->maps().count();
|
||||
if (_ml->loadFile(fileName)) {
|
||||
for (int i = count; i < _ml->maps().count(); i++) {
|
||||
QAction *a = new QAction(_ml->maps().at(i)->name(), this);
|
||||
a->setCheckable(true);
|
||||
a->setActionGroup(_mapsActionGroup);
|
||||
_mapsSignalMapper->setMapping(a, i);
|
||||
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
|
||||
_mapActions.append(a);
|
||||
_mapMenu->insertAction(_mapsEnd, a);
|
||||
}
|
||||
_showMapAction->setEnabled(true);
|
||||
_clearMapCacheAction->setEnabled(true);
|
||||
a->activate(QAction::Trigger);
|
||||
_mapActions.last()->activate(QAction::Trigger);
|
||||
} else {
|
||||
QString error = tr("Error loading map:") + "\n\n"
|
||||
+ fileName + "\n\n" + _ml->errorString();
|
||||
|
@ -121,8 +121,6 @@ private:
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
|
||||
const QString fileFormats() const;
|
||||
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
@ -120,7 +120,7 @@ bool IGCParser::readHRecord(const char *line, int len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IGCParser::readBRecord(const char *line, int len)
|
||||
bool IGCParser::readBRecord(TrackData &track, const char *line, int len)
|
||||
{
|
||||
qreal lat, lon, ele;
|
||||
QTime time;
|
||||
@ -156,12 +156,12 @@ bool IGCParser::readBRecord(const char *line, int len)
|
||||
Trackpoint t(Coordinates(lon, lat));
|
||||
t.setTimestamp(QDateTime(_date, _time, Qt::UTC));
|
||||
t.setElevation(ele);
|
||||
_tracks.last().append(t);
|
||||
track.append(t);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IGCParser::readCRecord(const char *line, int len)
|
||||
bool IGCParser::readCRecord(RouteData &route, const char *line, int len)
|
||||
{
|
||||
qreal lat, lon;
|
||||
|
||||
@ -183,14 +183,16 @@ bool IGCParser::readCRecord(const char *line, int len)
|
||||
|
||||
Waypoint w(Coordinates(lon, lat));
|
||||
w.setName(QString(ba.trimmed()));
|
||||
_routes.last().append(w);
|
||||
route.append(w);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IGCParser::loadFile(QFile *file)
|
||||
bool IGCParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(waypoints);
|
||||
qint64 len;
|
||||
char line[76 + 2 + 1 + 1];
|
||||
bool route = false, track = false;
|
||||
@ -221,11 +223,11 @@ bool IGCParser::loadFile(QFile *file)
|
||||
return false;
|
||||
} else if (line[0] == 'C') {
|
||||
if (route) {
|
||||
if (!readCRecord(line, len))
|
||||
if (!readCRecord(routes.last() ,line, len))
|
||||
return false;
|
||||
} else {
|
||||
route = true;
|
||||
_routes.append(RouteData());
|
||||
routes.append(RouteData());
|
||||
}
|
||||
} else if (line[0] == 'B') {
|
||||
if (_date.isNull()) {
|
||||
@ -233,11 +235,11 @@ bool IGCParser::loadFile(QFile *file)
|
||||
return false;
|
||||
}
|
||||
if (!track) {
|
||||
_tracks.append(TrackData());
|
||||
tracks.append(TrackData());
|
||||
_time = QTime(0, 0);
|
||||
track = true;
|
||||
}
|
||||
if (!readBRecord(line, len))
|
||||
if (!readBRecord(tracks.last(), line, len))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,18 @@
|
||||
class IGCParser : public Parser
|
||||
{
|
||||
public:
|
||||
IGCParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
{_errorLine = 0;}
|
||||
IGCParser() : _errorLine(0) {}
|
||||
~IGCParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
private:
|
||||
bool readHRecord(const char *line, int len);
|
||||
bool readBRecord(const char *line, int len);
|
||||
bool readCRecord(const char *line, int len);
|
||||
bool readBRecord(TrackData &track, const char *line, int len);
|
||||
bool readCRecord(RouteData &route, const char *line, int len);
|
||||
|
||||
int _errorLine;
|
||||
QString _errorString;
|
||||
|
@ -251,20 +251,21 @@ void KMLParser::track(TrackData &track)
|
||||
_reader.raiseError(mismatchError);
|
||||
}
|
||||
|
||||
void KMLParser::multiGeometry(const QString &name, const QString &desc,
|
||||
void KMLParser::multiGeometry(QList<TrackData> &tracks,
|
||||
QList<Waypoint> &waypoints, const QString &name, const QString &desc,
|
||||
const QDateTime timestamp)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Point") {
|
||||
_waypoints.append(Waypoint());
|
||||
Waypoint &w = _waypoints.last();
|
||||
waypoints.append(Waypoint());
|
||||
Waypoint &w = waypoints.last();
|
||||
w.setName(name);
|
||||
w.setDescription(desc);
|
||||
w.setTimestamp(timestamp);
|
||||
point(w);
|
||||
} else if (_reader.name() == "LineString") {
|
||||
_tracks.append(TrackData());
|
||||
TrackData &t = _tracks.last();
|
||||
tracks.append(TrackData());
|
||||
TrackData &t = tracks.last();
|
||||
t.setName(name);
|
||||
t.setDescription(desc);
|
||||
lineString(t);
|
||||
@ -273,7 +274,7 @@ void KMLParser::multiGeometry(const QString &name, const QString &desc,
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::placemark()
|
||||
void KMLParser::placemark(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
QString name, desc;
|
||||
QDateTime timestamp;
|
||||
@ -286,23 +287,23 @@ void KMLParser::placemark()
|
||||
else if (_reader.name() == "TimeStamp")
|
||||
timestamp = timeStamp();
|
||||
else if (_reader.name() == "MultiGeometry")
|
||||
multiGeometry(name, desc, timestamp);
|
||||
multiGeometry(tracks, waypoints, name, desc, timestamp);
|
||||
else if (_reader.name() == "Point") {
|
||||
_waypoints.append(Waypoint());
|
||||
Waypoint &w = _waypoints.last();
|
||||
waypoints.append(Waypoint());
|
||||
Waypoint &w = waypoints.last();
|
||||
w.setName(name);
|
||||
w.setDescription(desc);
|
||||
w.setTimestamp(timestamp);
|
||||
point(w);
|
||||
} else if (_reader.name() == "LineString") {
|
||||
_tracks.append(TrackData());
|
||||
TrackData &t = _tracks.last();
|
||||
tracks.append(TrackData());
|
||||
TrackData &t = tracks.last();
|
||||
t.setName(name);
|
||||
t.setDescription(desc);
|
||||
lineString(t);
|
||||
} else if (_reader.name() == "Track") {
|
||||
_tracks.append(TrackData());
|
||||
TrackData &t = _tracks.last();
|
||||
tracks.append(TrackData());
|
||||
TrackData &t = tracks.last();
|
||||
t.setName(name);
|
||||
t.setDescription(desc);
|
||||
track(t);
|
||||
@ -311,58 +312,56 @@ void KMLParser::placemark()
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::folder()
|
||||
void KMLParser::folder(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Placemark")
|
||||
placemark();
|
||||
placemark(tracks, waypoints);
|
||||
else if (_reader.name() == "Folder")
|
||||
folder();
|
||||
folder(tracks, waypoints);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::document()
|
||||
void KMLParser::document(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Placemark")
|
||||
placemark();
|
||||
placemark(tracks, waypoints);
|
||||
else if (_reader.name() == "Folder")
|
||||
folder();
|
||||
folder(tracks, waypoints);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::kml()
|
||||
void KMLParser::kml(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Document")
|
||||
document();
|
||||
document(tracks, waypoints);
|
||||
else if (_reader.name() == "Placemark")
|
||||
placemark();
|
||||
placemark(tracks, waypoints);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
bool KMLParser::parse()
|
||||
bool KMLParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(routes);
|
||||
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
if (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "kml")
|
||||
kml();
|
||||
kml(tracks, waypoints);
|
||||
else
|
||||
_reader.raiseError("Not a KML file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool KMLParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -8,22 +8,20 @@
|
||||
class KMLParser : public Parser
|
||||
{
|
||||
public:
|
||||
KMLParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~KMLParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
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:
|
||||
bool parse();
|
||||
void kml();
|
||||
void document();
|
||||
void folder();
|
||||
void placemark();
|
||||
void multiGeometry(const QString &name, const QString &desc,
|
||||
const QDateTime timestamp);
|
||||
void kml(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void document(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void folder(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void placemark(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void multiGeometry(QList<TrackData> &tracks, QList<Waypoint> &waypoints,
|
||||
const QString &name, const QString &desc, const QDateTime timestamp);
|
||||
void track(TrackData &track);
|
||||
void lineString(TrackData &track);
|
||||
void point(Waypoint &waypoint);
|
||||
|
136
src/maplist.cpp
136
src/maplist.cpp
@ -6,26 +6,25 @@
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
bool MapList::loadListEntry(const QByteArray &line)
|
||||
Map *MapList::loadListEntry(const QByteArray &line)
|
||||
{
|
||||
QList<QByteArray> list = line.split('\t');
|
||||
if (list.size() != 2)
|
||||
return false;
|
||||
return 0;
|
||||
|
||||
QByteArray ba1 = list[0].trimmed();
|
||||
QByteArray ba2 = list[1].trimmed();
|
||||
if (ba1.isEmpty() || ba2.isEmpty())
|
||||
return false;
|
||||
return 0;
|
||||
|
||||
_maps.append(new OnlineMap(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||
QString::fromLatin1(ba2.data(), ba2.size()), this));
|
||||
|
||||
return true;
|
||||
return new OnlineMap(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||
QString::fromLatin1(ba2.data(), ba2.size()), this);
|
||||
}
|
||||
|
||||
bool MapList::loadList(const QString &path)
|
||||
{
|
||||
QFile file(path);
|
||||
QList<Map*> maps;
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
_errorString = file.errorString();
|
||||
@ -36,65 +35,102 @@ bool MapList::loadList(const QString &path)
|
||||
while (!file.atEnd()) {
|
||||
ln++;
|
||||
QByteArray line = file.readLine();
|
||||
Map *map = loadListEntry(line);
|
||||
|
||||
if (!loadListEntry(line)) {
|
||||
if (map)
|
||||
maps.append(map);
|
||||
else {
|
||||
for (int i = 0; i < maps.count(); i++)
|
||||
delete maps.at(i);
|
||||
_errorString = QString("Invalid map list entry on line %1.")
|
||||
.arg(QString::number(ln));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_maps += maps;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapList::loadMap(const QString &path)
|
||||
{
|
||||
OfflineMap *map = new OfflineMap(path, this);
|
||||
if (map->isValid()) {
|
||||
_maps.append(map);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = map->errorString();
|
||||
delete map;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool MapList::loadTba(const QString &path)
|
||||
{
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool MapList::loadTar(const QString &path)
|
||||
{
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
OfflineMap *map = new OfflineMap(path, this);
|
||||
if (map->isValid()) {
|
||||
_maps.append(map);
|
||||
return true;
|
||||
} else {
|
||||
qWarning("%s: %s", qPrintable(path), qPrintable(_errorString));
|
||||
qWarning("%s: %s", qPrintable(path),
|
||||
qPrintable(map->errorString()));
|
||||
_errorString = "Not a map/atlas file";
|
||||
delete map;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MapList::loadFile(const QString &path)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
QString suffix = fi.suffix().toLower();
|
||||
|
||||
if (suffix == "map") {
|
||||
OfflineMap *om = new OfflineMap(path, this);
|
||||
if (om->isValid()) {
|
||||
_maps.append(om);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = om->errorString();
|
||||
delete om;
|
||||
return false;
|
||||
}
|
||||
} else if (suffix == "tba") {
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
return false;
|
||||
}
|
||||
} else if (suffix == "tar") {
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
OfflineMap *om = new OfflineMap(path, this);
|
||||
if (om->isValid()) {
|
||||
_maps.append(om);
|
||||
return true;
|
||||
} else {
|
||||
qWarning("%s: %s", qPrintable(path), qPrintable(_errorString));
|
||||
qWarning("%s: %s", qPrintable(path),
|
||||
qPrintable(om->errorString()));
|
||||
_errorString = "Not a map/atlas file";
|
||||
delete om;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (suffix == "txt")
|
||||
return loadList(path);
|
||||
else if (suffix == "map")
|
||||
return loadMap(path);
|
||||
else if (suffix == "tba")
|
||||
return loadTba(path);
|
||||
else if (suffix == "tar")
|
||||
return loadTar(path);
|
||||
else {
|
||||
_errorString = "Not a map/atlas file";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QString MapList::formats()
|
||||
{
|
||||
return tr("Map files (*.map *.tba *.tar)") + ";;"
|
||||
+ tr("URL list files (*.txt)");
|
||||
}
|
||||
|
||||
QStringList MapList::filter()
|
||||
{
|
||||
QStringList filter;
|
||||
filter << "*.map" << "*.tba" << "*.tar" << "*.txt";
|
||||
return filter;
|
||||
}
|
||||
|
@ -12,14 +12,21 @@ class MapList : public QObject
|
||||
public:
|
||||
MapList(QObject *parent = 0) : QObject(parent) {}
|
||||
|
||||
bool loadMap(const QString &path);
|
||||
bool loadList(const QString &path);
|
||||
bool loadFile(const QString &path);
|
||||
|
||||
QList<Map*> &maps() {return _maps;}
|
||||
const QList<Map*> &maps() const {return _maps;}
|
||||
const QString &errorString() const {return _errorString;}
|
||||
|
||||
static QString formats();
|
||||
static QStringList filter();
|
||||
|
||||
private:
|
||||
bool loadListEntry(const QByteArray &line);
|
||||
Map *loadListEntry(const QByteArray &line);
|
||||
|
||||
bool loadList(const QString &path);
|
||||
bool loadMap(const QString &path);
|
||||
bool loadTba(const QString &path);
|
||||
bool loadTar(const QString &path);
|
||||
|
||||
QList<Map*> _maps;
|
||||
QString _errorString;
|
||||
|
@ -227,7 +227,7 @@ bool NMEAParser::readEW(const char *data, int len, qreal &lon)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::readRMC(const char *line, int len)
|
||||
bool NMEAParser::readRMC(TrackData &track, const char *line, int len)
|
||||
{
|
||||
int col = 1;
|
||||
const char *vp = line;
|
||||
@ -280,22 +280,23 @@ bool NMEAParser::readRMC(const char *line, int len)
|
||||
}
|
||||
|
||||
if (!date.isNull()) {
|
||||
if (_date.isNull() && !_time.isNull() && !_tracks.last().isEmpty())
|
||||
_tracks.last().last().setTimestamp(QDateTime(date, _time, Qt::UTC));
|
||||
if (_date.isNull() && !_time.isNull() && !track.isEmpty())
|
||||
track.last().setTimestamp(QDateTime(date, _time, Qt::UTC));
|
||||
_date = date;
|
||||
}
|
||||
|
||||
if (valid && !_GGA && !std::isnan(lat) && !std::isnan(lon)) {
|
||||
Trackpoint t(Coordinates(lon, lat));
|
||||
Coordinates c(lon, lat);
|
||||
if (valid && !_GGA && c.isValid()) {
|
||||
Trackpoint t(c);
|
||||
if (!_date.isNull() && !time.isNull())
|
||||
t.setTimestamp(QDateTime(_date, time, Qt::UTC));
|
||||
_tracks.last().append(t);
|
||||
track.append(t);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::readGGA(const char *line, int len)
|
||||
bool NMEAParser::readGGA(TrackData &track, const char *line, int len)
|
||||
{
|
||||
int col = 1;
|
||||
const char *vp = line;
|
||||
@ -356,13 +357,14 @@ bool NMEAParser::readGGA(const char *line, int len)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!std::isnan(lat) && !std::isnan(lon)) {
|
||||
Trackpoint t(Coordinates(lon, lat));
|
||||
Coordinates c(lon, lat);
|
||||
if (c.isValid()) {
|
||||
Trackpoint t(c);
|
||||
if (!(_time.isNull() || _date.isNull()))
|
||||
t.setTimestamp(QDateTime(_date, _time, Qt::UTC));
|
||||
if (!std::isnan(ele))
|
||||
t.setElevation(ele - gh);
|
||||
_tracks.last().append(t);
|
||||
track.append(t);
|
||||
|
||||
_GGA = true;
|
||||
}
|
||||
@ -370,7 +372,7 @@ bool NMEAParser::readGGA(const char *line, int len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::readWPL(const char *line, int len)
|
||||
bool NMEAParser::readWPL(QList<Waypoint> &waypoints, const char *line, int len)
|
||||
{
|
||||
int col = 1;
|
||||
const char *vp = line;
|
||||
@ -411,10 +413,11 @@ bool NMEAParser::readWPL(const char *line, int len)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!std::isnan(lat) && !std::isnan(lon)) {
|
||||
Waypoint w(Coordinates(lon, lat));
|
||||
Coordinates c(lon, lat);
|
||||
if (c.isValid()) {
|
||||
Waypoint w(c);
|
||||
w.setName(name);
|
||||
_waypoints.append(w);
|
||||
waypoints.append(w);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -474,8 +477,10 @@ bool NMEAParser::readZDA(const char *line, int len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::loadFile(QFile *file)
|
||||
bool NMEAParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(routes);
|
||||
qint64 len;
|
||||
char line[80 + 2 + 1 + 1];
|
||||
|
||||
@ -486,7 +491,8 @@ bool NMEAParser::loadFile(QFile *file)
|
||||
_time = QTime();
|
||||
_GGA = false;
|
||||
|
||||
_tracks.append(TrackData());
|
||||
tracks.append(TrackData());
|
||||
TrackData &track = tracks.last();
|
||||
|
||||
while (!file->atEnd()) {
|
||||
len = file->readLine(line, sizeof(line));
|
||||
@ -501,13 +507,13 @@ bool NMEAParser::loadFile(QFile *file)
|
||||
|
||||
if (validSentence(line, len)) {
|
||||
if (!memcmp(line + 3, "RMC,", 4)) {
|
||||
if (!readRMC(line + 7, len))
|
||||
if (!readRMC(track, line + 7, len))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "GGA,", 4)) {
|
||||
if (!readGGA(line + 7, len))
|
||||
if (!readGGA(track, line + 7, len))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "WPL,", 4)) {
|
||||
if (!readWPL(line + 7, len))
|
||||
if (!readWPL(waypoints, line + 7, len))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "ZDA,", 4)) {
|
||||
if (!readZDA(line + 7, len))
|
||||
@ -518,7 +524,7 @@ bool NMEAParser::loadFile(QFile *file)
|
||||
_errorLine++;
|
||||
}
|
||||
|
||||
if (!_tracks.last().size() && !_waypoints.size()) {
|
||||
if (!tracks.last().size() && !waypoints.size()) {
|
||||
_errorString = "No usable NMEA sentence found";
|
||||
return false;
|
||||
}
|
||||
|
@ -8,12 +8,11 @@
|
||||
class NMEAParser : public Parser
|
||||
{
|
||||
public:
|
||||
NMEAParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
{_errorLine = 0; _GGA = false;}
|
||||
NMEAParser() : _errorLine(0), _GGA(false) {}
|
||||
~NMEAParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
@ -27,9 +26,9 @@ private:
|
||||
bool readAltitude(const char *data, int len, qreal &ele);
|
||||
bool readGeoidHeight(const char *data, int len, qreal &gh);
|
||||
|
||||
bool readRMC(const char *line, int len);
|
||||
bool readGGA(const char *line, int len);
|
||||
bool readWPL(const char *line, int len);
|
||||
bool readRMC(TrackData &track, const char *line, int len);
|
||||
bool readGGA(TrackData &track, const char *line, int len);
|
||||
bool readWPL(QList<Waypoint> &waypoints, const char *line, int len);
|
||||
bool readZDA(const char *line, int len);
|
||||
|
||||
int _errorLine;
|
||||
|
11
src/parser.h
11
src/parser.h
@ -12,19 +12,12 @@
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : _tracks(tracks), _routes(routes),
|
||||
_waypoints(waypoints) {}
|
||||
virtual ~Parser() {}
|
||||
|
||||
virtual bool loadFile(QFile *file) = 0;
|
||||
virtual bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints) = 0;
|
||||
virtual QString errorString() const = 0;
|
||||
virtual int errorLine() const = 0;
|
||||
|
||||
protected:
|
||||
QList<TrackData> &_tracks;
|
||||
QList<RouteData> &_routes;
|
||||
QList<Waypoint> &_waypoints;
|
||||
};
|
||||
|
||||
#endif // PARSER_H
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define SCALE_OFFSET 7
|
||||
|
||||
PathView::PathView(Map *map, POI *poi, QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
Q_ASSERT(map != 0);
|
||||
Q_ASSERT(poi != 0);
|
||||
|
@ -131,7 +131,7 @@ void TCXParser::lap(TrackData &track)
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::course(TrackData &track)
|
||||
void TCXParser::course(QList<Waypoint> &waypoints, TrackData &track)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Track")
|
||||
@ -144,7 +144,7 @@ void TCXParser::course(TrackData &track)
|
||||
Waypoint w;
|
||||
waypointData(w);
|
||||
if (w.coordinates().isValid())
|
||||
_waypoints.append(w);
|
||||
waypoints.append(w);
|
||||
else
|
||||
warning("Missing Trackpoint coordinates");
|
||||
} else
|
||||
@ -162,56 +162,54 @@ void TCXParser::activity(TrackData &track)
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::courses()
|
||||
void TCXParser::courses(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Course") {
|
||||
_tracks.append(TrackData());
|
||||
course(_tracks.back());
|
||||
tracks.append(TrackData());
|
||||
course(waypoints, tracks.back());
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::activities()
|
||||
void TCXParser::activities(QList<TrackData> &tracks)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Activity") {
|
||||
_tracks.append(TrackData());
|
||||
activity(_tracks.back());
|
||||
tracks.append(TrackData());
|
||||
activity(tracks.back());
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::tcx()
|
||||
void TCXParser::tcx(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Courses")
|
||||
courses();
|
||||
courses(tracks, waypoints);
|
||||
else if (_reader.name() == "Activities")
|
||||
activities();
|
||||
activities(tracks);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
bool TCXParser::parse()
|
||||
bool TCXParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(routes);
|
||||
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
if (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "TrainingCenterDatabase")
|
||||
tcx();
|
||||
tcx(tracks, waypoints);
|
||||
else
|
||||
_reader.raiseError("Not a TCX file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool TCXParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -8,20 +8,18 @@
|
||||
class TCXParser : public Parser
|
||||
{
|
||||
public:
|
||||
TCXParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~TCXParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
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:
|
||||
bool parse();
|
||||
void tcx();
|
||||
void courses();
|
||||
void activities();
|
||||
void course(TrackData &track);
|
||||
void tcx(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void courses(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void activities(QList<TrackData> &tracks);
|
||||
void course(QList<Waypoint> &waypoints, TrackData &track);
|
||||
void activity(TrackData &track);
|
||||
void lap(TrackData &track);
|
||||
void trackpoints(TrackData &track);
|
||||
|
Reference in New Issue
Block a user