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);
|
2016-10-25 19:46:44 +02:00
|
|
|
bool res;
|
2016-10-23 11:09:20 +02:00
|
|
|
|
2016-11-10 08:46:59 +01:00
|
|
|
_errorLine = 1;
|
2016-10-23 11:09:20 +02:00
|
|
|
_errorString.clear();
|
|
|
|
|
2016-10-29 10:40:30 +02:00
|
|
|
while (!file->atEnd()) {
|
|
|
|
QByteArray line = file->readLine();
|
2016-10-23 11:09:20 +02:00
|
|
|
QList<QByteArray> list = line.split(',');
|
|
|
|
if (list.size() < 3) {
|
2016-10-29 12:22:28 +02:00
|
|
|
_errorString = "Parse error";
|
2016-10-23 11:09:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-12 20:13:09 +02:00
|
|
|
qreal lon = list[0].trimmed().toDouble(&res);
|
2016-10-25 19:46:44 +02:00
|
|
|
if (!res || (lon < -180.0 || lon > 180.0)) {
|
2016-10-29 12:22:28 +02:00
|
|
|
_errorString = "Invalid longitude";
|
2016-10-23 11:09:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-12 20:13:09 +02:00
|
|
|
qreal lat = list[1].trimmed().toDouble(&res);
|
|
|
|
if (!res || (lat < -90.0 || lat > 90.0)) {
|
|
|
|
_errorString = "Invalid latitude";
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-24 00:21:40 +02:00
|
|
|
Waypoint wp(Coordinates(lon, lat));
|
2016-10-23 11:09:20 +02:00
|
|
|
|
|
|
|
QByteArray ba = list[2].trimmed();
|
|
|
|
QString name = QString::fromUtf8(ba.data(), ba.size());
|
|
|
|
wp.setName(name);
|
|
|
|
|
|
|
|
if (list.size() > 3) {
|
|
|
|
ba = list[3].trimmed();
|
|
|
|
wp.setDescription(QString::fromUtf8(ba.data(), ba.size()));
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
waypoints.append(wp);
|
2016-11-10 08:46:59 +01:00
|
|
|
_errorLine++;
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|