1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-19 04:02:09 +01:00

Improved error reporting

This commit is contained in:
Martin Tůma 2016-10-29 12:22:28 +02:00
parent e4d777bace
commit c89f8dbb47
6 changed files with 85 additions and 79 deletions

View File

@ -151,7 +151,7 @@
<translation>Otevřít soubor</translation> <translation>Otevřít soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="684"/> <location filename="../src/gui.cpp" line="686"/>
<source>Open POI file</source> <source>Open POI file</source>
<translation>Otevřít POI soubor</translation> <translation>Otevřít POI soubor</translation>
</message> </message>
@ -364,70 +364,63 @@
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="603"/> <location filename="../src/gui.cpp" line="603"/>
<location filename="../src/gui.cpp" line="685"/> <location filename="../src/gui.cpp" line="687"/>
<source>All supported files (*.gpx *.tcx *.kml *.csv)</source> <source>All supported files (*.gpx *.tcx *.kml *.csv)</source>
<translation>Všechny podporované soubory (*.gpx *.tcx *.kml *.csv) </translation> <translation>Všechny podporované soubory (*.gpx *.tcx *.kml *.csv) </translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="604"/> <location filename="../src/gui.cpp" line="604"/>
<location filename="../src/gui.cpp" line="686"/> <location filename="../src/gui.cpp" line="688"/>
<source>GPX files (*.gpx)</source> <source>GPX files (*.gpx)</source>
<translation>Soubory GPX (*.gpx)</translation> <translation>Soubory GPX (*.gpx)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="604"/> <location filename="../src/gui.cpp" line="604"/>
<location filename="../src/gui.cpp" line="687"/> <location filename="../src/gui.cpp" line="689"/>
<source>TCX files (*.tcx)</source> <source>TCX files (*.tcx)</source>
<translation>Soubory TCX (*.tcx)</translation> <translation>Soubory TCX (*.tcx)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="605"/> <location filename="../src/gui.cpp" line="605"/>
<location filename="../src/gui.cpp" line="687"/> <location filename="../src/gui.cpp" line="689"/>
<source>KML files (*.kml)</source> <source>KML files (*.kml)</source>
<translation>Soubory KML (*.kml)</translation> <translation>Soubory KML (*.kml)</translation>
</message> </message>
<message>
<location filename="../src/gui.cpp" line="672"/>
<source>Error loading data file:
%1</source>
<translation>Datový soubor nelze otevřít:
%1 </translation>
</message>
<message> <message>
<location filename="../src/gui.cpp" line="605"/> <location filename="../src/gui.cpp" line="605"/>
<location filename="../src/gui.cpp" line="686"/> <location filename="../src/gui.cpp" line="688"/>
<source>CSV files (*.csv)</source> <source>CSV files (*.csv)</source>
<translation>Soubory CSV (*.csv)</translation> <translation>Soubory CSV (*.csv)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="606"/> <location filename="../src/gui.cpp" line="606"/>
<location filename="../src/gui.cpp" line="688"/> <location filename="../src/gui.cpp" line="690"/>
<source>All files (*)</source> <source>All files (*)</source>
<translation>Všechny soubory (*)</translation> <translation>Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="774"/> <location filename="../src/gui.cpp" line="775"/>
<location filename="../src/gui.cpp" line="777"/> <location filename="../src/gui.cpp" line="778"/>
<source>Date</source> <source>Date</source>
<translation>Datum</translation> <translation>Datum</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="786"/> <location filename="../src/gui.cpp" line="787"/>
<source>Routes</source> <source>Routes</source>
<translation>Trasy</translation> <translation>Trasy</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="974"/> <location filename="../src/gui.cpp" line="975"/>
<source>No GPX files loaded</source> <source>No GPX files loaded</source>
<translation>Nejsou načteny žádné GPX soubory</translation> <translation>Nejsou načteny žádné GPX soubory</translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../src/gui.cpp" line="978"/> <location filename="../src/gui.cpp" line="979"/>
<source>%1 files</source> <source>%n files</source>
<translation> <translation>
<numerusform>%1 soubor</numerusform> <numerusform>%n soubor</numerusform>
<numerusform>%1 soubory</numerusform> <numerusform>%n soubory</numerusform>
<numerusform>%1 souborů</numerusform> <numerusform>%n souborů</numerusform>
</translation> </translation>
</message> </message>
<message> <message>
@ -451,7 +444,7 @@
<translation>Exportovat do PDF...</translation> <translation>Exportovat do PDF...</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="788"/> <location filename="../src/gui.cpp" line="789"/>
<source>Waypoints</source> <source>Waypoints</source>
<translation>Navigační body</translation> <translation>Navigační body</translation>
</message> </message>
@ -497,12 +490,22 @@
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="675"/> <location filename="../src/gui.cpp" line="675"/>
<location filename="../src/gui.cpp" line="705"/> <source>Error loading data file:</source>
<translation>Datový soubor nelze načíst:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="678"/>
<location filename="../src/gui.cpp" line="706"/>
<source>Line: %1</source> <source>Line: %1</source>
<translation>Řádka: %1</translation> <translation>Řádka: %1</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="784"/> <location filename="../src/gui.cpp" line="703"/>
<source>Error loading POI file:</source>
<translation>Soubor POI nelze načíst:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="785"/>
<source>Tracks</source> <source>Tracks</source>
<translation>Cesty</translation> <translation>Cesty</translation>
</message> </message>
@ -529,29 +532,16 @@
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="325"/> <location filename="../src/gui.cpp" line="325"/>
<location filename="../src/gui.cpp" line="791"/> <location filename="../src/gui.cpp" line="792"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="332"/> <location filename="../src/gui.cpp" line="332"/>
<location filename="../src/gui.cpp" line="793"/> <location filename="../src/gui.cpp" line="794"/>
<source>Time</source> <source>Time</source>
<translation>Čas</translation> <translation>Čas</translation>
</message> </message>
<message>
<location filename="../src/gui.cpp" line="677"/>
<location filename="../src/gui.cpp" line="706"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="702"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
%1</translation>
</message>
</context> </context>
<context> <context>
<name>GraphView</name> <name>GraphView</name>
@ -654,7 +644,17 @@
<context> <context>
<name>RouteItem</name> <name>RouteItem</name>
<message> <message>
<location filename="../src/routeitem.cpp" line="14"/> <location filename="../src/routeitem.cpp" line="15"/>
<source>Name</source>
<translation>Název</translation>
</message>
<message>
<location filename="../src/routeitem.cpp" line="17"/>
<source>Description</source>
<translation>Popis</translation>
</message>
<message>
<location filename="../src/routeitem.cpp" line="18"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
@ -748,17 +748,27 @@
<context> <context>
<name>TrackItem</name> <name>TrackItem</name>
<message> <message>
<location filename="../src/trackitem.cpp" line="13"/> <location filename="../src/trackitem.cpp" line="14"/>
<source>Name</source>
<translation>Název</translation>
</message>
<message>
<location filename="../src/trackitem.cpp" line="16"/>
<source>Description</source>
<translation>Popis</translation>
</message>
<message>
<location filename="../src/trackitem.cpp" line="17"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/trackitem.cpp" line="16"/> <location filename="../src/trackitem.cpp" line="20"/>
<source>Time</source> <source>Time</source>
<translation>Čas</translation> <translation>Čas</translation>
</message> </message>
<message> <message>
<location filename="../src/trackitem.cpp" line="18"/> <location filename="../src/trackitem.cpp" line="22"/>
<source>Date</source> <source>Date</source>
<translation>Datum</translation> <translation>Datum</translation>
</message> </message>

