From 932f817496eb00728faa84aa57d7286f1e66e18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 12 Feb 2016 20:12:37 +0100 Subject: [PATCH] Improved error handling Added file filters to open dialogs --- lang/gpxsee_cs.ts | 216 ++++++++++++++++++++++++---------------------- src/gui.cpp | 21 +++-- src/gui.h | 2 +- src/map.cpp | 2 +- src/map.h | 3 +- src/maplist.cpp | 4 +- src/maplist.h | 4 +- src/poi.cpp | 17 ++++ 8 files changed, 149 insertions(+), 120 deletions(-) diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts index c053fce8..6d67b30b 100644 --- a/lang/gpxsee_cs.ts +++ b/lang/gpxsee_cs.ts @@ -1,57 +1,57 @@ - + ElevationGraph - + Distance Vzdálenost - + Elevation Výška - - + + km km - - + + m m - + Ascent Stoupání - + Descent Klesání - + Minimum Minimum - + mi mi - + ft ft - + Maximum Maximum @@ -59,326 +59,336 @@ GUI - + About Qt O Qt - + GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese - + Open file Otevřít soubor - + Save as Uložit jako - + Open POI file Otevřít POI soubor - + Open Otevřít - + Quit Ukončit - - + + Keyboard controls Ovládací klávesy - + Save Uložit - + Close Zavřít - + Reload Znovu načíst - + Show Zobrazit - - + + File Soubor - - + + Data sources Zdroje dat - + Load POI file Nahrát POI soubor - + Show POIs Zobrazit POI - + Show map Zobrazit mapu - + Show graphs Zobrazovat grafy - + Show toolbars Zobrazovat nástrojové lišty - + Metric Metrické - + Imperial Imperiální - + Next Následující - + Previous Předchozí - + Last Poslední - + First První - + Map Mapa - + POI POI - + Settings Nastavení - + Units Jednotky - + Help Nápověda - + Elevation Výška - + Speed Rychlost - + Next file Následující soubor - + Previous file Předchozí soubor - + First file První soubor - + Last file Poslední soubor - + Append modifier Modifikátor nahradit/přidat - + Map (tiles) source URLs are read on program startup from the following file: URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru: - + The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like: Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad: - + To make GPXSee load a POI file automatically on startup, add the file to the following directory: POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře: - - + + GPX files (*.gpx);;All files (*) + soubory GPX (*.gpx);;všechny soubory (*) + + + + Line: %1 Řádka: %1 - - + + GPX files (*.gpx);;CSV files (*.csv);;All files (*) + soubory GPX (*.gpx);;soubory CSV (*.csv);;všechny soubory (*) + + + + mi mi - - - - + + + + ft ft - - + + Maximum Maximum - - + + Minimum Minimum - - + + About GPXSee O aplikaci GPXSee - + Navigation Navigace - + GPX viewer and analyzer Prohlížeč a analyzátor GPX - + Map sources Mapové zdroje - + POIs POI body - - + + Distance Vzdálenost - - + + Time Čas - - + + Ascent Stoupání - - - - + + + + m m - - + + Descent Klesání - + %1 tracks Počet tras: %1 - - + + km km - - + + Error Chyba - + Error loading GPX file: %1 Soubor GPX nelze otevřít: %1 - + Error loading POI file: %1 Soubor POI nelze otevřít: @@ -411,44 +421,44 @@ SpeedGraph - + Distance Vzdálenost - + Speed Rychlost - - + + km - - + + km/h km/h - + Average Průměr - + Maximum Maximum - + mi mi - + mi/h mi/h diff --git a/src/gui.cpp b/src/gui.cpp index d6c00b02..422d5e28 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -35,7 +35,7 @@ static QString timeSpan(qreal time) } -GUI::GUI() +GUI::GUI(QWidget *parent) : QMainWindow(parent) { loadFiles(); @@ -75,18 +75,15 @@ GUI::GUI() void GUI::loadFiles() { // Maps - _maps = MapList::load(QString("%1/" MAP_LIST_FILE).arg(QDir::homePath())); - _maps += MapList::load(":/maps.txt"); + _maps = MapList::load(this, QString("%1/" MAP_LIST_FILE) + .arg(QDir::homePath())); + _maps += MapList::load(this, ":/maps.txt"); // POI files QDir dir(QString("%1/" POI_DIR).arg(QDir::homePath())); QFileInfoList list = dir.entryInfoList(QStringList(), QDir::Files); - for (int i = 0; i < list.size(); ++i) { - if (!_poi.loadFile(list.at(i).absoluteFilePath())) - fprintf(stderr, "Error loading POI file: %s: %s", - qPrintable(list.at(i).absoluteFilePath()), - qPrintable(_poi.errorString())); - } + for (int i = 0; i < list.size(); ++i) + _poi.loadFile(list.at(i).absoluteFilePath()); } void GUI::createMapActions() @@ -407,7 +404,8 @@ void GUI::dataSources() void GUI::openFile() { - QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file")); + QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"), + QString(), tr("GPX files (*.gpx);;All files (*)")); QStringList list = files; for (QStringList::Iterator it = list.begin(); it != list.end(); it++) @@ -466,7 +464,8 @@ bool GUI::loadFile(const QString &fileName) void GUI::openPOIFile() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open POI file")); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open POI file"), + QString(), tr("GPX files (*.gpx);;CSV files (*.csv);;All files (*)")); if (!fileName.isEmpty()) { if (!_poi.loadFile(fileName)) { diff --git a/src/gui.h b/src/gui.h index 27156b79..031df47d 100644 --- a/src/gui.h +++ b/src/gui.h @@ -23,7 +23,7 @@ class GUI : public QMainWindow Q_OBJECT public: - GUI(); + GUI(QWidget *parent = 0); bool openFile(const QString &fileName); diff --git a/src/map.cpp b/src/map.cpp index b228e0b0..abd587ba 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -6,7 +6,7 @@ #include "map.h" -Map::Map(const QString &name, const QString &url, QObject *parent) +Map::Map(QObject *parent, const QString &name, const QString &url) : QObject(parent) { _name = name; diff --git a/src/map.h b/src/map.h index 2436ffb8..df0917ce 100644 --- a/src/map.h +++ b/src/map.h @@ -28,7 +28,8 @@ signals: void loaded(); public: - Map(const QString &name, const QString &url, QObject *parent = 0); + Map(QObject *parent = 0, const QString &name = QString(), + const QString &url = QString()); const QString &name() const {return _name;} void loadTiles(QList &list); diff --git a/src/maplist.cpp b/src/maplist.cpp index d35631ff..de65739a 100644 --- a/src/maplist.cpp +++ b/src/maplist.cpp @@ -4,7 +4,7 @@ #include "maplist.h" -QList MapList::load(const QString &fileName) +QList MapList::load(QObject *parent, const QString &fileName) { QList mapList; QFileInfo fi(fileName); @@ -33,7 +33,7 @@ QList MapList::load(const QString &fileName) QByteArray ba1 = list[0].trimmed(); QByteArray ba2 = list[1].trimmed(); - mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()), + mapList.append(new Map(parent, QString::fromUtf8(ba1.data(), ba1.size()), QString::fromLatin1(ba2.data(), ba2.size()))); } diff --git a/src/maplist.h b/src/maplist.h index eb864023..bb505da1 100644 --- a/src/maplist.h +++ b/src/maplist.h @@ -3,13 +3,15 @@ #include #include +#include class Map; class MapList { public: - static QList load(const QString &fileName); + static QList load(QObject *parent = 0, + const QString &fileName = QString()); }; #endif // MAPLIST_H diff --git a/src/poi.cpp b/src/poi.cpp index f276ebfb..d9e554a6 100644 --- a/src/poi.cpp +++ b/src/poi.cpp @@ -10,14 +10,31 @@ bool POI::loadFile(const QString &fileName) { + QString error; + int errorLine; + _error.clear(); _errorLine = 0; + if (loadCSVFile(fileName)) return true; + else { + error = _error; + errorLine = _errorLine; + } if (loadGPXFile(fileName)) return true; + fprintf(stderr, "Error loading POI file: %s:\n", qPrintable(fileName)); + fprintf(stderr, "CSV: line %d: %s\n", errorLine, qPrintable(error)); + fprintf(stderr, "GPX: line %d: %s\n", _errorLine, qPrintable(_error)); + + if (errorLine > _errorLine) { + _errorLine = errorLine; + _error = error; + } + return false; }