mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Improved error handling
Added file filters to open dialogs
This commit is contained in:
21
src/gui.cpp
21
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)) {
|
||||
|
@ -23,7 +23,7 @@ class GUI : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GUI();
|
||||
GUI(QWidget *parent = 0);
|
||||
|
||||
bool openFile(const QString &fileName);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Tile> &list);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
QList<Map*> MapList::load(const QString &fileName)
|
||||
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
||||
{
|
||||
QList<Map*> mapList;
|
||||
QFileInfo fi(fileName);
|
||||
@ -33,7 +33,7 @@ QList<Map*> 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())));
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,15 @@
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
class Map;
|
||||
|
||||
class MapList
|
||||
{
|
||||
public:
|
||||
static QList<Map*> load(const QString &fileName);
|
||||
static QList<Map*> load(QObject *parent = 0,
|
||||
const QString &fileName = QString());
|
||||
};
|
||||
|
||||
#endif // MAPLIST_H
|
||||
|
17
src/poi.cpp
17
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user