mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Improved file loading performance
Better error reporting
This commit is contained in:
parent
c425b3868d
commit
1744764025
@ -14,7 +14,6 @@ public:
|
||||
bool loadFile(QIODevice *device);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
const char *name() const {return "CSV";}
|
||||
|
||||
private:
|
||||
QString _errorString;
|
||||
|
61
src/data.cpp
61
src/data.cpp
@ -1,4 +1,5 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QLineF>
|
||||
#include "gpxparser.h"
|
||||
#include "tcxparser.h"
|
||||
@ -9,16 +10,22 @@
|
||||
|
||||
Data::Data() : _errorLine(0)
|
||||
{
|
||||
_parsers << new GPXParser(_track_data, _route_data, _waypoint_data);
|
||||
_parsers << new TCXParser(_track_data, _route_data, _waypoint_data);
|
||||
_parsers << new KMLParser(_track_data, _route_data, _waypoint_data);
|
||||
_parsers << new CSVParser(_track_data, _route_data, _waypoint_data);
|
||||
_parsers.insert("gpx", new GPXParser(_track_data, _route_data,
|
||||
_waypoint_data));
|
||||
_parsers.insert("tcx", new TCXParser(_track_data, _route_data,
|
||||
_waypoint_data));
|
||||
_parsers.insert("kml", new KMLParser(_track_data, _route_data,
|
||||
_waypoint_data));
|
||||
_parsers.insert("csv", new CSVParser(_track_data, _route_data,
|
||||
_waypoint_data));
|
||||
}
|
||||
|
||||
Data::~Data()
|
||||
{
|
||||
for(int i = 0; i < _parsers.count(); i++)
|
||||
delete _parsers.at(i);
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
delete it.value();
|
||||
|
||||
for (int i = 0; i < _tracks.count(); i++)
|
||||
delete _tracks.at(i);
|
||||
@ -26,9 +33,19 @@ Data::~Data()
|
||||
delete _routes.at(i);
|
||||
}
|
||||
|
||||
void Data::createData()
|
||||
{
|
||||
for (int i = 0; i < _track_data.count(); i++)
|
||||
_tracks.append(new Track(_track_data.at(i)));
|
||||
for (int i = 0; i < _route_data.count(); i++)
|
||||
_routes.append(new Route(_route_data.at(i)));
|
||||
}
|
||||
|
||||
bool Data::loadFile(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
QFileInfo fi(fileName);
|
||||
|
||||
|
||||
_errorString.clear();
|
||||
_errorLine = 0;
|
||||
@ -38,25 +55,31 @@ bool Data::loadFile(const QString &fileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _parsers.size(); i++) {
|
||||
if (_parsers.at(i)->loadFile(&file)) {
|
||||
for (int i = 0; i < _track_data.count(); i++)
|
||||
_tracks.append(new Track(_track_data.at(i)));
|
||||
for (int i = 0; i < _route_data.count(); i++)
|
||||
_routes.append(new Route(_route_data.at(i)));
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
if ((it = _parsers.find(fi.suffix().toLower())) != _parsers.end()) {
|
||||
if (it.value()->loadFile(&file)) {
|
||||
createData();
|
||||
return true;
|
||||
}
|
||||
|
||||
_errorLine = it.value()->errorLine();
|
||||
_errorString = it.value()->errorString();
|
||||
} else {
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++) {
|
||||
if (it.value()->loadFile(&file)) {
|
||||
createData();
|
||||
return true;
|
||||
}
|
||||
file.reset();
|
||||
}
|
||||
|
||||
fprintf(stderr, "Error loading data file: %s:\n", qPrintable(fileName));
|
||||
for (int i = 0; i < _parsers.size(); i++) {
|
||||
fprintf(stderr, "%s: line %d: %s\n", _parsers.at(i)->name(),
|
||||
_parsers.at(i)->errorLine(), qPrintable(_parsers.at(i)->errorString()));
|
||||
if (_parsers.at(i)->errorLine() > _errorLine) {
|
||||
_errorLine = _parsers.at(i)->errorLine();
|
||||
_errorString = _parsers.at(i)->errorString();
|
||||
}
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
fprintf(stderr, "%s: line %d: %s\n", qPrintable(it.key()),
|
||||
it.value()->errorLine(), qPrintable(it.value()->errorString()));
|
||||
|
||||
_errorLine = 0;
|
||||
_errorString = "Unknown format";
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
#include "waypoint.h"
|
||||
@ -26,9 +27,11 @@ public:
|
||||
const QList<Waypoint> &waypoints() const {return _waypoint_data;}
|
||||
|
||||
private:
|
||||
void createData();
|
||||
|
||||
QString _errorString;
|
||||
int _errorLine;
|
||||
QList<Parser*> _parsers;
|
||||
QHash<QString, Parser*> _parsers;
|
||||
|
||||
QList<Track*> _tracks;
|
||||
QList<Route*> _routes;
|
||||
|
@ -17,7 +17,6 @@ public:
|
||||
bool loadFile(QIODevice *device);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
const char *name() const {return "GPX";}
|
||||
|
||||
private:
|
||||
enum DataType {
|
||||
|
@ -17,7 +17,6 @@ public:
|
||||
bool loadFile(QIODevice *device);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
const char *name() const {return "KML";}
|
||||
|
||||
private:
|
||||
bool parse();
|
||||
|
@ -19,7 +19,6 @@ public:
|
||||
virtual bool loadFile(QIODevice *device) = 0;
|
||||
virtual QString errorString() const = 0;
|
||||
virtual int errorLine() const = 0;
|
||||
virtual const char *name() const = 0;
|
||||
|
||||
protected:
|
||||
QList<QVector<Trackpoint> > &_tracks;
|
||||
|
@ -17,7 +17,6 @@ public:
|
||||
bool loadFile(QIODevice *device);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
const char *name() const {return "TCX";}
|
||||
|
||||
private:
|
||||
bool parse();
|
||||
|
Loading…
Reference in New Issue
Block a user