mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 15:10:05 +00:00 
			
		
		
		
	added **BASIC** unit handling to radius field.
This commit is contained in:
		
							parent
							
								
									b421251bcd
								
							
						
					
					
						commit
						c53836e91a
					
				
					 6 changed files with 95 additions and 4 deletions
				
			
		|  | @ -8,6 +8,8 @@ | |||
| #include <scwx/util/logger.hpp> | ||||
| #include <scwx/qt/config/radar_site.hpp> | ||||
| #include <scwx/qt/settings/general_settings.hpp> | ||||
| #include <scwx/qt/settings/unit_settings.hpp> | ||||
| #include <scwx/qt/types/unit_types.hpp> | ||||
| 
 | ||||
| #include <boost/asio/post.hpp> | ||||
| #include <boost/asio/thread_pool.hpp> | ||||
|  | @ -138,12 +140,19 @@ void AlertManager::Impl::HandleAlert(const types::TextEventKey& key, | |||
|    } | ||||
| 
 | ||||
|    settings::AudioSettings& audioSettings = settings::AudioSettings::Instance(); | ||||
|    settings::UnitSettings&  unitSettings  = settings::UnitSettings::Instance(); | ||||
|    types::LocationMethod    locationMethod = types::GetLocationMethod( | ||||
|       audioSettings.alert_location_method().GetValue()); | ||||
|    common::Coordinate currentCoordinate = CurrentCoordinate(locationMethod); | ||||
|    std::string        alertCounty = audioSettings.alert_county().GetValue(); | ||||
|    auto               alertRadius = | ||||
|       units::length::meters<double>(audioSettings.alert_radius().GetValue()); | ||||
| 
 | ||||
|    types::DistanceUnits radiusUnits = | ||||
|       types::GetDistanceUnitsFromName(unitSettings.distance_units().GetValue()); | ||||
|    double radiusScale = types::GetDistanceUnitsScale(radiusUnits); | ||||
|    auto   alertRadius = units::length::kilometers<double>( | ||||
|       audioSettings.alert_radius().GetValue() / radiusScale); | ||||
| 
 | ||||
|    logger_->debug("alertRadius: {}", (double)alertRadius); | ||||
| 
 | ||||
|    auto message = textEventManager_->message_list(key).at(messageIndex); | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,16 +26,20 @@ public: | |||
|          types::GetOtherUnitsName(types::OtherUnits::Default); | ||||
|       std::string defaultSpeedUnitsValue = | ||||
|          types::GetSpeedUnitsName(types::SpeedUnits::Knots); | ||||
|       std::string defaultDistanceUnitsValue = | ||||
|          types::GetDistanceUnitsName(types::DistanceUnits::Kilometers); | ||||
| 
 | ||||
|       boost::to_lower(defaultAccumulationUnitsValue); | ||||
|       boost::to_lower(defaultEchoTopsUnitsValue); | ||||
|       boost::to_lower(defaultOtherUnitsValue); | ||||
|       boost::to_lower(defaultSpeedUnitsValue); | ||||
|       boost::to_lower(defaultDistanceUnitsValue); | ||||
| 
 | ||||
|       accumulationUnits_.SetDefault(defaultAccumulationUnitsValue); | ||||
|       echoTopsUnits_.SetDefault(defaultEchoTopsUnitsValue); | ||||
|       otherUnits_.SetDefault(defaultOtherUnitsValue); | ||||
|       speedUnits_.SetDefault(defaultSpeedUnitsValue); | ||||
|       distanceUnits_.SetDefault(defaultDistanceUnitsValue); | ||||
| 
 | ||||
|       accumulationUnits_.SetValidator( | ||||
|          SCWX_SETTINGS_ENUM_VALIDATOR(types::AccumulationUnits, | ||||
|  | @ -53,6 +57,10 @@ public: | |||
|          SCWX_SETTINGS_ENUM_VALIDATOR(types::SpeedUnits, | ||||
|                                       types::SpeedUnitsIterator(), | ||||
|                                       types::GetSpeedUnitsName)); | ||||
|       distanceUnits_.SetValidator( | ||||
|          SCWX_SETTINGS_ENUM_VALIDATOR(types::DistanceUnits, | ||||
|                                       types::DistanceUnitsIterator(), | ||||
|                                       types::GetDistanceUnitsName)); | ||||
|    } | ||||
| 
 | ||||
