1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Yet another refactoring

This commit is contained in:
Martin Tůma 2016-02-19 21:42:54 +01:00
parent 59d8b3cc77
commit ba4ac9fe51
12 changed files with 39 additions and 39 deletions

View File

@ -19,15 +19,15 @@ public:
int trackCount() const {return _tracks.count();} int trackCount() const {return _tracks.count();}
Track track(int i) const {return Track(_tracks.at(i));} Track track(int i) const {return Track(_tracks.at(i));}
const QList<WayPoint> &waypoints() const {return _waypoints;} const QList<Waypoint> &waypoints() const {return _waypoints;}
private: private:
Parser _parser; Parser _parser;
QString _error; QString _error;
int _errorLine; int _errorLine;
QList<QVector<TrackPoint> > _tracks; QList<QVector<Trackpoint> > _tracks;
QList<WayPoint> _waypoints; QList<Waypoint> _waypoints;
}; };
#endif // GPX_H #endif // GPX_H

View File

@ -64,7 +64,7 @@ void Parser::trackPoints()
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") { if (_reader.name() == "trkpt") {
_track->append(TrackPoint()); _track->append(Trackpoint());
handleTrekPointAttributes(_reader.attributes()); handleTrekPointAttributes(_reader.attributes());
trackPointData(); trackPointData();
} else } else
@ -96,11 +96,11 @@ void Parser::gpx()
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "trk") { if (_reader.name() == "trk") {
_tracks.append(QVector<TrackPoint>()); _tracks.append(QVector<Trackpoint>());
_track = &_tracks.back(); _track = &_tracks.back();
track(); track();
} else if (_reader.name() == "wpt") { } else if (_reader.name() == "wpt") {
_waypoints.append(WayPoint()); _waypoints.append(Waypoint());
handleWayPointAttributes(_reader.attributes()); handleWayPointAttributes(_reader.attributes());
wayPointData(); wayPointData();
} else } else

View File

@ -11,7 +11,7 @@
class Parser class Parser
{ {
public: public:
Parser(QList<QVector<TrackPoint> > &tracks, QList<WayPoint> &waypoints) Parser(QList<QVector<Trackpoint> > &tracks, QList<Waypoint> &waypoints)
: _tracks(tracks), _waypoints(waypoints) {_track = 0;} : _tracks(tracks), _waypoints(waypoints) {_track = 0;}
bool loadFile(QIODevice *device); bool loadFile(QIODevice *device);
QString errorString() const {return _reader.errorString();} QString errorString() const {return _reader.errorString();}
@ -33,9 +33,9 @@ private:
void handleExtensionData(QStringRef element, const QString &value); void handleExtensionData(QStringRef element, const QString &value);
QXmlStreamReader _reader; QXmlStreamReader _reader;
QList<QVector<TrackPoint> > &_tracks; QList<QVector<Trackpoint> > &_tracks;
QList<WayPoint> &_waypoints; QList<Waypoint> &_waypoints;
QVector<TrackPoint> *_track; QVector<Trackpoint> *_track;
}; };
#endif // PARSER_H #endif // PARSER_H

View File

