Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use default special member functions for gpx related classes. #586

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ set(HEADERS
appname.h
babeldata.h
donate.h
dpencode.h
filterdata.h
filterdlg.h
filterwidgets.h
Expand All @@ -137,6 +138,7 @@ set(HEADERS
gmapdlg.h
gpx.h
help.h
latlng.h
mainwindow.h
map.h
optionsdlg.h
Expand Down
2 changes: 2 additions & 0 deletions gui/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ HEADERS += advdlg.h
HEADERS += appname.h
HEADERS += babeldata.h
HEADERS += donate.h
HEADERS += dpencode.h
HEADERS += filterdata.h
HEADERS += filterdlg.h
HEADERS += filterwidgets.h
Expand All @@ -109,6 +110,7 @@ HEADERS += formatload.h
HEADERS += gmapdlg.h
HEADERS += gpx.h
HEADERS += help.h
HEADERS += latlng.h
HEADERS += mainwindow.h
HEADERS += map.h
HEADERS += optionsdlg.h
Expand Down
119 changes: 14 additions & 105 deletions gui/gpx.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
#include <QList> // for QList
#include <QString> // for QString
#include <QtGlobal> // for foreach
#include <limits> // for numeric_limits
#include "latlng.h" // for LatLng


//------------------------------------------------------------------------
class GpxItem
{
public:
GpxItem(): visible(true) {}
GpxItem(bool visible): visible(visible) {}

void setVisible(bool b)
{
visible = b;
Expand All @@ -48,17 +46,13 @@ class GpxItem
}

protected:
bool visible;
bool visible{true};
};

//------------------------------------------------------------------------
class GpxRoutePoint: public GpxItem
{
public:
GpxRoutePoint(): location(LatLng()), name(QString())
{
}

void setLocation(const LatLng& pt)
{
location = pt;
Expand Down Expand Up @@ -88,29 +82,6 @@ class GpxRoutePoint: public GpxItem
class GpxRoute: public GpxItem
{
public:
GpxRoute(): name(QString()), cachedLength(-1) {}

GpxRoute(const GpxRoute& c)
:GpxItem(c.visible),
name(c.name), cachedLength(c.cachedLength)
{
routePoints.clear();
foreach (GpxRoutePoint sg, c.routePoints) {
routePoints << sg;
}
}
GpxRoute& operator = (const GpxRoute& c)
{
visible = c.visible;
name = c.name;
cachedLength = c.cachedLength;
routePoints.clear();
foreach (GpxRoutePoint sg, c.routePoints) {
routePoints << sg;
}
return *this;
}

double length() const
{
if (cachedLength >=0.0) {
Expand Down Expand Up @@ -161,17 +132,13 @@ class GpxRoute: public GpxItem
private:
QString name;
QList <GpxRoutePoint> routePoints;
double cachedLength;
double cachedLength{-1.0};
};

//------------------------------------------------------------------------
class GpxTrackPoint: public GpxItem
{
public:
GpxTrackPoint(): location(LatLng()), elevation(0), dateTime(QDateTime())
{
}

void setLocation(const LatLng& pt)
{
location = pt;
Expand Down Expand Up @@ -204,32 +171,14 @@ class GpxTrackPoint: public GpxItem

private:
LatLng location;
double elevation;
double elevation{std::numeric_limits<double>::lowest()};
QDateTime dateTime;
};

//------------------------------------------------------------------------
class GpxTrackSegment: public GpxItem
{
public:
GpxTrackSegment() {}

GpxTrackSegment(const GpxTrackSegment& c): GpxItem(c.visible)
{
trackPoints.clear();
foreach (GpxTrackPoint pt, c.trackPoints) {
trackPoints << pt;
}
}
GpxTrackSegment& operator = (const GpxTrackSegment& c)
{
visible = c.visible;
trackPoints.clear();
foreach (GpxTrackPoint pt, c.trackPoints) {
trackPoints << pt;
}
return *this;
}
void addPoint(const GpxTrackPoint& pt)
{
trackPoints << pt;
Expand All @@ -247,40 +196,11 @@ class GpxTrackSegment: public GpxItem
private:
QList <GpxTrackPoint> trackPoints;
};

//------------------------------------------------------------------------
class GpxTrack: public GpxItem
{
public:
GpxTrack(): number(1), name(QString()), comment(QString()), description(QString()), cachedLength(-1.0) {}

GpxTrack(const GpxTrack& c)
:GpxItem(c.visible),
number(c.number),
name(c.name),
comment(c.comment),
description(c.description),
cachedLength(c.cachedLength)
{
trackSegments.clear();
foreach (GpxTrackSegment sg, c.trackSegments) {
trackSegments << sg;
}
}
GpxTrack& operator = (const GpxTrack& c)
{
visible = c.visible;
number = c.number;
name = c.name;
comment = c.comment;
description = c.description;
cachedLength = c.cachedLength;
trackSegments.clear();
foreach (GpxTrackSegment sg, c.trackSegments) {
trackSegments << sg;
}
return *this;
}

void setNumber(int n)
{
number = n;
Expand Down Expand Up @@ -361,27 +281,18 @@ class GpxTrack: public GpxItem
}

private:
int number;
int number{1};
QString name;
QString comment;
QString description;
QList <GpxTrackSegment> trackSegments;
double cachedLength;
double cachedLength{-1.0};
};

//------------------------------------------------------------------------
class GpxWaypoint: public GpxItem
{
public:
GpxWaypoint():
location_(LatLng(0, 0)),
elevation_(-1.0E-100),
name_(QString()),
comment_(QString()),
description_(QString()),
symbol_(QString())
{}

void setLocation(const LatLng& pt)
{
location_ = pt;
Expand Down Expand Up @@ -444,7 +355,7 @@ class GpxWaypoint: public GpxItem

private:
LatLng location_;
double elevation_;
double elevation_{std::numeric_limits<double>::lowest()};
QString name_;
QString comment_;
QString description_;
Expand All @@ -455,20 +366,19 @@ class GpxWaypoint: public GpxItem
class Gpx
{
public:
Gpx() {}
bool read(const QString& fileName);

QList <GpxWaypoint>& getWaypoints()
{
return wayPoints;
} // nonconst

QList <GpxTrack>& getTracks()
QList <GpxTrack>& getTracks()
{
return tracks;
}

QList <GpxRoute>& getRoutes()
QList <GpxRoute>& getRoutes()
{
return routes;
}
Expand All @@ -478,21 +388,20 @@ class Gpx
return wayPoints;
}

const QList <GpxTrack>& getTracks() const
const QList <GpxTrack>& getTracks() const
{
return tracks;
}

const QList <GpxRoute>& getRoutes() const
const QList <GpxRoute>& getRoutes() const
{
return routes;
}

private:
QList <GpxWaypoint> wayPoints;
QList <GpxTrack> tracks;
QList <GpxRoute> routes;
QList <GpxTrack> tracks;
QList <GpxRoute> routes;
};


#endif
9 changes: 4 additions & 5 deletions gui/latlng.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
class LatLng
{
public:
LatLng(): _lat(0), _lng(0) {};
LatLng(double lat, double lng): _lat(lat), _lng(lng) {};
LatLng() = default;
LatLng(double lat, double lng): _lat(lat), _lng(lng) {}
double lat() const
{
return _lat;
Expand All @@ -41,9 +41,8 @@ class LatLng
double haversineDistance(const LatLng& other) const;

private:
double _lat;
double _lng;
double _lat{0.0};
double _lng{0.0};
};


#endif