diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 32d900ce..becb5901 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -129,12 +129,14 @@ set(SRC_SETTINGS source/scwx/qt/settings/general_settings.cpp source/scwx/qt/settings/settings_interface_base.cpp source/scwx/qt/settings/settings_variable.cpp source/scwx/qt/settings/settings_variable_base.cpp) -set(HDR_TYPES source/scwx/qt/types/font_types.hpp +set(HDR_TYPES source/scwx/qt/types/alert_types.hpp + source/scwx/qt/types/font_types.hpp source/scwx/qt/types/github_types.hpp source/scwx/qt/types/qt_types.hpp source/scwx/qt/types/radar_product_record.hpp source/scwx/qt/types/text_event_key.hpp) -set(SRC_TYPES source/scwx/qt/types/github_types.cpp +set(SRC_TYPES source/scwx/qt/types/alert_types.cpp + source/scwx/qt/types/github_types.cpp source/scwx/qt/types/radar_product_record.cpp source/scwx/qt/types/text_event_key.cpp) set(HDR_UI source/scwx/qt/ui/about_dialog.hpp diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.cpp b/scwx-qt/source/scwx/qt/settings/general_settings.cpp index 19c97f8a..0375ecc4 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -20,12 +21,21 @@ class GeneralSettingsImpl public: explicit GeneralSettingsImpl() { + std::string defaultDefaultAlertActionValue = + types::GetAlertActionName(types::AlertAction::Go); + std::string defaultMapProviderValue = + map::GetMapProviderName(map::MapProvider::MapTiler); + + boost::to_lower(defaultDefaultAlertActionValue); + boost::to_lower(defaultMapProviderValue); + debugEnabled_.SetDefault(false); + defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue); defaultRadarSite_.SetDefault("KLSX"); fontSizes_.SetDefault({16}); gridWidth_.SetDefault(1); gridHeight_.SetDefault(1); - mapProvider_.SetDefault("maptiler"); + mapProvider_.SetDefault(defaultMapProviderValue); mapboxApiKey_.SetDefault("?"); maptilerApiKey_.SetDefault("?"); updateNotificationsEnabled_.SetDefault(true); @@ -38,6 +48,26 @@ public: gridWidth_.SetMaximum(2); gridHeight_.SetMinimum(1); gridHeight_.SetMaximum(2); + + defaultAlertAction_.SetValidator( + [](const std::string& value) + { + for (types::AlertAction alertAction : types::AlertActionIterator()) + { + // If the value is equal to a lower case alert action name + std::string alertActionName = + types::GetAlertActionName(alertAction); + boost::to_lower(alertActionName); + if (value == alertActionName) + { + // Regard as a match, valid + return true; + } + } + + // No match found, invalid + return false; + }); mapProvider_.SetValidator( [](const std::string& value) { @@ -66,6 +96,7 @@ public: ~GeneralSettingsImpl() {} SettingsVariable debugEnabled_ {"debug_enabled"}; + SettingsVariable defaultAlertAction_ {"default_alert_action"}; SettingsVariable defaultRadarSite_ {"default_radar_site"}; SettingsContainer> fontSizes_ {"font_sizes"}; SettingsVariable gridWidth_ {"grid_width"}; @@ -80,6 +111,7 @@ GeneralSettings::GeneralSettings() : SettingsCategory("general"), p(std::make_unique()) { RegisterVariables({&p->debugEnabled_, + &p->defaultAlertAction_, &p->defaultRadarSite_, &p->fontSizes_, &p->gridWidth_, @@ -101,6 +133,11 @@ SettingsVariable& GeneralSettings::debug_enabled() const return p->debugEnabled_; } +SettingsVariable& GeneralSettings::default_alert_action() const +{ + return p->defaultAlertAction_; +} + SettingsVariable& GeneralSettings::default_radar_site() const { return p->defaultRadarSite_; @@ -145,6 +182,7 @@ SettingsVariable& GeneralSettings::update_notifications_enabled() const bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) { return (lhs.p->debugEnabled_ == rhs.p->debugEnabled_ && + lhs.p->defaultAlertAction_ == rhs.p->defaultAlertAction_ && lhs.p->defaultRadarSite_ == rhs.p->defaultRadarSite_ && lhs.p->fontSizes_ == rhs.p->fontSizes_ && lhs.p->gridWidth_ == rhs.p->gridWidth_ && diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.hpp b/scwx-qt/source/scwx/qt/settings/general_settings.hpp index a565f09e..4d54074d 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.hpp @@ -28,6 +28,7 @@ public: GeneralSettings& operator=(GeneralSettings&&) noexcept; SettingsVariable& debug_enabled() const; + SettingsVariable& default_alert_action() const; SettingsVariable& default_radar_site() const; SettingsContainer>& font_sizes() const; SettingsVariable& grid_height() const; diff --git a/scwx-qt/source/scwx/qt/types/alert_types.cpp b/scwx-qt/source/scwx/qt/types/alert_types.cpp new file mode 100644 index 00000000..34e44a95 --- /dev/null +++ b/scwx-qt/source/scwx/qt/types/alert_types.cpp @@ -0,0 +1,42 @@ +#include + +#include + +namespace scwx +{ +namespace qt +{ +namespace types +{ + +static const std::unordered_map alertActionName_ { + {AlertAction::Go, "Go"}, + {AlertAction::View, "View"}, + {AlertAction::Unknown, "?"}}; + +AlertAction GetAlertAction(const std::string& name) +{ + auto result = + std::find_if(alertActionName_.cbegin(), + alertActionName_.cend(), + [&](const std::pair& pair) -> bool + { return boost::iequals(pair.second, name); }); + + if (result != alertActionName_.cend()) + { + return result->first; + } + else + { + return AlertAction::Unknown; + } +} + +std::string GetAlertActionName(AlertAction alertAction) +{ + return alertActionName_.at(alertAction); +} + +} // namespace types +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/types/alert_types.hpp b/scwx-qt/source/scwx/qt/types/alert_types.hpp new file mode 100644 index 00000000..19431d4c --- /dev/null +++ b/scwx-qt/source/scwx/qt/types/alert_types.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include + +namespace scwx +{ +namespace qt +{ +namespace types +{ + +enum class AlertAction +{ + Go, + View, + Unknown +}; +typedef scwx::util::Iterator + AlertActionIterator; + +AlertAction GetAlertAction(const std::string& name); +std::string GetAlertActionName(AlertAction alertAction); + +} // namespace types +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp b/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp index 59acceae..f8da6d6e 100644 --- a/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp +++ b/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp @@ -1,9 +1,11 @@ #include "alert_dock_widget.hpp" #include "ui_alert_dock_widget.h" +#include #include #include #include +#include #include #include #include @@ -165,6 +167,39 @@ void AlertDockWidgetImpl::ConnectSignals() logger_->debug("Selected: {}", selectedAlertKey_.ToString()); }); + connect(self_->ui->alertView, + &QTreeView::doubleClicked, + this, + [this](const QModelIndex& /* index */) + { + // If an item is selected + if (selectedAlertKey_ != types::TextEventKey {}) + { + types::AlertAction alertAction = types::GetAlertAction( + manager::SettingsManager::general_settings() + .default_alert_action() + .GetValue()); + + switch (alertAction) + { + case types::AlertAction::Go: + // Move map + emit self_->MoveMap(selectedAlertCentroid_.latitude_, + selectedAlertCentroid_.longitude_); + break; + + case types::AlertAction::View: + // View alert + alertDialog_->SelectAlert(selectedAlertKey_); + alertDialog_->show(); + break; + + default: + // Do nothing + break; + } + } + }); connect(self_->ui->alertViewButton, &QPushButton::clicked, this, diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index 5793f6bb..27b49c22 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,7 @@ public: &mapProvider_, &mapboxApiKey_, &mapTilerApiKey_, + &defaultAlertAction_, &updateNotificationsEnabled_, &debugEnabled_}} { @@ -144,8 +146,9 @@ public: settings::SettingsInterface mapProvider_ {}; settings::SettingsInterface mapboxApiKey_ {}; settings::SettingsInterface mapTilerApiKey_ {}; - settings::SettingsInterface updateNotificationsEnabled_ {}; - settings::SettingsInterface debugEnabled_ {}; + settings::SettingsInterface defaultAlertAction_ {}; + settings::SettingsInterface updateNotificationsEnabled_ {}; + settings::SettingsInterface debugEnabled_ {}; std::unordered_map> colorTables_ {}; @@ -331,10 +334,13 @@ void SettingsDialogImpl::SetupGeneralTab() { for (map::MapProvider mapProvider : map::MapProviderIterator()) { - if (boost::iequals(text, map::GetMapProviderName(mapProvider))) + const std::string mapProviderName = + map::GetMapProviderName(mapProvider); + + if (boost::iequals(text, mapProviderName)) { // Return map provider label - return GetMapProviderName(mapProvider); + return mapProviderName; } } @@ -359,6 +365,42 @@ void SettingsDialogImpl::SetupGeneralTab() mapTilerApiKey_.SetEditWidget(self_->ui->mapTilerApiKeyLineEdit); mapTilerApiKey_.SetResetButton(self_->ui->resetMapTilerApiKeyButton); + for (const auto& alertAction : types::AlertActionIterator()) + { + self_->ui->defaultAlertActionComboBox->addItem( + QString::fromStdString(types::GetAlertActionName(alertAction))); + } + + defaultAlertAction_.SetSettingsVariable( + generalSettings.default_alert_action()); + defaultAlertAction_.SetMapFromValueFunction( + [](const std::string& text) -> std::string + { + for (types::AlertAction alertAction : types::AlertActionIterator()) + { + const std::string alertActionName = + types::GetAlertActionName(alertAction); + + if (boost::iequals(text, alertActionName)) + { + // Return alert action label + return alertActionName; + } + } + + // Alert action label not found, return unknown + return "?"; + }); + defaultAlertAction_.SetMapToValueFunction( + [](std::string text) -> std::string + { + // Convert label to lower case and return + boost::to_lower(text); + return text; + }); + defaultAlertAction_.SetEditWidget(self_->ui->defaultAlertActionComboBox); + defaultAlertAction_.SetResetButton(self_->ui->resetDefaultAlertActionButton); + updateNotificationsEnabled_.SetSettingsVariable( generalSettings.update_notifications_enabled()); updateNotificationsEnabled_.SetEditWidget( diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui index 9a748feb..e12f8909 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui @@ -109,39 +109,58 @@ 0 + + + + + + + Font Sizes + + + + + + + + + + Default Radar Site + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + - - + + - ... + Mapbox API Key - - + + - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + MapTiler API Key - - - - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - + + - + ... @@ -152,17 +171,10 @@ - - + + - Font Sizes - - - - - - - MapTiler API Key + ... @@ -177,8 +189,22 @@ - - + + + + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + @@ -199,12 +225,9 @@ - + - - - - + ... @@ -215,19 +238,6 @@ - - - - - - - Mapbox API Key - - - - - - @@ -235,25 +245,36 @@ - - - - Default Radar Site - - - - + Map Provider - - + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + - - + + + + Default Alert Action + + + + + + + + ... diff --git a/test/data b/test/data index 938b0240..93eb0d15 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 938b0240e51aff37530adc679a11d0e65e5e96ce +Subproject commit 93eb0d154ce70675812c5569a51c4fdadedbc24d