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