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)
{
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);

View File

@ -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();
}

View File

@ -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<QByteArray> 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();
}

View File

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