1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00
GPXSee/src/data/csvparser.cpp

45 lines
1005 B
C++
Raw Normal View History

#include <QByteArrayList>
#include "common/csv.h"
2016-10-23 11:09:20 +02:00
#include "csvparser.h"
bool CSVParser::parse(QFile *file, QList<TrackData> &tracks,
2019-01-31 01:46:53 +01:00
QList<RouteData> &routes, QList<Area> &polygons,
QVector<Waypoint> &waypoints)
2016-10-23 11:09:20 +02:00
{
Q_UNUSED(tracks);
2017-07-27 19:47:46 +02:00
Q_UNUSED(routes);
2019-01-31 01:46:53 +01:00
Q_UNUSED(polygons);
2019-08-15 21:27:55 +02:00
CSV csv(file);
QByteArrayList entry;
2019-08-15 21:27:55 +02:00
bool ok;
2016-10-23 11:09:20 +02:00
2019-08-15 21:27:55 +02:00
while (!csv.atEnd()) {
if (!csv.readEntry(entry) || entry.size() < 3) {
2016-10-29 12:22:28 +02:00
_errorString = "Parse error";
2019-08-15 21:27:55 +02:00
_errorLine = csv.line();
2016-10-23 11:09:20 +02:00
return false;
}
double lon = entry.at(0).toDouble(&ok);
2019-08-15 21:27:55 +02:00
if (!ok || (lon < -180.0 || lon > 180.0)) {
2016-10-29 12:22:28 +02:00
_errorString = "Invalid longitude";
2019-08-15 21:27:55 +02:00
_errorLine = csv.line();
2016-10-23 11:09:20 +02:00
return false;
}
double lat = entry.at(1).toDouble(&ok);
2019-08-15 21:27:55 +02:00
if (!ok || (lat < -90.0 || lat > 90.0)) {
_errorString = "Invalid latitude";
2019-08-15 21:27:55 +02:00
_errorLine = csv.line();
return false;
}
Waypoint wp(Coordinates(lon, lat));
wp.setName(entry.at(2));
2019-08-15 21:27:55 +02:00
if (entry.size() > 3)
wp.setDescription(entry.at(3));
2016-10-23 11:09:20 +02:00
2017-07-27 19:47:46 +02:00
waypoints.append(wp);
2016-10-23 11:09:20 +02:00
}
return true;
}