mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Some more error handling fixes.
This commit is contained in:
parent
78fb5c1547
commit
640829d89d
@ -2,11 +2,6 @@
|
||||
#include "wgs84.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
bool Coordinates::isValid() const
|
||||
{
|
||||
return (_lon >= -180.0 && _lon <= 180.0 && _lat >= -90.0 && _lat <= 90.0)
|
||||
? true : false;
|
||||
}
|
||||
|
||||
qreal Coordinates::distanceTo(const Coordinates &c) const
|
||||
{
|
||||
|
@ -19,7 +19,12 @@ public:
|
||||
qreal lon() const {return _lon;}
|
||||
qreal lat() const {return _lat;}
|
||||
|
||||
bool isValid() const;
|
||||
bool isNull() const
|
||||
{return (std::isnan(_lon) || std::isnan(_lat)) ? true : false;}
|
||||
bool isValid() const
|
||||
{return (_lon >= -180.0 && _lon <= 180.0 && _lat >= -90.0
|
||||
&& _lat <= 90.0) ? true : false;}
|
||||
|
||||
qreal distanceTo(const Coordinates &c) const;
|
||||
|
||||
QPointF toMercator() const;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "csvparser.h"
|
||||
|
||||
bool CSVParser::loadFile(QIODevice *device)
|
||||
bool CSVParser::loadFile(QFile *file)
|
||||
{
|
||||
bool res;
|
||||
int ln = 1;
|
||||
@ -8,8 +8,8 @@ bool CSVParser::loadFile(QIODevice *device)
|
||||
_errorLine = 0;
|
||||
_errorString.clear();
|
||||
|
||||
while (!device->atEnd()) {
|
||||
QByteArray line = device->readLine();
|
||||
while (!file->atEnd()) {
|
||||
QByteArray line = file->readLine();
|
||||
QList<QByteArray> list = line.split(',');
|
||||
if (list.size() < 3) {
|
||||
_errorString = "Parse error.";
|
||||
|
@ -11,7 +11,7 @@ public:
|
||||
{_errorLine = 0;}
|
||||
~CSVParser() {}
|
||||
|
||||
bool loadFile(QIODevice *device);
|
||||
bool loadFile(QFile *file);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
|
@ -235,10 +235,10 @@ bool GPXParser::parse()
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool GPXParser::loadFile(QIODevice *device)
|
||||
bool GPXParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(device);
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~GPXParser() {}
|
||||
|
||||
bool loadFile(QIODevice *device);
|
||||
bool loadFile(QFile *file);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
|
||||
|
@ -220,6 +220,9 @@ void KMLParser::point(Waypoint &waypoint)
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (waypoint.coordinates().isNull())
|
||||
_reader.raiseError("Missing Point coordinates.");
|
||||
}
|
||||
|
||||
void KMLParser::Track(TrackData &track)
|
||||
@ -332,10 +335,10 @@ bool KMLParser::parse()
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool KMLParser::loadFile(QIODevice *device)
|
||||
bool KMLParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(device);
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~KMLParser() {}
|
||||
|
||||
bool loadFile(QIODevice *device);
|
||||
bool loadFile(QFile *file);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
|
||||
|
@ -3,11 +3,11 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QFile>
|
||||
#include "trackdata.h"
|
||||
#include "routedata.h"
|
||||
#include "waypoint.h"
|
||||
|
||||
class QIODevice;
|
||||
|
||||
class Parser
|
||||
{
|
||||
@ -17,7 +17,7 @@ public:
|
||||
_waypoints(waypoints) {}
|
||||
virtual ~Parser() {}
|
||||
|
||||
virtual bool loadFile(QIODevice *device) = 0;
|
||||
virtual bool loadFile(QFile *file) = 0;
|
||||
virtual QString errorString() const = 0;
|
||||
virtual int errorLine() const = 0;
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
#include "tcxparser.h"
|
||||
|
||||
|
||||
void TCXParser::warning(const char *text)
|
||||
{
|
||||
QFile *file = static_cast<QFile *>(_reader.device());
|
||||
fprintf(stderr, "%s:%lld: %s\n", qPrintable(file->fileName()),
|
||||
_reader.lineNumber(), text);
|
||||
}
|
||||
|
||||
qreal TCXParser::number()
|
||||
{
|
||||
bool res;
|
||||
@ -87,8 +94,12 @@ void TCXParser::trackpoints(TrackData &track)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Trackpoint") {
|
||||
track.append(Trackpoint());
|
||||
trackpointData(track.back());
|
||||
Trackpoint t;
|
||||
trackpointData(t);
|
||||
if (!t.coordinates().isNull())
|
||||
track.append(t);
|
||||
else
|
||||
warning("Missing Trackpoint coordinates");
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
@ -114,8 +125,12 @@ void TCXParser::course(TrackData &track)
|
||||
else if (_reader.name() == "Notes")
|
||||
track.setDescription(_reader.readElementText());
|
||||
else if (_reader.name() == "CoursePoint") {
|
||||
_waypoints.append(Waypoint());
|
||||
waypointData(_waypoints.back());
|
||||
Waypoint w;
|
||||
waypointData(w);
|
||||
if (!w.coordinates().isNull())
|
||||
_waypoints.append(w);
|
||||
else
|
||||
warning("Missing Trackpoint coordinates");
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
@ -177,10 +192,10 @@ bool TCXParser::parse()
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool TCXParser::loadFile(QIODevice *device)
|
||||
bool TCXParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(device);
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~TCXParser() {}
|
||||
|
||||
bool loadFile(QIODevice *device);
|
||||
bool loadFile(QFile *file);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
|
||||
@ -31,6 +31,8 @@ private:
|
||||
qreal number();
|
||||
QDateTime time();
|
||||
|
||||
void warning(const char *text);
|
||||
|
||||
QXmlStreamReader _reader;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user