View File

@ -12,20 +12,20 @@ bool CSVParser::loadFile(QFile *file)
QByteArray line = file->readLine(); QByteArray line = file->readLine();
QList<QByteArray> list = line.split(','); QList<QByteArray> list = line.split(',');
if (list.size() < 3) { if (list.size() < 3) {
_errorString = "Parse error."; _errorString = "Parse error";
_errorLine = ln; _errorLine = ln;
return false; return false;
} }
qreal lat = list[0].trimmed().toDouble(&res); qreal lat = list[0].trimmed().toDouble(&res);
if (!res || (lat < -90.0 || lat > 90.0)) { if (!res || (lat < -90.0 || lat > 90.0)) {
_errorString = "Invalid latitude."; _errorString = "Invalid latitude";
_errorLine = ln; _errorLine = ln;
return false; return false;
} }
qreal lon = list[1].trimmed().toDouble(&res); qreal lon = list[1].trimmed().toDouble(&res);
if (!res || (lon < -180.0 || lon > 180.0)) { if (!res || (lon < -180.0 || lon > 180.0)) {
_errorString = "Invalid longitude."; _errorString = "Invalid longitude";
_errorLine = ln; _errorLine = ln;
return false; return false;
} }

View File

@ -6,7 +6,7 @@ qreal GPXParser::number()
bool res; bool res;
qreal ret = _reader.readElementText().toDouble(&res); qreal ret = _reader.readElementText().toDouble(&res);
if (!res) if (!res)
_reader.raiseError(QString("Invalid %1.").arg( _reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString())); _reader.name().toString()));
return ret; return ret;
@ -17,7 +17,7 @@ QDateTime GPXParser::time()
QDateTime d = QDateTime::fromString(_reader.readElementText(), QDateTime d = QDateTime::fromString(_reader.readElementText(),
Qt::ISODate); Qt::ISODate);
if (!d.isValid()) if (!d.isValid())
_reader.raiseError(QString("Invalid %1.").arg( _reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString())); _reader.name().toString()));
return d; return d;
@ -35,7 +35,7 @@ Coordinates GPXParser::coordinates()
lon = attr.value("lon").toDouble(&res); lon = attr.value("lon").toDouble(&res);
#endif // QT_VERSION < 5 #endif // QT_VERSION < 5
if (!res || (lon < -180.0 || lon > 180.0)) { if (!res || (lon < -180.0 || lon > 180.0)) {
_reader.raiseError("Invalid longitude."); _reader.raiseError("Invalid longitude");
return Coordinates(); return Coordinates();
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
@ -44,7 +44,7 @@ Coordinates GPXParser::coordinates()
lat = attr.value("lat").toDouble(&res); lat = attr.value("lat").toDouble(&res);
#endif // QT_VERSION < 5 #endif // QT_VERSION < 5
if (!res || (lat < -90.0 || lat > 90.0)) { if (!res || (lat < -90.0 || lat > 90.0)) {
_reader.raiseError("Invalid latitude."); _reader.raiseError("Invalid latitude");
return Coordinates(); return Coordinates();
} }
@ -229,7 +229,7 @@ bool GPXParser::parse()
if (_reader.name() == "gpx") if (_reader.name() == "gpx")
gpx(); gpx();
else else
_reader.raiseError("Not a GPX file."); _reader.raiseError("Not a GPX file");
} }
return !_reader.error(); return !_reader.error();

