From c89f8dbb47c4d350b44bff207eb5f1705c1680c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 29 Oct 2016 12:22:28 +0200 Subject: [PATCH] Improved error reporting --- lang/gpxsee_cs.ts | 100 +++++++++++++++++++++++++--------------------- src/csvparser.cpp | 6 +-- src/gpxparser.cpp | 10 ++--- src/gui.cpp | 22 +++++----- src/kmlparser.cpp | 16 ++++---- src/tcxparser.cpp | 10 ++--- 6 files changed, 85 insertions(+), 79 deletions(-) diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts index cc75dde9..ac2989e4 100644 --- a/lang/gpxsee_cs.ts +++ b/lang/gpxsee_cs.ts @@ -151,7 +151,7 @@ Otevřít soubor - + Open POI file Otevřít POI soubor @@ -364,70 +364,63 @@ - + All supported files (*.gpx *.tcx *.kml *.csv) Všechny podporované soubory (*.gpx *.tcx *.kml *.csv) - + GPX files (*.gpx) Soubory GPX (*.gpx) - + TCX files (*.tcx) Soubory TCX (*.tcx) - + KML files (*.kml) Soubory KML (*.kml) - - - Error loading data file: -%1 - Datový soubor nelze otevřít: -%1 - - + CSV files (*.csv) Soubory CSV (*.csv) - + All files (*) Všechny soubory (*) - - + + Date Datum - + Routes Trasy - + No GPX files loaded Nejsou načteny žádné GPX soubory - - %1 files + + %n files - %1 soubor - %1 soubory - %1 souborů + %n soubor + %n soubory + %n souborů @@ -451,7 +444,7 @@ Exportovat do PDF... - + Waypoints Navigační body @@ -497,12 +490,22 @@ - + Error loading data file: + Datový soubor nelze načíst: + + + + Line: %1 Řádka: %1 - + + Error loading POI file: + Soubor POI nelze načíst: + + + Tracks Cesty @@ -529,29 +532,16 @@ - + Distance Vzdálenost - + Time Čas - - - - Error - Chyba - - - - Error loading POI file: -%1 - Soubor POI nelze otevřít: -%1 - GraphView @@ -654,7 +644,17 @@ RouteItem - + + Name + Název + + + + Description + Popis + + + Distance Vzdálenost @@ -748,17 +748,27 @@ TrackItem - + + Name + Název + + + + Description + Popis + + + Distance Vzdálenost - + Time Čas - + Date Datum diff --git a/src/csvparser.cpp b/src/csvparser.cpp index a6d244cd..b1504fd2 100644 --- a/src/csvparser.cpp +++ b/src/csvparser.cpp @@ -12,20 +12,20 @@ bool CSVParser::loadFile(QFile *file) QByteArray line = file->readLine(); QList 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; } diff --git a/src/gpxparser.cpp b/src/gpxparser.cpp index 778dede3..9468a55e 100644 --- a/src/gpxparser.cpp +++ b/src/gpxparser.cpp @@ -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(); diff --git a/src/gui.cpp b/src/gui.cpp index 411cb3f5..bd14a00c 100644 --- a/src/gui.cpp +++ b/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; diff --git a/src/kmlparser.cpp b/src/kmlparser.cpp index a44bf871..24c3b9c2 100644 --- a/src/kmlparser.cpp +++ b/src/kmlparser.cpp @@ -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(); diff --git a/src/tcxparser.cpp b/src/tcxparser.cpp index 74281ac8..f15734fc 100644 --- a/src/tcxparser.cpp +++ b/src/tcxparser.cpp @@ -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();