@ -43,7 +43,7 @@ bool POI::loadGPXFile(const QString &fileName)
if (gpx.loadFile(fileName)) { if (gpx.loadFile(fileName)) {
for (int i = 0; i < gpx.waypoints().size(); i++) for (int i = 0; i < gpx.waypoints().size(); i++)
_data.append(WayPoint( _data.append(Waypoint(
ll2mercator(gpx.waypoints().at(i).coordinates()), ll2mercator(gpx.waypoints().at(i).coordinates()),
gpx.waypoints().at(i).description())); gpx.waypoints().at(i).description()));
@ -97,7 +97,7 @@ bool POI::loadCSVFile(const QString &fileName)
} }
QByteArray ba = list[2].trimmed(); QByteArray ba = list[2].trimmed();
_data.append(WayPoint(ll2mercator(QPointF(lon, lat)), _data.append(Waypoint(ll2mercator(QPointF(lon, lat)),
QString::fromUtf8(ba.data(), ba.size()))); QString::fromUtf8(ba.data(), ba.size())));
ln++; ln++;
} }
@ -120,9 +120,9 @@ static bool cb(size_t data, void* context)
return true; return true;
} }
QVector<WayPoint> POI::points(const QVector<QPointF> &path, qreal radius) const QVector<Waypoint> POI::points(const QVector<QPointF> &path, qreal radius) const
{ {
QVector<WayPoint> ret; QVector<Waypoint> ret;
QSet<int> set; QSet<int> set;
qreal min[2], max[2]; qreal min[2], max[2];

View File

@ -15,7 +15,7 @@ public:
QString errorString() const {return _error;} QString errorString() const {return _error;}
int errorLine() const {return _errorLine;} int errorLine() const {return _errorLine;}
QVector<WayPoint> points(const QVector<QPointF> &path, QVector<Waypoint> points(const QVector<QPointF> &path,
qreal radius = 0.01) const; qreal radius = 0.01) const;
void clear(); void clear();
@ -27,7 +27,7 @@ private:
bool loadGPXFile(const QString &fileName); bool loadGPXFile(const QString &fileName);
POITree _tree; POITree _tree;
QVector<WayPoint> _data; QVector<Waypoint> _data;
QString _error; QString _error;
int _errorLine; int _errorLine;

View File

@ -8,7 +8,7 @@
class Track class Track
{ {
public: public:
Track(const QVector<TrackPoint> &data) : _data(data) {} Track(const QVector<Trackpoint> &data) : _data(data) {}
void elevationGraph(QVector<QPointF> &graph) const; void elevationGraph(QVector<QPointF> &graph) const;
void speedGraph(QVector<QPointF> &graph) const; void speedGraph(QVector<QPointF> &graph) const;
@ -18,7 +18,7 @@ public:
QDateTime date() const; QDateTime date() const;
private: private:
const QVector<TrackPoint> &_data; const QVector<Trackpoint> &_data;
}; };
#endif // TRACK_H #endif // TRACK_H

View File

@ -4,7 +4,7 @@
#include <QPointF> #include <QPointF>
#include <QDateTime> #include <QDateTime>
struct TrackPoint struct Trackpoint
{ {
QPointF coordinates; QPointF coordinates;
QDateTime timestamp; QDateTime timestamp;
@ -12,7 +12,7 @@ struct TrackPoint
qreal geoidheight; qreal geoidheight;
qreal speed; qreal speed;
TrackPoint() {elevation = 0; geoidheight = 0; speed = -1;} Trackpoint() {elevation = 0; geoidheight = 0; speed = -1;}
}; };
#endif // TRACKPOINT_H #endif // TRACKPOINT_H

View File

@ -156,7 +156,7 @@ void TrackView::rescale(qreal scale)
_trackPaths.at(i)->setPen(pen); _trackPaths.at(i)->setPen(pen);
} }
QHash<WayPoint, WayPointItem*>::const_iterator it, jt; QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) { for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
it.value()->setPos(QPointF(it.value()->entry().coordinates().x() it.value()->setPos(QPointF(it.value()->entry().coordinates().x()
* 1.0/scale, -it.value()->entry().coordinates().y() * 1.0/scale)); * 1.0/scale, -it.value()->entry().coordinates().y() * 1.0/scale));
@ -176,19 +176,19 @@ void TrackView::rescale(qreal scale)
void TrackView::loadPOI(const POI &poi) void TrackView::loadPOI(const POI &poi)
{ {
QHash<WayPoint, WayPointItem*>::const_iterator it,jt; QHash<Waypoint, WaypointItem*>::const_iterator it,jt;
if (!_tracks.size()) if (!_tracks.size())
return; return;
for (int i = 0; i < _tracks.size(); i++) { for (int i = 0; i < _tracks.size(); i++) {
QVector<WayPoint> p = poi.points(_tracks.at(i)); QVector<Waypoint> p = poi.points(_tracks.at(i));
for (int i = 0; i < p.size(); i++) { for (int i = 0; i < p.size(); i++) {
if (_pois.contains(p.at(i))) if (_pois.contains(p.at(i)))
continue; continue;
WayPointItem *pi = new WayPointItem(p.at(i)); WaypointItem *pi = new WaypointItem(p.at(i));
pi->setPos(p.at(i).coordinates().x() * 1.0/_scale, pi->setPos(p.at(i).coordinates().x() * 1.0/_scale,
-p.at(i).coordinates().y() * 1.0/_scale); -p.at(i).coordinates().y() * 1.0/_scale);
pi->setZValue(1); pi->setZValue(1);
@ -298,7 +298,7 @@ enum QPrinter::Orientation TrackView::orientation() const
void TrackView::clearPOI() void TrackView::clearPOI()
{ {
QHash<WayPoint, WayPointItem*>::const_iterator it; QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) { for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
_scene->removeItem(it.value()); _scene->removeItem(it.value());

View File

@ -13,7 +13,7 @@
class GPX; class GPX;
class POI; class POI;
class Map; class Map;
class WayPointItem; class WaypointItem;
class MarkerItem; class MarkerItem;
class ScaleItem; class ScaleItem;
@ -61,7 +61,7 @@ private:
QList<QVector<QPointF> > _tracks; QList<QVector<QPointF> > _tracks;
QList<QGraphicsPathItem*> _trackPaths; QList<QGraphicsPathItem*> _trackPaths;
QList<MarkerItem*> _markers; QList<MarkerItem*> _markers;
QHash<WayPoint, WayPointItem*> _pois; QHash<Waypoint, WaypointItem*> _pois;
Map *_map; Map *_map;
ScaleItem *_mapScale; ScaleItem *_mapScale;

View File

@ -5,11 +5,11 @@
#include <QString> #include <QString>
#include <QHash> #include <QHash>
class WayPoint class Waypoint
{ {
public: public:
WayPoint() {} Waypoint() {}
WayPoint(const QPointF &coordinates, const QString &description) Waypoint(const QPointF &coordinates, const QString &description)
: _coordinates(coordinates), _description(description) {} : _coordinates(coordinates), _description(description) {}
const QPointF &coordinates() const {return _coordinates;} const QPointF &coordinates() const {return _coordinates;}
@ -19,7 +19,7 @@ public:
void setDescription(const QString &description) void setDescription(const QString &description)
{_description = description;} {_description = description;}
bool operator==(const WayPoint &other) const bool operator==(const Waypoint &other) const
{return this->_description == other._description {return this->_description == other._description
&& this->_coordinates == other._coordinates;} && this->_coordinates == other._coordinates;}
@ -28,7 +28,7 @@ private:
QString _description; QString _description;
}; };
inline uint qHash(const WayPoint &key) inline uint qHash(const Waypoint &key)
{ {
return ::qHash(key.description()); return ::qHash(key.description());
} }

View File

@ -5,14 +5,14 @@
#define POINT_SIZE 8 #define POINT_SIZE 8
WayPointItem::WayPointItem(const WayPoint &entry, QGraphicsItem *parent) WaypointItem::WaypointItem(const Waypoint &entry, QGraphicsItem *parent)
: QGraphicsItem(parent) : QGraphicsItem(parent)
{ {
_entry = entry; _entry = entry;
updateBoundingRect(); updateBoundingRect();
} }
void WayPointItem::updateBoundingRect() void WaypointItem::updateBoundingRect()
{ {
QFont font; QFont font;
font.setPixelSize(FONT_SIZE); font.setPixelSize(FONT_SIZE);
@ -24,7 +24,7 @@ void WayPointItem::updateBoundingRect()
ts.height() + fm.descent() + POINT_SIZE); ts.height() + fm.descent() + POINT_SIZE);
} }
void WayPointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) QWidget *widget)
{ {
Q_UNUSED(option); Q_UNUSED(option);

View File

@ -4,11 +4,11 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include "waypoint.h" #include "waypoint.h"
class WayPointItem : public QGraphicsItem class WaypointItem : public QGraphicsItem
{ {
public: public:
WayPointItem(const WayPoint &entry, QGraphicsItem *parent = 0); WaypointItem(const Waypoint &entry, QGraphicsItem *parent = 0);
const WayPoint &entry() const {return _entry;} const Waypoint &entry() const {return _entry;}
QRectF boundingRect() const {return _boundingRect;} QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -17,7 +17,7 @@ public:
private: private:
void updateBoundingRect(); void updateBoundingRect();
WayPoint _entry; Waypoint _entry;
QRectF _boundingRect; QRectF _boundingRect;
}; };