diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-05-12 13:19:57 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-13 09:16:11 +0900 |
commit | 2b06e4be671930bc22feb830f328871a31315d9f (patch) | |
tree | 1eef094dcfbe77c24383ffe815c152995491ceff /qthelper.cpp | |
parent | 05e00866312b177ff64fa6e5bcd565871a66d172 (diff) | |
download | subsurface-2b06e4be671930bc22feb830f328871a31315d9f.tar.gz |
Move printGpsCoords from MainTab to QtHelper
Last time I touched this I got a scream from dirk, but then I
looked at the code again and the problem that I faced was that
I broke translations in a sad way, well, now I broke it again.
However, this method shouldn't belong to MainTab ( because of
that thingy that I said before and also many others: Separate
the logic of your application from the UI specific code )
This generates a string that's going to be used on the Interface,
it doesn't display it on the interface. Move it down below makes
it easier to test ( I don't need to create an Widget and worry
about the parent-relationship with the mainwindow just to test
this function, for instance. )
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qthelper.cpp')
-rw-r--r-- | qthelper.cpp | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/qthelper.cpp b/qthelper.cpp index a5e450eff..f056f5238 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -110,6 +110,32 @@ QString weight_string(int weight_in_grams) return (str); } +QString printGPSCoords(int lat, int lon) +{ + unsigned int latdeg, londeg; + unsigned int latmin, lonmin; + double latsec, lonsec; + QString lath, lonh, result; + + if (!lat && !lon) + return QString(); + + lath = lat >= 0 ? tr("N") : tr("S"); + lonh = lon >= 0 ? tr("E") : tr("W"); + lat = abs(lat); + lon = abs(lon); + latdeg = lat / 1000000; + londeg = lon / 1000000; + latmin = (lat % 1000000) * 60; + lonmin = (lon % 1000000) * 60; + latsec = (latmin % 1000000) * 60; + lonsec = (lonmin % 1000000) * 60; + result.sprintf("%u%s%02d\'%06.3f\"%s %u%s%02d\'%06.3f\"%s", + latdeg, UTF8_DEGREE, latmin / 1000000, latsec / 1000000, lath.toUtf8().data(), + londeg, UTF8_DEGREE, lonmin / 1000000, lonsec / 1000000, lonh.toUtf8().data()); + return result; +} + bool parseGpsText(const QString &gps_text, double *latitude, double *longitude) { enum { @@ -121,10 +147,10 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude) int eastWest = 4; int northSouth = 1; QString trHemisphere[4]; - trHemisphere[0] = MainWindow::instance()->information()->trHemisphere("N"); - trHemisphere[1] = MainWindow::instance()->information()->trHemisphere("S"); - trHemisphere[2] = MainWindow::instance()->information()->trHemisphere("E"); - trHemisphere[3] = MainWindow::instance()->information()->trHemisphere("W"); + trHemisphere[0] = tr("N"); + trHemisphere[1] = tr("S"); + trHemisphere[2] = tr("E"); + trHemisphere[3] = tr("W"); QString regExp; /* an empty string is interpreted as 0.0,0.0 and therefore "no gps location" */ if (gps_text.trimmed().isEmpty()) { @@ -302,7 +328,6 @@ extern "C" void call_for_each_dc(void *f, void (*callback)(void *, const char *, } } - static xmlDocPtr get_stylesheet_doc(const xmlChar *uri, xmlDictPtr, int, void *, xsltLoadType) { QFile f(QLatin1String(":/xslt/") + (const char *)uri); |