mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 11:39:16 +02:00
Improved error reporting
This commit is contained in:
@ -12,20 +12,20 @@ bool CSVParser::loadFile(QFile *file)
|
||||
QByteArray line = file->readLine();
|
||||
QList<QByteArray> list = line.split(',');
|
||||
if (list.size() < 3) {
|
||||
_errorString = "Parse error.";
|
||||
_errorString = "Parse error";
|
||||
_errorLine = ln;
|
||||
return false;
|
||||
}
|
||||
|
||||
qreal lat = list[0].trimmed().toDouble(&res);
|
||||
if (!res || (lat < -90.0 || lat > 90.0)) {
|
||||
_errorString = "Invalid latitude.";
|
||||
_errorString = "Invalid latitude";
|
||||
_errorLine = ln;
|
||||
return false;
|
||||
}
|
||||
qreal lon = list[1].trimmed().toDouble(&res);
|
||||
if (!res || (lon < -180.0 || lon > 180.0)) {
|
||||
_errorString = "Invalid longitude.";
|
||||
_errorString = "Invalid longitude";
|
||||
_errorLine = ln;
|
||||
return false;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ qreal GPXParser::number()
|
||||
bool res;
|
||||
qreal ret = _reader.readElementText().toDouble(&res);
|
||||
if (!res)
|
||||
_reader.raiseError(QString("Invalid %1.").arg(
|
||||
_reader.raiseError(QString("Invalid %1").arg(
|
||||
_reader.name().toString()));
|
||||
|
||||
return ret;
|
||||
@ -17,7 +17,7 @@ QDateTime GPXParser::time()
|
||||
QDateTime d = QDateTime::fromString(_reader.readElementText(),
|
||||
Qt::ISODate);
|
||||
if (!d.isValid())
|
||||
_reader.raiseError(QString("Invalid %1.").arg(
|
||||
_reader.raiseError(QString("Invalid %1").arg(
|
||||
_reader.name().toString()));
|
||||
|
||||
return d;
|
||||
@ -35,7 +35,7 @@ Coordinates GPXParser::coordinates()
|
||||
lon = attr.value("lon").toDouble(&res);
|
||||
#endif // QT_VERSION < 5
|
||||
if (!res || (lon < -180.0 || lon > 180.0)) {
|
||||
_reader.raiseError("Invalid longitude.");
|
||||
_reader.raiseError("Invalid longitude");
|
||||
return Coordinates();
|
||||
}
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
@ -44,7 +44,7 @@ Coordinates GPXParser::coordinates()
|
||||
lat = attr.value("lat").toDouble(&res);
|
||||
#endif // QT_VERSION < 5
|
||||
if (!res || (lat < -90.0 || lat > 90.0)) {
|
||||
_reader.raiseError("Invalid latitude.");
|
||||
_reader.raiseError("Invalid latitude");
|
||||
return Coordinates();
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ bool GPXParser::parse()
|
||||
if (_reader.name() == "gpx")
|
||||
gpx();
|
||||
else
|
||||
_reader.raiseError("Not a GPX file.");
|
||||
_reader.raiseError("Not a GPX file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
|
22
src/gui.cpp
22
src/gui.cpp
@ -672,13 +672,11 @@ bool GUI::loadFile(const QString &fileName)
|
||||
updateGraphTabs();
|
||||
updatePathView();
|
||||
|
||||
QString error = fileName + QString("\n\n")
|
||||
+ tr("Error loading data file:\n%1").arg(data.errorString())
|
||||
+ QString("\n");
|
||||
QString error = tr("Error loading data file:") + "\n\n"
|
||||
+ fileName + "\n\n" + data.errorString();
|
||||
if (data.errorLine())
|
||||
error.append(tr("Line: %1").arg(data.errorLine()));
|
||||
|
||||
QMessageBox::critical(this, tr("Error"), error);
|
||||
error.append("\n" + tr("Line: %1").arg(data.errorLine()));
|
||||
QMessageBox::critical(this, APP_NAME, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -702,12 +700,11 @@ bool GUI::openPOIFile(const QString &fileName)
|
||||
return false;
|
||||
|
||||
if (!_poi->loadFile(fileName)) {
|
||||
QString error = fileName + QString("\n\n")
|
||||
+ tr("Error loading POI file:\n%1").arg(_poi->errorString())
|
||||
+ QString("\n");
|
||||
QString error = tr("Error loading POI file:") + "\n\n"
|
||||
+ fileName + "\n\n" + _poi->errorString();
|
||||
if (_poi->errorLine())
|
||||
error.append(tr("Line: %1").arg(_poi->errorLine()));
|
||||
QMessageBox::critical(this, tr("Error"), error);
|
||||
error.append("\n" + tr("Line: %1").arg(_poi->errorLine()));
|
||||
QMessageBox::critical(this, APP_NAME, error);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
@ -979,8 +976,7 @@ void GUI::updateStatusBarInfo()
|
||||
else if (_files.count() == 1)
|
||||
_fileNameLabel->setText(_files.at(0));
|
||||
else
|
||||
_fileNameLabel->setText(tr("%1 files", "", _files.count())
|
||||
.arg(_files.count()));
|
||||
_fileNameLabel->setText(tr("%n files", "", _files.count()));
|
||||
|
||||
qreal d = distance();
|
||||
Units units = _imperialUnitsAction->isChecked() ? Imperial : Metric;
|
||||
|
@ -6,7 +6,7 @@ qreal KMLParser::number()
|
||||
bool res;
|
||||
qreal ret = _reader.readElementText().toDouble(&res);
|
||||
if (!res)
|
||||
_reader.raiseError(QString("Invalid %1.").arg(
|
||||
_reader.raiseError(QString("Invalid %1").arg(
|
||||
_reader.name().toString()));
|
||||
|
||||
return ret;
|
||||
@ -17,7 +17,7 @@ QDateTime KMLParser::time()
|
||||
QDateTime d = QDateTime::fromString(_reader.readElementText(),
|
||||
Qt::ISODate);
|
||||
if (!d.isValid())
|
||||
_reader.raiseError(QString("Invalid %1.").arg(
|
||||
_reader.raiseError(QString("Invalid %1").arg(
|
||||
_reader.name().toString()));
|
||||
|
||||
return d;
|
||||
@ -205,7 +205,7 @@ void KMLParser::lineString(TrackData &track)
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "coordinates") {
|
||||
if (!lineCoordinates(track))
|
||||
_reader.raiseError("Invalid coordinates.");
|
||||
_reader.raiseError("Invalid coordinates");
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
@ -216,18 +216,18 @@ void KMLParser::point(Waypoint &waypoint)
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "coordinates") {
|
||||
if (!pointCoordinates(waypoint))
|
||||
_reader.raiseError("Invalid coordinates.");
|
||||
_reader.raiseError("Invalid coordinates");
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (waypoint.coordinates().isNull())
|
||||
_reader.raiseError("Missing Point coordinates.");
|
||||
_reader.raiseError("Missing Point coordinates");
|
||||
}
|
||||
|
||||
void KMLParser::Track(TrackData &track)
|
||||
{
|
||||
const char mismatchError[] = "gx:coord/when element count mismatch.";
|
||||
const char mismatchError[] = "gx:coord/when element count mismatch";
|
||||
int i = track.size();
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
@ -239,7 +239,7 @@ void KMLParser::Track(TrackData &track)
|
||||
_reader.raiseError(mismatchError);
|
||||
return;
|
||||
} else if (!coord(track[i])) {
|
||||
_reader.raiseError("Invalid coordinates.");
|
||||
_reader.raiseError("Invalid coordinates");
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
@ -329,7 +329,7 @@ bool KMLParser::parse()
|
||||
if (_reader.name() == "kml")
|
||||
kml();
|
||||
else
|
||||
_reader.raiseError("Not a KML file.");
|
||||
_reader.raiseError("Not a KML file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
|
@ -13,7 +13,7 @@ qreal TCXParser::number()
|
||||
bool res;
|
||||
qreal ret = _reader.readElementText().toDouble(&res);
|
||||
if (!res)
|
||||
_reader.raiseError(QString("Invalid %1.").arg(
|
||||
_reader.raiseError(QString("Invalid %1").arg(
|
||||
_reader.name().toString()));
|
||||
|
||||
return ret;
|
||||
@ -24,7 +24,7 @@ QDateTime TCXParser::time()
|
||||
QDateTime d = QDateTime::fromString(_reader.readElementText(),
|
||||
Qt::ISODate);
|
||||
if (!d.isValid())
|
||||
_reader.raiseError(QString("Invalid %1.").arg(
|
||||
_reader.raiseError(QString("Invalid %1").arg(
|
||||
_reader.name().toString()));
|
||||
|
||||
return d;
|
||||
@ -40,13 +40,13 @@ Coordinates TCXParser::position()
|
||||
if (_reader.name() == "LatitudeDegrees") {
|
||||
val = _reader.readElementText().toDouble(&res);
|
||||
if (!res || (val < -90.0 || val > 90.0))
|
||||
_reader.raiseError("Invalid LatitudeDegrees.");
|
||||
_reader.raiseError("Invalid LatitudeDegrees");
|
||||
else
|
||||
pos.setLat(val);
|
||||
} else if (_reader.name() == "LongitudeDegrees") {
|
||||
val = _reader.readElementText().toDouble(&res);
|
||||
if (!res || (val < -180.0 || val > 180.0))
|
||||
_reader.raiseError("Invalid LongitudeDegrees.");
|
||||
_reader.raiseError("Invalid LongitudeDegrees");
|
||||
else
|
||||
pos.setLon(val);
|
||||
} else
|
||||
@ -186,7 +186,7 @@ bool TCXParser::parse()
|
||||
if (_reader.name() == "TrainingCenterDatabase")
|
||||
tcx();
|
||||
else
|
||||
_reader.raiseError("Not a TCX file.");
|
||||
_reader.raiseError("Not a TCX file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
|
Reference in New Issue
Block a user