From 9c5de8e9ee498d6086ca094c9799cd30d2658414 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Thu, 27 Apr 2023 22:33:13 -0500 Subject: [PATCH] Add Map Provider and MapTiler API key to settings dialog --- scwx-qt/source/scwx/qt/ui/settings_dialog.cpp | 45 ++++++ scwx-qt/source/scwx/qt/ui/settings_dialog.ui | 140 ++++++++++++------ 2 files changed, 136 insertions(+), 49 deletions(-) diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index b8250d7f..359abb7b 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,8 @@ struct ColorTableConversions float scale {1.0f}; }; +static const std::array kMapProviders_ {"Mapbox", "MapTiler"}; + static const std::array, 15> kColorTableTypes_ {std::pair {"BR", "BR"}, std::pair {"BV", "BV"}, @@ -83,7 +86,9 @@ public: &fontSizes_, &gridWidth_, &gridHeight_, + &mapProvider_, &mapboxApiKey_, + &mapTilerApiKey_, &updateNotificationsEnabled_, &debugEnabled_}} { @@ -137,7 +142,9 @@ public: settings::SettingsInterface> fontSizes_ {}; settings::SettingsInterface gridWidth_ {}; settings::SettingsInterface gridHeight_ {}; + settings::SettingsInterface mapProvider_ {}; settings::SettingsInterface mapboxApiKey_ {}; + settings::SettingsInterface mapTilerApiKey_ {}; settings::SettingsInterface updateNotificationsEnabled_ {}; settings::SettingsInterface debugEnabled_ {}; @@ -313,10 +320,48 @@ void SettingsDialogImpl::SetupGeneralTab() gridHeight_.SetEditWidget(self_->ui->gridHeightSpinBox); gridHeight_.SetResetButton(self_->ui->resetGridHeightButton); + for (const auto& mapProvider : kMapProviders_) + { + self_->ui->mapProviderComboBox->addItem( + QString::fromStdString(mapProvider)); + } + + mapProvider_.SetSettingsVariable(generalSettings.map_provider()); + mapProvider_.SetMapFromValueFunction( + [](const std::string& text) -> std::string + { + auto it = std::find_if(kMapProviders_.cbegin(), + kMapProviders_.cend(), + [&text](const std::string& mapProvider) + { return boost::iequals(text, mapProvider); }); + + if (it == kMapProviders_.cend()) + { + // Map provider label not found, return unknown + return "?"; + } + + // Return map provider label + return *it; + }); + mapProvider_.SetMapToValueFunction( + [](std::string text) -> std::string + { + // Convert label to lower case and return + boost::to_lower(text); + return text; + }); + mapProvider_.SetEditWidget(self_->ui->mapProviderComboBox); + mapProvider_.SetResetButton(self_->ui->resetMapProviderButton); + mapboxApiKey_.SetSettingsVariable(generalSettings.mapbox_api_key()); mapboxApiKey_.SetEditWidget(self_->ui->mapboxApiKeyLineEdit); mapboxApiKey_.SetResetButton(self_->ui->resetMapboxApiKeyButton); + mapTilerApiKey_.SetSettingsVariable(generalSettings.maptiler_api_key()); + mapTilerApiKey_.SetEditWidget(self_->ui->mapTilerApiKeyLineEdit); + mapTilerApiKey_.SetResetButton(self_->ui->resetMapTilerApiKeyButton); + 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 f021c230..9a748feb 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui @@ -109,43 +109,14 @@ 0 - - - - Default Radar Site - - + + - - - - Grid Height - - - - - - - - + + ... - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - - - - - - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - @@ -159,11 +130,41 @@ - - + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + - - + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + + + + + Font Sizes + + + + + + + MapTiler API Key + + @@ -176,13 +177,13 @@ - - + + - - + + - Mapbox API Key + Grid Height @@ -197,16 +198,36 @@ - - + + - - + + + + + - Font Sizes + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + + + + + Mapbox API Key + + + + + + @@ -214,11 +235,32 @@ - - + + + + Default Radar Site + + + + + + + Map Provider + + + + + + + + ... + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg +