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

Fixed empty CSV fields handling

This commit is contained in:
Martin Tůma 2018-04-14 00:45:03 +02:00
parent 3f71775101
commit 5eaf0455aa
3 changed files with 49 additions and 32 deletions

View File

@ -55,22 +55,28 @@ bool PLTParser::parse(QFile *file, QList<TrackData> &tracks,
Trackpoint tp(gcs->toWGS84(Coordinates(lon, lat))); Trackpoint tp(gcs->toWGS84(Coordinates(lon, lat)));
if (list.size() >= 4) { if (list.size() >= 4) {
double elevation = list.at(3).trimmed().toDouble(&res); QByteArray field(list.at(3).trimmed());
if (!res) { if (!field.isEmpty()) {
_errorString = "Invalid elevation"; double elevation = field.toDouble(&res);
return false; if (!res) {
_errorString = "Invalid elevation";
return false;
}
if (elevation != -777)
tp.setElevation(elevation * 0.3048);
} }
if (elevation != -777)
tp.setElevation(elevation * 0.3048);
} }
if (list.size() >= 5) { if (list.size() >= 5) {
double date = list.at(4).trimmed().toDouble(&res); QByteArray field(list.at(4).trimmed());
if (!res) { if (!field.isEmpty()) {
_errorString = "Invalid date"; double date = field.toDouble(&res);
return false; if (!res) {
_errorString = "Invalid date";
return false;
}
tp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
} }
tp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
} }
track.append(tp); track.append(tp);

View File

@ -68,17 +68,21 @@ bool RTEParser::parse(QFile *file, QList<TrackData> &tracks,
if (!name.isEmpty()) if (!name.isEmpty())
wp.setName(name); wp.setName(name);
if (list.size() >= 8) { if (list.size() >= 8) {
double date = list.at(7).trimmed().toDouble(&res); QByteArray field(list.at(7).trimmed());
if (!res) { if (!field.isEmpty()) {
_errorString = "Invalid date"; double date = field.toDouble(&res);
return false; if (!res) {
_errorString = "Invalid date";
return false;
}
wp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
} }
wp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
} }
if (list.size() >= 14) { if (list.size() >= 14) {
QString desc(list.at(13).trimmed().replace('\xD1', ',')); QString desc(list.at(13).trimmed().replace('\xD1', ','));
wp.setDescription(desc); if (!desc.isEmpty())
wp.setDescription(desc);
} }
routes.last().append(wp); routes.last().append(wp);

View File

@ -51,26 +51,33 @@ bool WPTParser::parse(QFile *file, QList<TrackData> &tracks,
if (!name.isEmpty()) if (!name.isEmpty())
wp.setName(name); wp.setName(name);
if (list.size() >= 5) { if (list.size() >= 5) {
double date = list.at(4).trimmed().toDouble(&res); QByteArray field(list.at(4).trimmed());
if (!res) { if (!field.isEmpty()) {
_errorString = "Invalid date"; double date = field.toDouble(&res);
return false; if (!res) {
_errorString = "Invalid date";
return false;
}
wp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
} }
wp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
} }
if (list.size() >= 11) { if (list.size() >= 11) {
QString desc(list.at(10).trimmed().replace('\xD1', ',')); QString desc(list.at(10).trimmed().replace('\xD1', ','));
if (!desc.isEmpty()) if (!desc.isEmpty())
wp.setDescription(desc); wp.setDescription(desc);
} if (list.size() >= 15) { }
double elevation = list.at(14).trimmed().toDouble(&res); if (list.size() >= 15) {
if (!res) { QByteArray field(list.at(14).trimmed());
_errorString = "Invalid elevation"; if (!field.isEmpty()) {
return false; double elevation = list.at(14).trimmed().toDouble(&res);
if (!res) {
_errorString = "Invalid elevation";
return false;
}
if (elevation != -777)
wp.setElevation(elevation * 0.3048);
} }
if (elevation != -777)
wp.setElevation(elevation * 0.3048);
} }
waypoints.append(wp); waypoints.append(wp);