From 12d5dcc78c9b036aa34c2420bb75c4c1a6776ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 11 Oct 2016 00:19:42 +0200 Subject: [PATCH] Improved error handling. Code cleanup. --- src/gui.cpp | 7 ++++--- src/pathview.cpp | 4 ++-- src/poi.cpp | 17 ++++++++--------- src/poi.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index abd96d8c..83f7e955 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -673,12 +673,13 @@ void GUI::openPOIFile() bool GUI::openPOIFile(const QString &fileName) { - if (fileName.isEmpty()) + if (fileName.isEmpty() || _poi->files().contains(fileName)) return false; if (!_poi->loadFile(fileName)) { - QString error = tr("Error loading POI file:\n%1") - .arg(_poi->errorString()) + QString("\n"); + QString error = fileName + QString("\n\n") + + tr("Error loading POI file:\n%1").arg(_poi->errorString()) + + QString("\n"); if (_poi->errorLine()) error.append(tr("Line: %1").arg(_poi->errorLine())); QMessageBox::critical(this, tr("Error"), error); diff --git a/src/pathview.cpp b/src/pathview.cpp index 1462f1f8..4f985437 100644 --- a/src/pathview.cpp +++ b/src/pathview.cpp @@ -315,12 +315,12 @@ void PathView::rescale(qreal scale) void PathView::setPOI(POI *poi) { if (_poi) - disconnect(_poi, SIGNAL(reloadRequired()), this, SLOT(updatePOI())); + disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI())); _poi = poi; if (_poi) - connect(_poi, SIGNAL(reloadRequired()), this, SLOT(updatePOI())); + connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI())); updatePOI(); } diff --git a/src/poi.cpp b/src/poi.cpp index 9db28388..961cde11 100644 --- a/src/poi.cpp +++ b/src/poi.cpp @@ -22,16 +22,15 @@ bool POI::loadFile(const QString &fileName) _error.clear(); _errorLine = 0; - if (loadCSVFile(fileName)) { - emit reloadRequired(); + emit pointsChanged(); return true; } else { error = _error; errorLine = _errorLine; } if (loadGPXFile(fileName)) { - emit reloadRequired(); + emit pointsChanged(); return true; } @@ -99,20 +98,20 @@ bool POI::loadCSVFile(const QString &fileName) QByteArray line = file.readLine(); QList list = line.split(','); if (list.size() < 3) { - _error = "Parse error"; + _error = "Parse error."; _errorLine = ln; return false; } qreal lat = list[0].trimmed().toDouble(&ret); if (!ret) { - _error = "Invalid latitude"; + _error = "Invalid latitude."; _errorLine = ln; return false; } qreal lon = list[1].trimmed().toDouble(&ret); if (!ret) { - _error = "Invalid longitude"; + _error = "Invalid longitude."; _errorLine = ln; return false; } @@ -251,7 +250,7 @@ void POI::enableFile(const QString &fileName, bool enable) } } - emit reloadRequired(); + emit pointsChanged(); } void POI::clear() @@ -261,12 +260,12 @@ void POI::clear() _files.clear(); _indexes.clear(); - emit reloadRequired(); + emit pointsChanged(); } void POI::setRadius(qreal radius) { _radius = radius; - emit reloadRequired(); + emit pointsChanged(); } diff --git a/src/poi.h b/src/poi.h index dae34f98..73f6fcda 100644 --- a/src/poi.h +++ b/src/poi.h @@ -34,7 +34,7 @@ public: void clear(); signals: - void reloadRequired(); + void pointsChanged(); private: typedef RTree POITree;