1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00
GPXSee/src/data/csvparser.cpp

48 lines
1.0 KiB
C++
Raw Normal View History

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"
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);
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)) {
_errorString = "Invalid latitude";
2019-08-15 21:27:55 +02:00
_errorLine = csv.line();
return false;
}
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;
}