2019-08-15 22:10:25 +02:00
|
|
|
#include <QStringList>
|
2019-08-15 21:27:55 +02:00
|
|
|
#include "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);
|
|
|
|
QStringList entry;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-15 21:27:55 +02:00
|
|
|
double lon = entry.at(0).trimmed().toDouble(&ok);
|
|
|
|
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;
|
|
|
|
}
|
2019-08-15 21:27:55 +02:00
|
|
|
double lat = entry.at(1).trimmed().toDouble(&ok);
|
|
|
|
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));
|
2019-08-15 21:27:55 +02:00
|
|
|
wp.setName(entry.at(2).trimmed());
|
|
|
|
if (entry.size() > 3)
|
|
|
|
wp.setDescription(entry.at(3).trimmed());
|
2016-10-23 11:09:20 +02:00
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
waypoints.append(wp);
|
2019-08-15 21:27:55 +02:00
|
|
|
|
|
|
|
entry.clear();
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|