From a4ed160060b9addd7302f62e227d73a24d4d443c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 24 Jul 2020 11:07:58 +0200 Subject: [PATCH] [localeq] Offer a Config setting to set location from region/zone - already had methods for various kinds of broken-up data, but not one for plain "region/zone" strings; having this makes it easier for QML to report a zone. - use the region/zone method from QML, so that clicking on the world map updates the actual TZ in Config. --- src/modules/locale/Config.cpp | 9 +++++++++ src/modules/locale/Config.h | 9 ++++++++- src/modules/localeq/Map.qml | 7 ++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index f0198dd21..f28a2d0b5 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -218,6 +218,15 @@ Config::setCurrentLocation() } } +void Config::setCurrentLocation(const QString& regionzone) +{ + auto r = CalamaresUtils::GeoIP::splitTZString( regionzone ); + if ( r.isValid() ) + { + setCurrentLocation( r.first, r.second ); + } +} + void Config::setCurrentLocation( const QString& regionName, const QString& zoneName ) { diff --git a/src/modules/locale/Config.h b/src/modules/locale/Config.h index 484c1032e..d74555ee5 100644 --- a/src/modules/locale/Config.h +++ b/src/modules/locale/Config.h @@ -92,7 +92,14 @@ public Q_SLOTS: /// Set LC (formats) by user-choice, overriding future location changes void setLCLocaleExplicitly( const QString& locale ); - /** @brief Sets a location by name + /** @brief Sets a location by full name + * + * @p regionzone should be an identifier from zone.tab, e.g. "Africa/Abidjan", + * which is split into regon and zone. Invalid names will **not** + * change the actual location. + */ + void setCurrentLocation( const QString& regionzone ); + /** @brief Sets a location by split name * * @p region should be "America" or the like, while @p zone * names a zone within that region. diff --git a/src/modules/localeq/Map.qml b/src/modules/localeq/Map.qml index 023de6d1b..080d7388a 100644 --- a/src/modules/localeq/Map.qml +++ b/src/modules/localeq/Map.qml @@ -74,6 +74,7 @@ Column { var tz2 = responseJSON.timezoneId tzText.text = "Timezone: " + tz2 + config.setCurrentLocation(tz2) } } @@ -126,7 +127,7 @@ Column { anchorPoint.x: image.width/4 anchorPoint.y: image.height coordinate: QtPositioning.coordinate( - map.center.latitude, + map.center.latitude, map.center.longitude) //coordinate: QtPositioning.coordinate(40.730610, -73.935242) // New York @@ -156,7 +157,7 @@ Column { map.center.longitude = coordinate.longitude getTz(); - + console.log(coordinate.latitude, coordinate.longitude) } } @@ -199,7 +200,7 @@ Column { } Rectangle { - width: parent.width + width: parent.width height: 100 anchors.horizontalCenter: parent.horizontalCenter