mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-27 21:24:47 +01:00
Fixed error line reporting in CSV-based files
This commit is contained in:
parent
e8b4105365
commit
01dfbb3706
@ -14,22 +14,27 @@ bool CSVParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
bool ok;
|
||||
|
||||
while (!csv.atEnd()) {
|
||||
if (!csv.readEntry(entry) || entry.size() < 3) {
|
||||
if (!csv.readEntry(entry)) {
|
||||
_errorString = "Parse error";
|
||||
_errorLine = csv.line();
|
||||
return false;
|
||||
}
|
||||
if (entry.size() < 3) {
|
||||
_errorString = "Invalid column count";
|
||||
_errorLine = csv.line() - 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
double lon = entry.at(0).toDouble(&ok);
|
||||
if (!ok || (lon < -180.0 || lon > 180.0)) {
|
||||
_errorString = "Invalid longitude";
|
||||
_errorLine = csv.line();
|
||||
_errorLine = csv.line() - 1;
|
||||
return false;
|
||||
}
|
||||
double lat = entry.at(1).toDouble(&ok);
|
||||
if (!ok || (lat < -90.0 || lat > 90.0)) {
|
||||
_errorString = "Invalid latitude";
|
||||
_errorLine = csv.line();
|
||||
_errorLine = csv.line() - 1;
|
||||
return false;
|
||||
}
|
||||
Waypoint wp(Coordinates(lon, lat));
|
||||
|
@ -159,7 +159,7 @@ bool CUPParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
return false;
|
||||
}
|
||||
|
||||
_errorLine = csv.line();
|
||||
_errorLine = csv.line() - 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -147,50 +147,55 @@ bool Conversion::loadList(const QString &path)
|
||||
}
|
||||
|
||||
while (!csv.atEnd()) {
|
||||
if (!csv.readEntry(entry) || entry.size() < 26) {
|
||||
if (!csv.readEntry(entry)) {
|
||||
qWarning("%s:%d: Parse error", qPrintable(path), csv.line());
|
||||
return false;
|
||||
}
|
||||
if (entry.size() < 26) {
|
||||
qWarning("%s:%d: Invalid column count", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString name(entry.at(0));
|
||||
int proj = entry.at(1).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid projection code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int units = entry.at(2).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid linear units code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int transform = entry.at(3).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid coordinate transformation code",
|
||||
qPrintable(path), csv.line());
|
||||
qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int cs = entry.at(4).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid coordinate system code",
|
||||
qPrintable(path), csv.line());
|
||||
qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!LinearUnits(units).isValid()) {
|
||||
qWarning("%s:%d: Unknown linear units code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
if (!Method(transform).isValid()) {
|
||||
qWarning("%s:%d: Unknown coordinate transformation code",
|
||||
qPrintable(path), csv.line());
|
||||
qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
if (!CoordinateSystem(cs).isValid()) {
|
||||
qWarning("%s:%d: Unknown coordinate system code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -44,25 +44,32 @@ bool Ellipsoid::loadList(const QString &path)
|
||||
}
|
||||
|
||||
while (!csv.atEnd()) {
|
||||
if (!csv.readEntry(entry) || entry.size() < 4) {
|
||||
if (!csv.readEntry(entry)) {
|
||||
qWarning("%s:%d: Parse error", qPrintable(path), csv.line());
|
||||
return false;
|
||||
}
|
||||
if (entry.size() < 4) {
|
||||
qWarning("%s:%d: Invalid column count", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = entry.at(1).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s: %d: Invalid ellipsoid code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double radius = entry.at(2).toDouble(&res);
|
||||
if (!res) {
|
||||
qWarning("%s: %d: Invalid radius", qPrintable(path), csv.line());
|
||||
qWarning("%s: %d: Invalid radius", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double flattening = entry.at(3).toDouble(&res);
|
||||
if (!res) {
|
||||
qWarning("%s: %d: Invalid flattening", qPrintable(path), csv.line());
|
||||
qWarning("%s: %d: Invalid flattening", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -101,86 +101,92 @@ bool GCS::loadList(const QString &path)
|
||||
}
|
||||
|
||||
while (!csv.atEnd()) {
|
||||
if (!csv.readEntry(entry) || entry.size() < 14) {
|
||||
if (!csv.readEntry(entry)) {
|
||||
qWarning("%s:%d: Parse error", qPrintable(path), csv.line());
|
||||
return false;
|
||||
}
|
||||
if (entry.size() < 14) {
|
||||
qWarning("%s:%d: Invalid column count", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = parameter(entry.at(1), &res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid GCS code", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid GCS code", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int gd = parameter(entry.at(2), &res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid geodetic datum code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int au = entry.at(3).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid angular units code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int el = entry.at(4).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid ellipsoid code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int pm = entry.at(5).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid prime meridian code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int ct = entry.at(6).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid coordinates transformation code",
|
||||
qPrintable(path), csv.line());
|
||||
qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double dx = entry.at(7).toDouble(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid dx", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid dx", qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double dy = entry.at(8).toDouble(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid dy", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid dy", qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double dz = entry.at(9).toDouble(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid dz", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid dz", qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double rx = parameterd(entry.at(10), &res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid rx", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid rx", qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double ry = parameterd(entry.at(11), &res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid ry", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid ry", qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double rz = parameterd(entry.at(12), &res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid rz", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid rz", qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
double ds = parameterd(entry.at(13), &res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid ds", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid ds", qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
const Ellipsoid &e = Ellipsoid::ellipsoid(el);
|
||||
if (e.isNull()) {
|
||||
qWarning("%s:%d: Unknown ellipsoid code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -197,12 +203,12 @@ bool GCS::loadList(const QString &path)
|
||||
break;
|
||||
default:
|
||||
qWarning("%s:%d: Unknown coordinates transformation method",
|
||||
qPrintable(path), csv.line());
|
||||
qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
if (!datum.isValid()) {
|
||||
qWarning("%s:%d: Invalid coordinates transformation parameters",
|
||||
qPrintable(path), csv.line());
|
||||
qPrintable(path), csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -211,7 +217,7 @@ bool GCS::loadList(const QString &path)
|
||||
_gcss.append(Entry(id, gd, entry.at(0), gcs));
|
||||
else
|
||||
qWarning("%s:%d: Unknown prime meridian/angular units code",
|
||||
qPrintable(path), csv.line());
|
||||
qPrintable(path), csv.line() - 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -37,35 +37,44 @@ bool PCS::loadList(const QString &path)
|
||||
}
|
||||
|
||||
while (!csv.atEnd()) {
|
||||
if (!csv.readEntry(entry) || entry.size() < 4) {
|
||||
if (!csv.readEntry(entry)) {
|
||||
qWarning("%s:%d: Parse error", qPrintable(path), csv.line());
|
||||
return false;
|
||||
}
|
||||
if (entry.size() < 4) {
|
||||
qWarning("%s:%d: Invalid column count", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString name(entry.at(0));
|
||||
int id = entry.at(1).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid PCS code", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid PCS code", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int gcs = entry.at(2).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid GCS code", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Invalid GCS code", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
int proj = entry.at(3).toInt(&res);
|
||||
if (!res) {
|
||||
qWarning("%s:%d: Invalid projection code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (GCS::gcs(gcs).isNull()) {
|
||||
qWarning("%s:%d: Unknown GCS code", qPrintable(path), csv.line());
|
||||
qWarning("%s:%d: Unknown GCS code", qPrintable(path),
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
if (Conversion::conversion(proj).isNull()) {
|
||||
qWarning("%s:%d: Unknown projection code", qPrintable(path),
|
||||
csv.line());
|
||||
csv.line() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user