|    ~Impl() {} | ||||
|  | @ -61,6 +69,7 @@ public: | |||
|    SettingsVariable<std::string> echoTopsUnits_ {"echo_tops_units"}; | ||||
|    SettingsVariable<std::string> otherUnits_ {"other_units"}; | ||||
|    SettingsVariable<std::string> speedUnits_ {"speed_units"}; | ||||
|    SettingsVariable<std::string> distanceUnits_ {"speed_units"}; | ||||
| }; | ||||
| 
 | ||||
| UnitSettings::UnitSettings() : | ||||
|  | @ -69,7 +78,8 @@ UnitSettings::UnitSettings() : | |||
|    RegisterVariables({&p->accumulationUnits_, | ||||
|                       &p->echoTopsUnits_, | ||||
|                       &p->otherUnits_, | ||||
|                       &p->speedUnits_}); | ||||
|                       &p->speedUnits_, | ||||
|                       &p->distanceUnits_}); | ||||
|    SetDefaults(); | ||||
| } | ||||
| UnitSettings::~UnitSettings() = default; | ||||
|  | @ -97,6 +107,11 @@ SettingsVariable<std::string>& UnitSettings::speed_units() const | |||
|    return p->speedUnits_; | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<std::string>& UnitSettings::distance_units() const | ||||
| { | ||||
|    return p->distanceUnits_; | ||||
| } | ||||
| 
 | ||||
| UnitSettings& UnitSettings::Instance() | ||||
| { | ||||
|    static UnitSettings generalSettings_; | ||||
|  | @ -108,7 +123,8 @@ bool operator==(const UnitSettings& lhs, const UnitSettings& rhs) | |||
|    return (lhs.p->accumulationUnits_ == rhs.p->accumulationUnits_ && | ||||
|            lhs.p->echoTopsUnits_ == rhs.p->echoTopsUnits_ && | ||||
|            lhs.p->otherUnits_ == rhs.p->otherUnits_ && | ||||
|            lhs.p->speedUnits_ == rhs.p->speedUnits_); | ||||
|            lhs.p->speedUnits_ == rhs.p->speedUnits_ && | ||||
|            lhs.p->distanceUnits_ == rhs.p->distanceUnits_); | ||||
| } | ||||
| 
 | ||||
| } // namespace settings
 | ||||
|  |  | |||
|  | @ -29,6 +29,7 @@ public: | |||
|    SettingsVariable<std::string>& echo_tops_units() const; | ||||
|    SettingsVariable<std::string>& other_units() const; | ||||
|    SettingsVariable<std::string>& speed_units() const; | ||||
|    SettingsVariable<std::string>& distance_units() const; | ||||
| 
 | ||||
|    static UnitSettings& Instance(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -89,12 +89,35 @@ static const std::unordered_map<SpeedUnits, float> speedUnitsScale_ { | |||
|    {SpeedUnits::User, 1.0f}, | ||||
|    {SpeedUnits::Unknown, 1.0f}}; | ||||
| 
 | ||||
| static const std::unordered_map<DistanceUnits, std::string> | ||||
|    distanceUnitsAbbreviation_ {{DistanceUnits::Kilometers, "km"}, | ||||
|                                {DistanceUnits::Miles, "mi"}, | ||||
|                                {DistanceUnits::User, ""}, | ||||
|                                {DistanceUnits::Unknown, ""}}; | ||||
| 
 | ||||
| static const std::unordered_map<DistanceUnits, std::string> distanceUnitsName_ { | ||||
|    {DistanceUnits::Kilometers, "Kilometers"}, | ||||
|    {DistanceUnits::Miles, "Miles"}, | ||||
|    {DistanceUnits::User, "User-defined"}, | ||||
|    {DistanceUnits::Unknown, "?"}}; | ||||
| 
 | ||||
| static constexpr auto distanceUnitsBase_ = units::kilometers<float> {1.0f}; | ||||
| static const std::unordered_map<DistanceUnits, float> distanceUnitsScale_ { | ||||
|    {DistanceUnits::Kilometers, | ||||
|     (distanceUnitsBase_ / units::kilometers<float> {1.0f})}, | ||||
|    {DistanceUnits::Miles, | ||||
|     (distanceUnitsBase_ / units::miles<float> {1.0f})}, | ||||
|    {DistanceUnits::User, 1.0f}, | ||||
|    {DistanceUnits::Unknown, 1.0f}}; | ||||
| 
 | ||||
| 
 | ||||
| SCWX_GET_ENUM(AccumulationUnits, | ||||
|               GetAccumulationUnitsFromName, | ||||
|               accumulationUnitsName_) | ||||
| SCWX_GET_ENUM(EchoTopsUnits, GetEchoTopsUnitsFromName, echoTopsUnitsName_) | ||||
| SCWX_GET_ENUM(OtherUnits, GetOtherUnitsFromName, otherUnitsName_) | ||||
| SCWX_GET_ENUM(SpeedUnits, GetSpeedUnitsFromName, speedUnitsName_) | ||||
| SCWX_GET_ENUM(DistanceUnits, GetDistanceUnitsFromName, distanceUnitsName_) | ||||
| 
 | ||||
| const std::string& GetAccumulationUnitsAbbreviation(AccumulationUnits units) | ||||
| { | ||||
|  | @ -146,6 +169,21 @@ float GetSpeedUnitsScale(SpeedUnits units) | |||
|    return speedUnitsScale_.at(units); | ||||
| } | ||||
| 
 | ||||
| const std::string& GetDistanceUnitsAbbreviation(DistanceUnits units) | ||||
| { | ||||
|    return distanceUnitsAbbreviation_.at(units); | ||||
| } | ||||
| 
 | ||||
| const std::string& GetDistanceUnitsName(DistanceUnits units) | ||||
| { | ||||
|    return distanceUnitsName_.at(units); | ||||
| } | ||||
| 
 | ||||
| float GetDistanceUnitsScale(DistanceUnits units) | ||||
| { | ||||
|    return distanceUnitsScale_.at(units); | ||||
| } | ||||
| 
 | ||||
| } // namespace types
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -56,6 +56,17 @@ typedef scwx::util:: | |||
|    Iterator<SpeedUnits, SpeedUnits::KilometersPerHour, SpeedUnits::User> | ||||
|       SpeedUnitsIterator; | ||||
| 
 | ||||
