-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathformathandler.cpp
64 lines (56 loc) · 1.52 KB
/
formathandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/** @file formathandler.cpp
* Soubor s tridou FormatHandler dedici ze trify QObject pro prevadeni gps souradnic a casu
* do pozadovaneho formatu
*/
#include "formathandler.h"
FormatHandler::FormatHandler()
: QObject()
{
formatGps = "dm";
formatDateTime = "dd.M.yyyy hh:mm:ss";
}
QString FormatHandler::gpsInFormat(double l)
{
QString lStr;
if (formatGps == "d") { // stupne
if (l < 0) {
l *= -1;
}
lStr = QString::number(l, 'f', 5);
} else if (formatGps == "dm") { // stupne minuty
lStr = convertDegreeToDM(l);
} else { // stupne minuty sekundy
lStr = convertDegreeToDMS(l);
}
return lStr;
}
QString FormatHandler::gpsAllInFormat(double lat, double lon)
{
QString latStr = gpsInFormat(lat);
QString lonStr = gpsInFormat(lon);
return QString("%1%2 %3%4")
.arg(latStr)
.arg(lat >= 0 ? tr("N ") : tr("S "))
.arg(lonStr)
.arg(lon >= 0 ? tr("E") : tr("W"));
}
QString FormatHandler::convertDegreeToDM(double l)
{
if (l < 0) {
l *= -1;
}
int degree = l;
double min = (l - degree) * 60;
return QString::number(degree) + "°" + QString::number(min, 'f', 3) + "'";
}
QString FormatHandler::convertDegreeToDMS(double l)
{
if (l < 0) {
l = l * (-1);
}
int degree = l;
double minTmp = (l - degree) * 60;
int min = static_cast<int>(minTmp);
double sec = (minTmp - min) * 60;
return QString("%1°%2'%3\"").arg(degree).arg(min).arg(QString::number(sec, 'f', 2));
}