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

Refactoring

This commit is contained in:
Martin Tůma 2016-11-02 17:35:26 +01:00
parent 87a4398131
commit 984d3bb6c5
9 changed files with 88 additions and 76 deletions

View File

@ -63,7 +63,8 @@ HEADERS += src/config.h \
src/kmlparser.h \
src/trackdata.h \
src/routedata.h \
src/fitparser.h
src/fitparser.h \
src/format.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/poi.cpp \
@ -107,7 +108,8 @@ SOURCES += src/main.cpp \
src/csvparser.cpp \
src/coordinates.cpp \
src/kmlparser.cpp \
src/fitparser.cpp
src/fitparser.cpp \
src/format.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx {

53
src/format.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <QApplication>
#include "coordinates.h"
#include "format.h"
QString Format::timeSpan(qreal time)
{
unsigned h, m, s;
h = time / 3600;
m = (time - (h * 3600)) / 60;
s = time - (h * 3600) - (m * 60);
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
.arg(s, 2, 10, QChar('0'));
}
QString Format::distance(qreal value, Units units)
{
if (units == Imperial) {
if (value < MIINM)
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "ft");
else
return QString::number(value * M2MI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "mi");
} else {
if (value < KMINM)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "m");
else
return QString::number(value * M2KM, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "km");
}
}
QString Format::elevation(qreal value, Units units)
{
if (units == Metric)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "m");
else
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "ft");
}
QString Format::coordinates(const Coordinates &value)
{
QChar yH = (value.lat() < 0) ? 'S' : 'N';
QChar xH = (value.lon() < 0) ? 'W' : 'E';
return QString::number(qAbs(value.lat()), 'f', 5) + yH + "," + QChar(0x00A0)
+ QString::number(qAbs(value.lon()), 'f', 5) + xH;
}

17
src/format.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef FORMAT_H
#define FORMAT_H
#include <QString>
#include "units.h"
class Coordinates;
namespace Format
{
QString timeSpan(qreal time);
QString distance(qreal value, Units units);
QString elevation(qreal value, Units units);
QString coordinates(const Coordinates &value);
}
#endif // FORMAT_H

View File

@ -39,7 +39,7 @@
#include "cpuarch.h"
#include "exportdialog.h"
#include "graphtab.h"
#include "misc.h"
#include "format.h"
#include "gui.h"
@ -791,9 +791,9 @@ void GUI::plot(QPrinter *printer)
info.insert(tr("Waypoints"), QString::number(_waypointCount));
if (d > 0)
info.insert(tr("Distance"), ::distance(d, units));
info.insert(tr("Distance"), Format::distance(d, units));
if (t > 0)
info.insert(tr("Time"), ::timeSpan(t));
info.insert(tr("Time"), Format::timeSpan(t));
ratio = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI;
@ -983,13 +983,13 @@ void GUI::updateStatusBarInfo()
qreal d = distance();
Units units = _imperialUnitsAction->isChecked() ? Imperial : Metric;
if (d > 0)
_distanceLabel->setText(::distance(distance(), units));
_distanceLabel->setText(Format::distance(distance(), units));
else
_distanceLabel->clear();
qreal t = time();
if (t > 0)
_timeLabel->setText(::timeSpan(time()));
_timeLabel->setText(Format::timeSpan(time()));
else
_timeLabel->clear();
}

View File

@ -1,5 +1,4 @@
#include <cmath>
#include <QApplication>
#include "misc.h"
@ -34,53 +33,3 @@ double niceNum(double x, int round)
return nf * pow(10.0, expv);
}
QString timeSpan(qreal time)
{
unsigned h, m, s;
h = time / 3600;
m = (time - (h * 3600)) / 60;
s = time - (h * 3600) - (m * 60);
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
.arg(s, 2, 10, QChar('0'));
}
QString distance(qreal value, Units units)
{
if (units == Imperial) {
if (value < MIINM)
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "ft");
else
return QString::number(value * M2MI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Misc", "mi");
} else {
if (value < KMINM)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "m");
else
return QString::number(value * M2KM, 'f', 1) + UNIT_SPACE
+ qApp->translate("Misc", "km");
}
}
QString elevation(qreal value, Units units)
{
if (units == Metric)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "m");
else
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "ft");
}
QString coordinates(const Coordinates &value)
{
QChar yH = (value.lat() < 0) ? 'S' : 'N';
QChar xH = (value.lon() < 0) ? 'W' : 'E';
return QString::number(qAbs(value.lat()), 'f', 5) + yH + "," + QChar(0x00A0)
+ QString::number(qAbs(value.lon()), 'f', 5) + xH;
}

View File

@ -1,16 +1,6 @@
#ifndef MISC_H
#define MISC_H
#include <QString>
#include <QPoint>
#include "coordinates.h"
#include "units.h"
double niceNum(double x, int round);
QString timeSpan(qreal time);
QString distance(qreal value, Units units);
QString elevation(qreal value, Units units);
QString coordinates(const Coordinates &value);
#endif // MISC_H

View File

@ -1,6 +1,6 @@
#include <QApplication>
#include <QPainter>
#include "misc.h"
#include "format.h"
#include "waypoint.h"
#include "waypointitem.h"
#include "tooltip.h"
@ -16,7 +16,7 @@ QString RouteItem::toolTip()
if (!_desc.isEmpty())
tt.insert(qApp->translate("RouteItem", "Description"), _desc);
tt.insert(qApp->translate("RouteItem", "Distance"),
::distance(_distance, _units));
Format::distance(_distance, _units));
return tt.toString();
}

View File

@ -1,7 +1,7 @@
#include <QApplication>
#include <QCursor>
#include <QPainter>
#include "misc.h"
#include "format.h"
#include "tooltip.h"
#include "trackitem.h"
@ -15,9 +15,10 @@ QString TrackItem::toolTip()
if (!_desc.isEmpty())
tt.insert(qApp->translate("TrackItem", "Description"), _desc);
tt.insert(qApp->translate("TrackItem", "Distance"),
::distance(_distance, _units));
Format::distance(_distance, _units));
if (_time > 0)
tt.insert(qApp->translate("TrackItem", "Time"), ::timeSpan(_time));
tt.insert(qApp->translate("TrackItem", "Time"),
Format::timeSpan(_time));
if (!_date.isNull())
tt.insert(qApp->translate("TrackItem", "Date"),
_date.toString(Qt::SystemLocaleShortDate));

View File

@ -1,7 +1,7 @@
#include <QApplication>
#include <QPainter>
#include "config.h"
#include "misc.h"
#include "format.h"
#include "tooltip.h"
#include "waypointitem.h"
@ -16,10 +16,10 @@ QString WaypointItem::toolTip()
if (!_waypoint.name().isEmpty() && !_showLabel)
tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name());
tt.insert(qApp->translate("WaypointItem", "Coordinates"),
::coordinates(_waypoint.coordinates()));
Format::coordinates(_waypoint.coordinates()));
if (!std::isnan(_waypoint.elevation()))
tt.insert(qApp->translate("WaypointItem", "Elevation"),
::elevation(_waypoint.elevation(), _units));
Format::elevation(_waypoint.elevation(), _units));
if (!_waypoint.timestamp().isNull())
tt.insert(qApp->translate("WaypointItem", "Date"),
_waypoint.timestamp().toString(Qt::SystemLocaleShortDate));