From 569b37c29d44c043e628ad18f4a93d4279016371 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sun, 13 Mar 2016 21:41:03 +0300 Subject: [PATCH] Introduced the constant for measurement units in the settings. --- android/jni/com/mapswithme/maps/settings/UnitLocale.cpp | 6 +++--- drape_frontend/gui/ruler_helper.cpp | 2 +- iphone/Maps/Settings/Preferences.mm | 5 ++--- iphone/Maps/Settings/SettingsViewController.mm | 4 ++-- map/framework.cpp | 2 +- platform/measurement_utils.cpp | 6 +++--- platform/platform_android.cpp | 4 ++-- platform/platform_ios.mm | 4 ++-- platform/platform_qt.cpp | 4 ++-- platform/platform_tests/measurement_tests.cpp | 8 ++++---- platform/settings.cpp | 1 + platform/settings.hpp | 4 +++- qt/preferences_dialog.cpp | 4 ++-- 13 files changed, 28 insertions(+), 26 deletions(-) diff --git a/android/jni/com/mapswithme/maps/settings/UnitLocale.cpp b/android/jni/com/mapswithme/maps/settings/UnitLocale.cpp index b44de3438f..aa1fe3ec5e 100644 --- a/android/jni/com/mapswithme/maps/settings/UnitLocale.cpp +++ b/android/jni/com/mapswithme/maps/settings/UnitLocale.cpp @@ -9,14 +9,14 @@ extern "C" Java_com_mapswithme_maps_settings_UnitLocale_setCurrentUnits(JNIEnv * env, jobject thiz, jint units) { Settings::Units const u = static_cast(units); - Settings::Set("Units", u); + Settings::Set(Settings::kMeasurementUnits, u); g_framework->SetupMeasurementSystem(); } JNIEXPORT jint JNICALL Java_com_mapswithme_maps_settings_UnitLocale_getCurrentUnits(JNIEnv * env, jobject thiz) { - Settings::Units u = Settings::Metric; - return (Settings::Get("Units", u) ? u : -1); + Settings::Units u; + return (Settings::Get(Settings::kMeasurementUnits, u) ? u : -1); } } diff --git a/drape_frontend/gui/ruler_helper.cpp b/drape_frontend/gui/ruler_helper.cpp index 406851e705..3d5d800857 100644 --- a/drape_frontend/gui/ruler_helper.cpp +++ b/drape_frontend/gui/ruler_helper.cpp @@ -225,7 +225,7 @@ double RulerHelper::CalcMetresDiff(double value) ConversionFn conversionFn = &identity; Settings::Units units = Settings::Metric; - Settings::Get("Units", units); + Settings::Get(Settings::kMeasurementUnits, units); if (units == Settings::Foot) { diff --git a/iphone/Maps/Settings/Preferences.mm b/iphone/Maps/Settings/Preferences.mm index cc51b99218..0dd9774d5b 100644 --- a/iphone/Maps/Settings/Preferences.mm +++ b/iphone/Maps/Settings/Preferences.mm @@ -11,13 +11,12 @@ + (void)setup { Settings::Units u; - string const units = "Units"; - if (!Settings::Get(units, u)) + if (!Settings::Get(Settings::kMeasurementUnits, u)) { // get system locale preferences BOOL const isMetric = [[[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleUsesMetricSystem] boolValue]; u = isMetric ? Settings::Metric : Settings::Foot; - Settings::Set(units, u); + Settings::Set(Settings::kMeasurementUnits, u); } GetFramework().SetupMeasurementSystem(); } diff --git a/iphone/Maps/Settings/SettingsViewController.mm b/iphone/Maps/Settings/SettingsViewController.mm index 0b46c155d2..322fe5f674 100644 --- a/iphone/Maps/Settings/SettingsViewController.mm +++ b/iphone/Maps/Settings/SettingsViewController.mm @@ -88,7 +88,7 @@ typedef NS_ENUM(NSUInteger, Section) { cell = [tableView dequeueReusableCellWithIdentifier:[SelectableCell className]]; Settings::Units units = Settings::Metric; - (void)Settings::Get("Units", units); + (void)Settings::Get(Settings::kMeasurementUnits, units); BOOL const selected = units == unitsForIndex(indexPath.row); SelectableCell * customCell = (SelectableCell *)cell; customCell.accessoryType = selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; @@ -322,7 +322,7 @@ Settings::Units unitsForIndex(NSInteger index) Settings::Units units = unitsForIndex(indexPath.row); [[Statistics instance] logEvent:kStatEventName(kStatSettings, kStatChangeMeasureUnits) withParameters:@{kStatValue : (units == Settings::Units::Metric ? kStatKilometers : kStatMiles)}]; - Settings::Set("Units", units); + Settings::Set(Settings::kMeasurementUnits, units); [tableView reloadSections:[NSIndexSet indexSetWithIndex:SectionMetrics] withRowAnimation:UITableViewRowAnimationFade]; GetFramework().SetupMeasurementSystem(); break; diff --git a/map/framework.cpp b/map/framework.cpp index b2d1a3748b..d15cc4f83e 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1521,7 +1521,7 @@ void Framework::SetupMeasurementSystem() GetPlatform().SetupMeasurementSystem(); Settings::Units units = Settings::Metric; - Settings::Get("Units", units); + Settings::Get(Settings::kMeasurementUnits, units); m_routingSession.SetTurnNotificationsUnits(units); } diff --git a/platform/measurement_utils.cpp b/platform/measurement_utils.cpp index 8e6360cc52..755cd70608 100644 --- a/platform/measurement_utils.cpp +++ b/platform/measurement_utils.cpp @@ -49,7 +49,7 @@ bool FormatDistanceImpl(double m, string & res, bool FormatDistance(double m, string & res) { Units u = Metric; - (void)Get("Units", u); + (void)Get(Settings::kMeasurementUnits, u); /// @todo Put string units resources. switch (u) @@ -152,7 +152,7 @@ void FormatMercator(m2::PointD const & mercator, string & lat, string & lon, int string FormatAltitude(double altitudeInMeters) { Units u = Metric; - (void)Get("Units", u); + (void)Get(Settings::kMeasurementUnits, u); ostringstream ss; ss << fixed << setprecision(0); @@ -169,7 +169,7 @@ string FormatAltitude(double altitudeInMeters) string FormatSpeed(double metersPerSecond) { Units u = Metric; - (void)Get("Units", u); + (void)Get(Settings::kMeasurementUnits, u); double perHour; string res; diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index 01fd0980c2..4f0816535e 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -252,11 +252,11 @@ Platform::EError Platform::MkDir(string const & dirName) const void Platform::SetupMeasurementSystem() const { Settings::Units u; - if (Settings::Get("Units", u)) + if (Settings::Get(Settings::kMeasurementUnits, u)) return; // @TODO Add correct implementation u = Settings::Metric; - Settings::Set("Units", u); + Settings::Set(Settings::kMeasurementUnits, u); } namespace diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm index ec0b8058e1..b7cafe738b 100644 --- a/platform/platform_ios.mm +++ b/platform/platform_ios.mm @@ -263,11 +263,11 @@ Platform::EConnectionType Platform::ConnectionStatus() void Platform::SetupMeasurementSystem() const { Settings::Units u; - if (Settings::Get("Units", u)) + if (Settings::Get(Settings::kMeasurementUnits, u)) return; BOOL const isMetric = [[[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleUsesMetricSystem] boolValue]; u = isMetric ? Settings::Metric : Settings::Foot; - Settings::Set("Units", u); + Settings::Set(Settings::kMeasurementUnits, u); } //////////////////////////////////////////////////////////////////////// diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp index 527426a485..42b0a1c588 100644 --- a/platform/platform_qt.cpp +++ b/platform/platform_qt.cpp @@ -75,11 +75,11 @@ Platform::EError Platform::MkDir(string const & dirName) const void Platform::SetupMeasurementSystem() const { Settings::Units u; - if (Settings::Get("Units", u)) + if (Settings::Get(Settings::kMeasurementUnits, u)) return; bool const isMetric = QLocale::system().measurementSystem() == QLocale::MetricSystem; u = isMetric ? Settings::Metric : Settings::Foot; - Settings::Set("Units", u); + Settings::Set(Settings::kMeasurementUnits, u); } #if defined(OMIM_OS_LINUX) diff --git a/platform/platform_tests/measurement_tests.cpp b/platform/platform_tests/measurement_tests.cpp index ca27c074b1..a1090031da 100644 --- a/platform/platform_tests/measurement_tests.cpp +++ b/platform/platform_tests/measurement_tests.cpp @@ -8,7 +8,7 @@ using namespace MeasurementUtils; UNIT_TEST(Measurement_Smoke) { - Settings::Set("Units", Settings::Metric); + Settings::Set(Settings::kMeasurementUnits, Settings::Metric); typedef pair PairT; @@ -66,15 +66,15 @@ UNIT_TEST(LatLonToDMS_NoRounding) UNIT_TEST(FormatAltitude) { - Settings::Set("Units", Settings::Foot); + Settings::Set(Settings::kMeasurementUnits, Settings::Foot); TEST_EQUAL(FormatAltitude(10000), "32808ft", ()); - Settings::Set("Units", Settings::Metric); + Settings::Set(Settings::kMeasurementUnits, Settings::Metric); TEST_EQUAL(FormatAltitude(5), "5m", ()); } UNIT_TEST(FormatSpeed) { - Settings::Set("Units", Settings::Metric); + Settings::Set(Settings::kMeasurementUnits, Settings::Metric); TEST_EQUAL(FormatSpeed(10), "36km/h", ()); TEST_EQUAL(FormatSpeed(1), "3.6km/h", ()); } diff --git a/platform/settings.cpp b/platform/settings.cpp index 0dfb5a4249..902a1d4232 100644 --- a/platform/settings.cpp +++ b/platform/settings.cpp @@ -25,6 +25,7 @@ char const DELIM_CHAR = '='; } char const * Settings::kLocationStateMode = "LastLocationStateMode"; +char const * Settings::kMeasurementUnits = "Units"; namespace Settings { diff --git a/platform/settings.hpp b/platform/settings.hpp index 66dcbb261a..362332a4ea 100644 --- a/platform/settings.hpp +++ b/platform/settings.hpp @@ -6,8 +6,10 @@ namespace Settings { -// Current location state mode. @See location::EMyPositionMode. +/// Current location state mode. @See location::EMyPositionMode. extern char const * kLocationStateMode; +/// Metric or Feet. +extern char const * kMeasurementUnits; template bool FromString(string const & str, T & outValue); diff --git a/qt/preferences_dialog.cpp b/qt/preferences_dialog.cpp index 622f4f377e..98786f8f62 100644 --- a/qt/preferences_dialog.cpp +++ b/qt/preferences_dialog.cpp @@ -53,7 +53,7 @@ namespace qt radioBox->setLayout(pLayout); Units u; - if (!Settings::Get("Units", u)) + if (!Settings::Get(Settings::kMeasurementUnits, u)) { // set default measurement from system locale if (QLocale::system().measurementSystem() == QLocale::MetricSystem) @@ -101,6 +101,6 @@ namespace qt case 1: u = Foot; break; } - Settings::Set("Units", u); + Settings::Set(kMeasurementUnits, u); } }