View File

@ -672,13 +672,11 @@ bool GUI::loadFile(const QString &fileName)
updateGraphTabs(); updateGraphTabs();
updatePathView(); updatePathView();
QString error = fileName + QString("\n\n") QString error = tr("Error loading data file:") + "\n\n"
+ tr("Error loading data file:\n%1").arg(data.errorString()) + fileName + "\n\n" + data.errorString();
+ QString("\n");
if (data.errorLine()) if (data.errorLine())
error.append(tr("Line: %1").arg(data.errorLine())); error.append("\n" + tr("Line: %1").arg(data.errorLine()));
QMessageBox::critical(this, APP_NAME, error);
QMessageBox::critical(this, tr("Error"), error);
return false; return false;
} }
} }
@ -702,12 +700,11 @@ bool GUI::openPOIFile(const QString &fileName)
return false; return false;
if (!_poi->loadFile(fileName)) { if (!_poi->loadFile(fileName)) {
QString error = fileName + QString("\n\n") QString error = tr("Error loading POI file:") + "\n\n"
+ tr("Error loading POI file:\n%1").arg(_poi->errorString()) + fileName + "\n\n" + _poi->errorString();
+ QString("\n");
if (_poi->errorLine()) if (_poi->errorLine())
error.append(tr("Line: %1").arg(_poi->errorLine())); error.append("\n" + tr("Line: %1").arg(_poi->errorLine()));
QMessageBox::critical(this, tr("Error"), error); QMessageBox::critical(this, APP_NAME, error);
return false; return false;
} else { } else {
@ -979,8 +976,7 @@ void GUI::updateStatusBarInfo()
else if (_files.count() == 1) else if (_files.count() == 1)
_fileNameLabel->setText(_files.at(0)); _fileNameLabel->setText(_files.at(0));
else else
_fileNameLabel->setText(tr("%1 files", "", _files.count()) _fileNameLabel->setText(tr("%n files", "", _files.count()));
.arg(_files.count()));
qreal d = distance(); qreal d = distance();
Units units = _imperialUnitsAction->isChecked() ? Imperial : Metric; Units units = _imperialUnitsAction->isChecked() ? Imperial : Metric;

View File

@ -6,7 +6,7 @@ qreal KMLParser::number()
bool res; bool res;
qreal ret = _reader.readElementText().toDouble(&res); qreal ret = _reader.readElementText().toDouble(&res);
if (!res) if (!res)
_reader.raiseError(QString("Invalid %1.").arg( _reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString())); _reader.name().toString()));
return ret; return ret;
@ -17,7 +17,7 @@ QDateTime KMLParser::time()
QDateTime d = QDateTime::fromString(_reader.readElementText(), QDateTime d = QDateTime::fromString(_reader.readElementText(),
Qt::ISODate); Qt::ISODate);
if (!d.isValid()) if (!d.isValid())
_reader.raiseError(QString("Invalid %1.").arg( _reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString())); _reader.name().toString()));
return d; return d;
@ -205,7 +205,7 @@ void KMLParser::lineString(TrackData &track)
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "coordinates") { if (_reader.name() == "coordinates") {
if (!lineCoordinates(track)) if (!lineCoordinates(track))
_reader.raiseError("Invalid coordinates."); _reader.raiseError("Invalid coordinates");
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
@ -216,18 +216,18 @@ void KMLParser::point(Waypoint &waypoint)
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "coordinates") { if (_reader.name() == "coordinates") {
if (!pointCoordinates(waypoint)) if (!pointCoordinates(waypoint))
_reader.raiseError("Invalid coordinates."); _reader.raiseError("Invalid coordinates");
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
if (waypoint.coordinates().isNull()) if (waypoint.coordinates().isNull())
_reader.raiseError("Missing Point coordinates."); _reader.raiseError("Missing Point coordinates");
} }
void KMLParser::Track(TrackData &track) 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(); int i = track.size();
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
@ -239,7 +239,7 @@ void KMLParser::Track(TrackData &track)
_reader.raiseError(mismatchError); _reader.raiseError(mismatchError);
return; return;
} else if (!coord(track[i])) { } else if (!coord(track[i])) {
_reader.raiseError("Invalid coordinates."); _reader.raiseError("Invalid coordinates");
return; return;
} }
i++; i++;
@ -329,7 +329,7 @@ bool KMLParser::parse()
if (_reader.name() == "kml") if (_reader.name() == "kml")
kml(); kml();
else else
_reader.raiseError("Not a KML file."); _reader.raiseError("Not a KML file");
} }
return !_reader.error(); return !_reader.error();

View File

@ -13,7 +13,7 @@ qreal TCXParser::number()
bool res; bool res;
qreal ret = _reader.readElementText().toDouble(&res); qreal ret = _reader.readElementText().toDouble(&res);
if (!res) if (!res)
_reader.raiseError(QString("Invalid %1.").arg( _reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString())); _reader.name().toString()));
return ret; return ret;
@ -24,7 +24,7 @@ QDateTime TCXParser::time()
QDateTime d = QDateTime::fromString(_reader.readElementText(), QDateTime d = QDateTime::fromString(_reader.readElementText(),
Qt::ISODate); Qt::ISODate);
if (!d.isValid()) if (!d.isValid())
_reader.raiseError(QString("Invalid %1.").arg( _reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString())); _reader.name().toString()));
return d; return d;
@ -40,13 +40,13 @@ Coordinates TCXParser::position()
if (_reader.name() == "LatitudeDegrees") { if (_reader.name() == "LatitudeDegrees") {
val = _reader.readElementText().toDouble(&res); val = _reader.readElementText().toDouble(&res);
if (!res || (val < -90.0 || val > 90.0)) if (!res || (val < -90.0 || val > 90.0))
_reader.raiseError("Invalid LatitudeDegrees."); _reader.raiseError("Invalid LatitudeDegrees");
else else
pos.setLat(val); pos.setLat(val);
} else if (_reader.name() == "LongitudeDegrees") { } else if (_reader.name() == "LongitudeDegrees") {
val = _reader.readElementText().toDouble(&res); val = _reader.readElementText().toDouble(&res);
if (!res || (val < -180.0 || val > 180.0)) if (!res || (val < -180.0 || val > 180.0))
_reader.raiseError("Invalid LongitudeDegrees."); _reader.raiseError("Invalid LongitudeDegrees");
else else
pos.setLon(val); pos.setLon(val);
} else } else
@ -186,7 +186,7 @@ bool TCXParser::parse()
if (_reader.name() == "TrainingCenterDatabase") if (_reader.name() == "TrainingCenterDatabase")
tcx(); tcx();
else else
_reader.raiseError("Not a TCX file."); _reader.raiseError("Not a TCX file");
} }
return !_reader.error(); return !_reader.error();