2023-04-15 03:18:52 +02:00
|
|
|
#include <QByteArrayList>
|
|
|
|
#include "common/csv.h"
|
2016-10-23 11:09:20 +02:00
|
|
|
#include "csvparser.h"
|
|
|
|
|
2018-04-13 20:54:38 +02:00
|
|
|
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
|
|
|
{
|
2018-04-13 20:54:38 +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);
|
2023-04-15 03:18:52 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-04-15 03:18:52 +02:00
|
|
|
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;
|
|
|
|
}
|
2023-04-15 03:18:52 +02:00
|
|
|
double lat = entry.at(1).toDouble(&ok);
|
2019-08-15 21:27:55 +02:00
|
|
|
if (!ok || (lat < -90.0 || lat > 90.0)) {
|
2018-09-12 20:13:09 +02:00
|
|
|
_errorString = "Invalid latitude";
|
2019-08-15 21:27:55 +02:00
|
|
|
_errorLine = csv.line();
|
2018-09-12 20:13:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-24 00:21:40 +02:00
|
|
|
Waypoint wp(Coordinates(lon, lat));
|
2023-04-15 03:18:52 +02:00
|
|
|
wp.setName(entry.at(2));
|
2019-08-15 21:27:55 +02:00
|
|
|
if (entry.size() > 3)
|
2023-04-15 03:18:52 +02:00
|
|
|
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;
|
|
|
|
}
|