| enum class DistanceUnits | ||||
| { | ||||
|    Kilometers, | ||||
|    Miles, | ||||
|    User, | ||||
|    Unknown | ||||
| }; | ||||
| typedef scwx::util:: | ||||
|    Iterator<DistanceUnits, DistanceUnits::Kilometers, DistanceUnits::User> | ||||
|       DistanceUnitsIterator; | ||||
| 
 | ||||
| const std::string& GetAccumulationUnitsAbbreviation(AccumulationUnits units); | ||||
| const std::string& GetAccumulationUnitsName(AccumulationUnits units); | ||||
| AccumulationUnits  GetAccumulationUnitsFromName(const std::string& name); | ||||
|  | @ -74,6 +85,11 @@ const std::string& GetSpeedUnitsName(SpeedUnits units); | |||
| SpeedUnits         GetSpeedUnitsFromName(const std::string& name); | ||||
| float              GetSpeedUnitsScale(SpeedUnits units); | ||||
| 
 | ||||
| const std::string& GetDistanceUnitsAbbreviation(DistanceUnits units); | ||||
| const std::string& GetDistanceUnitsName(DistanceUnits units); | ||||
| DistanceUnits      GetDistanceUnitsFromName(const std::string& name); | ||||
| float              GetDistanceUnitsScale(DistanceUnits units); | ||||
| 
 | ||||
| } // namespace types
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -102,6 +102,16 @@ public: | |||
|                               types::GetSpeedUnitsName); | ||||
|       AddRow(speedUnits_, "Speed", speedComboBox); | ||||
| 
 | ||||
|       QComboBox* distanceComboBox = new QComboBox(self); | ||||
|       distanceComboBox->setSizePolicy(QSizePolicy::Expanding, | ||||
|                                    QSizePolicy::Preferred); | ||||
|       distanceUnits_.SetSettingsVariable(unitSettings.distance_units()); | ||||
|       SCWX_SETTINGS_COMBO_BOX(distanceUnits_, | ||||
|                               distanceComboBox, | ||||
|                               types::DistanceUnitsIterator(), | ||||
|                               types::GetDistanceUnitsName); | ||||
|       AddRow(distanceUnits_, "Distance", distanceComboBox); | ||||
| 
 | ||||
|       QComboBox* otherComboBox = new QComboBox(self); | ||||
|       otherComboBox->setSizePolicy(QSizePolicy::Expanding, | ||||
|                                    QSizePolicy::Preferred); | ||||
|  | @ -127,6 +137,7 @@ public: | |||
|    settings::SettingsInterface<std::string> echoTopsUnits_ {}; | ||||
|    settings::SettingsInterface<std::string> otherUnits_ {}; | ||||
|    settings::SettingsInterface<std::string> speedUnits_ {}; | ||||
|    settings::SettingsInterface<std::string> distanceUnits_ {}; | ||||
| }; | ||||
| 
 | ||||
| UnitSettingsWidget::UnitSettingsWidget(QWidget* parent) : | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak