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

Improved error handling.

Code cleanup.
This commit is contained in:
Martin Tůma 2016-10-11 00:19:42 +02:00
parent afd87c6fa2
commit 12d5dcc78c
4 changed files with 15 additions and 15 deletions

View File

@ -673,12 +673,13 @@ void GUI::openPOIFile()
bool GUI::openPOIFile(const QString &fileName) bool GUI::openPOIFile(const QString &fileName)
{ {
if (fileName.isEmpty()) if (fileName.isEmpty() || _poi->files().contains(fileName))
return false; return false;
if (!_poi->loadFile(fileName)) { if (!_poi->loadFile(fileName)) {
QString error = tr("Error loading POI file:\n%1") QString error = fileName + QString("\n\n")
.arg(_poi->errorString()) + QString("\n"); + tr("Error loading POI file:\n%1").arg(_poi->errorString())
+ QString("\n");
if (_poi->errorLine()) if (_poi->errorLine())
error.append(tr("Line: %1").arg(_poi->errorLine())); error.append(tr("Line: %1").arg(_poi->errorLine()));
QMessageBox::critical(this, tr("Error"), error); QMessageBox::critical(this, tr("Error"), error);

View File

@ -315,12 +315,12 @@ void PathView::rescale(qreal scale)
void PathView::setPOI(POI *poi) void PathView::setPOI(POI *poi)
{ {
if (_poi) if (_poi)
disconnect(_poi, SIGNAL(reloadRequired()), this, SLOT(updatePOI())); disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
_poi = poi; _poi = poi;
if (_poi) if (_poi)
connect(_poi, SIGNAL(reloadRequired()), this, SLOT(updatePOI())); connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
updatePOI(); updatePOI();
} }

View File

@ -22,16 +22,15 @@ bool POI::loadFile(const QString &fileName)
_error.clear(); _error.clear();
_errorLine = 0; _errorLine = 0;
if (loadCSVFile(fileName)) { if (loadCSVFile(fileName)) {
emit reloadRequired(); emit pointsChanged();
return true; return true;
} else { } else {
error = _error; error = _error;
errorLine = _errorLine; errorLine = _errorLine;
} }
if (loadGPXFile(fileName)) { if (loadGPXFile(fileName)) {
emit reloadRequired(); emit pointsChanged();
return true; return true;
} }
@ -99,20 +98,20 @@ bool POI::loadCSVFile(const QString &fileName)
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) {
_error = "Parse error"; _error = "Parse error.";
_errorLine = ln; _errorLine = ln;
return false; return false;
} }
qreal lat = list[0].trimmed().toDouble(&ret); qreal lat = list[0].trimmed().toDouble(&ret);
if (!ret) { if (!ret) {
_error = "Invalid latitude"; _error = "Invalid latitude.";
_errorLine = ln; _errorLine = ln;
return false; return false;
} }
qreal lon = list[1].trimmed().toDouble(&ret); qreal lon = list[1].trimmed().toDouble(&ret);
if (!ret) { if (!ret) {
_error = "Invalid longitude"; _error = "Invalid longitude.";
_errorLine = ln; _errorLine = ln;
return false; return false;
} }
@ -251,7 +250,7 @@ void POI::enableFile(const QString &fileName, bool enable)
} }
} }
emit reloadRequired(); emit pointsChanged();
} }
void POI::clear() void POI::clear()
@ -261,12 +260,12 @@ void POI::clear()
_files.clear(); _files.clear();
_indexes.clear(); _indexes.clear();
emit reloadRequired(); emit pointsChanged();
} }
void POI::setRadius(qreal radius) void POI::setRadius(qreal radius)
{ {
_radius = radius; _radius = radius;
emit reloadRequired(); emit pointsChanged();
} }

View File

@ -34,7 +34,7 @@ public:
void clear(); void clear();
signals: signals:
void reloadRequired(); void pointsChanged();
private: private:
typedef RTree<size_t, qreal, 2> POITree; typedef RTree<size_t, qreal, 2> POITree;