mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:40:05 +00:00 
			
		
		
		
	Add Map Provider and MapTiler API key to settings dialog
This commit is contained in:
		
							parent
							
								
									eed7e8e5e9
								
							
						
					
					
						commit
						9c5de8e9ee
					
				
					 2 changed files with 136 additions and 49 deletions
				
			
		|  | @ -12,6 +12,7 @@ | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| #include <scwx/util/threads.hpp> | #include <scwx/util/threads.hpp> | ||||||
| 
 | 
 | ||||||
|  | #include <boost/algorithm/string.hpp> | ||||||
| #include <fmt/format.h> | #include <fmt/format.h> | ||||||
| #include <QColorDialog> | #include <QColorDialog> | ||||||
| #include <QFileDialog> | #include <QFileDialog> | ||||||
|  | @ -35,6 +36,8 @@ struct ColorTableConversions | ||||||
|    float    scale {1.0f}; |    float    scale {1.0f}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | static const std::array<std::string, 2> kMapProviders_ {"Mapbox", "MapTiler"}; | ||||||
|  | 
 | ||||||
| static const std::array<std::pair<std::string, std::string>, 15> | static const std::array<std::pair<std::string, std::string>, 15> | ||||||
|    kColorTableTypes_ {std::pair {"BR", "BR"}, |    kColorTableTypes_ {std::pair {"BR", "BR"}, | ||||||
|                       std::pair {"BV", "BV"}, |                       std::pair {"BV", "BV"}, | ||||||
|  | @ -83,7 +86,9 @@ public: | ||||||
|           &fontSizes_, |           &fontSizes_, | ||||||
|           &gridWidth_, |           &gridWidth_, | ||||||
|           &gridHeight_, |           &gridHeight_, | ||||||
|  |           &mapProvider_, | ||||||
|           &mapboxApiKey_, |           &mapboxApiKey_, | ||||||
|  |           &mapTilerApiKey_, | ||||||
|           &updateNotificationsEnabled_, |           &updateNotificationsEnabled_, | ||||||
|           &debugEnabled_}} |           &debugEnabled_}} | ||||||
|    { |    { | ||||||
|  | @ -137,7 +142,9 @@ public: | ||||||
|    settings::SettingsInterface<std::vector<std::int64_t>> fontSizes_ {}; |    settings::SettingsInterface<std::vector<std::int64_t>> fontSizes_ {}; | ||||||
|    settings::SettingsInterface<std::int64_t>              gridWidth_ {}; |    settings::SettingsInterface<std::int64_t>              gridWidth_ {}; | ||||||
|    settings::SettingsInterface<std::int64_t>              gridHeight_ {}; |    settings::SettingsInterface<std::int64_t>              gridHeight_ {}; | ||||||
|  |    settings::SettingsInterface<std::string>               mapProvider_ {}; | ||||||
|    settings::SettingsInterface<std::string>               mapboxApiKey_ {}; |    settings::SettingsInterface<std::string>               mapboxApiKey_ {}; | ||||||
|  |    settings::SettingsInterface<std::string>               mapTilerApiKey_ {}; | ||||||
|    settings::SettingsInterface<bool> updateNotificationsEnabled_ {}; |    settings::SettingsInterface<bool> updateNotificationsEnabled_ {}; | ||||||
|    settings::SettingsInterface<bool> debugEnabled_ {}; |    settings::SettingsInterface<bool> debugEnabled_ {}; | ||||||
| 
 | 
 | ||||||
|  | @ -313,10 +320,48 @@ void SettingsDialogImpl::SetupGeneralTab() | ||||||
|    gridHeight_.SetEditWidget(self_->ui->gridHeightSpinBox); |    gridHeight_.SetEditWidget(self_->ui->gridHeightSpinBox); | ||||||
|    gridHeight_.SetResetButton(self_->ui->resetGridHeightButton); |    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_.SetSettingsVariable(generalSettings.mapbox_api_key()); | ||||||
|    mapboxApiKey_.SetEditWidget(self_->ui->mapboxApiKeyLineEdit); |    mapboxApiKey_.SetEditWidget(self_->ui->mapboxApiKeyLineEdit); | ||||||
|    mapboxApiKey_.SetResetButton(self_->ui->resetMapboxApiKeyButton); |    mapboxApiKey_.SetResetButton(self_->ui->resetMapboxApiKeyButton); | ||||||
| 
 | 
 | ||||||
|  |    mapTilerApiKey_.SetSettingsVariable(generalSettings.maptiler_api_key()); | ||||||
|  |    mapTilerApiKey_.SetEditWidget(self_->ui->mapTilerApiKeyLineEdit); | ||||||
|  |    mapTilerApiKey_.SetResetButton(self_->ui->resetMapTilerApiKeyButton); | ||||||
|  | 
 | ||||||
|    updateNotificationsEnabled_.SetSettingsVariable( |    updateNotificationsEnabled_.SetSettingsVariable( | ||||||
|       generalSettings.update_notifications_enabled()); |       generalSettings.update_notifications_enabled()); | ||||||
|    updateNotificationsEnabled_.SetEditWidget( |    updateNotificationsEnabled_.SetEditWidget( | ||||||
|  |  | ||||||
|  | @ -109,43 +109,14 @@ | ||||||
|              <property name="bottomMargin"> |              <property name="bottomMargin"> | ||||||
|               <number>0</number> |               <number>0</number> | ||||||
|              </property> |              </property> | ||||||
|              <item row="0" column="0"> |              <item row="1" column="2"> | ||||||
|               <widget class="QLabel" name="label"> |               <widget class="QLineEdit" name="fontSizesLineEdit"/> | ||||||
|                <property name="text"> |  | ||||||
|                 <string>Default Radar Site</string> |  | ||||||
|                </property> |  | ||||||
|               </widget> |  | ||||||
|              </item> |              </item> | ||||||
|              <item row="3" column="0"> |              <item row="0" column="3"> | ||||||
|               <widget class="QLabel" name="label_3"> |               <widget class="QToolButton" name="radarSiteSelectButton"> | ||||||
|                <property name="text"> |  | ||||||
|                 <string>Grid Height</string> |  | ||||||
|                </property> |  | ||||||
|               </widget> |  | ||||||
|              </item> |  | ||||||
|              <item row="3" column="2"> |  | ||||||
|               <widget class="QSpinBox" name="gridHeightSpinBox"/> |  | ||||||
|              </item> |  | ||||||
|              <item row="2" column="4"> |  | ||||||
|               <widget class="QToolButton" name="resetGridWidthButton"> |  | ||||||
|                <property name="text"> |                <property name="text"> | ||||||
|                 <string>...</string> |                 <string>...</string> | ||||||
|                </property> |                </property> | ||||||
|                <property name="icon"> |  | ||||||
|                 <iconset resource="../../../../scwx-qt.qrc"> |  | ||||||
|                  <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> |  | ||||||
|                </property> |  | ||||||
|               </widget> |  | ||||||
|              </item> |  | ||||||
|              <item row="4" column="4"> |  | ||||||
|               <widget class="QToolButton" name="resetMapboxApiKeyButton"> |  | ||||||
|                <property name="text"> |  | ||||||
|                 <string>...</string> |  | ||||||
|                </property> |  | ||||||
|                <property name="icon"> |  | ||||||
|                 <iconset resource="../../../../scwx-qt.qrc"> |  | ||||||
|                  <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> |  | ||||||
|                </property> |  | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|              <item row="0" column="4"> |              <item row="0" column="4"> | ||||||
|  | @ -159,11 +130,41 @@ | ||||||
|                </property> |                </property> | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|              <item row="2" column="2"> |              <item row="2" column="4"> | ||||||
|               <widget class="QSpinBox" name="gridWidthSpinBox"/> |               <widget class="QToolButton" name="resetGridWidthButton"> | ||||||
|  |                <property name="text"> | ||||||
|  |                 <string>...</string> | ||||||
|  |                </property> | ||||||
|  |                <property name="icon"> | ||||||
|  |                 <iconset resource="../../../../scwx-qt.qrc"> | ||||||
|  |                  <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> | ||||||
|  |                </property> | ||||||
|  |               </widget> | ||||||
|              </item> |              </item> | ||||||
|              <item row="0" column="2"> |              <item row="6" column="4"> | ||||||
|               <widget class="QComboBox" name="radarSiteComboBox"/> |               <widget class="QToolButton" name="resetMapTilerApiKeyButton"> | ||||||
|  |                <property name="text"> | ||||||
|  |                 <string>...</string> | ||||||
|  |                </property> | ||||||
|  |                <property name="icon"> | ||||||
|  |                 <iconset resource="../../../../scwx-qt.qrc"> | ||||||
|  |                  <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> | ||||||
|  |                </property> | ||||||
|  |               </widget> | ||||||
|  |              </item> | ||||||
|  |              <item row="1" column="0"> | ||||||
|  |               <widget class="QLabel" name="label_5"> | ||||||
|  |                <property name="text"> | ||||||
|  |                 <string>Font Sizes</string> | ||||||
|  |                </property> | ||||||
|  |               </widget> | ||||||
|  |              </item> | ||||||
|  |              <item row="6" column="0"> | ||||||
|  |               <widget class="QLabel" name="label_6"> | ||||||
|  |                <property name="text"> | ||||||
|  |                 <string>MapTiler API Key</string> | ||||||
|  |                </property> | ||||||
|  |               </widget> | ||||||
|              </item> |              </item> | ||||||
|              <item row="3" column="4"> |              <item row="3" column="4"> | ||||||
|               <widget class="QToolButton" name="resetGridHeightButton"> |               <widget class="QToolButton" name="resetGridHeightButton"> | ||||||
|  | @ -176,13 +177,13 @@ | ||||||
|                </property> |                </property> | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|              <item row="1" column="2"> |              <item row="2" column="2"> | ||||||
|               <widget class="QLineEdit" name="fontSizesLineEdit"/> |               <widget class="QSpinBox" name="gridWidthSpinBox"/> | ||||||
|              </item> |              </item> | ||||||
|              <item row="4" column="0"> |              <item row="3" column="0"> | ||||||
|               <widget class="QLabel" name="label_4"> |               <widget class="QLabel" name="label_3"> | ||||||
|                <property name="text"> |                <property name="text"> | ||||||
|                 <string>Mapbox API Key</string> |                 <string>Grid Height</string> | ||||||
|                </property> |                </property> | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|  | @ -197,16 +198,36 @@ | ||||||
|                </property> |                </property> | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|              <item row="4" column="2"> |              <item row="6" column="2"> | ||||||
|               <widget class="QLineEdit" name="mapboxApiKeyLineEdit"/> |               <widget class="QLineEdit" name="mapTilerApiKeyLineEdit"/> | ||||||
|              </item> |              </item> | ||||||
|              <item row="1" column="0"> |              <item row="0" column="2"> | ||||||
|               <widget class="QLabel" name="label_5"> |               <widget class="QComboBox" name="radarSiteComboBox"/> | ||||||
|  |              </item> | ||||||
|  |              <item row="5" column="4"> | ||||||
|  |               <widget class="QToolButton" name="resetMapboxApiKeyButton"> | ||||||
|                <property name="text"> |                <property name="text"> | ||||||
|                 <string>Font Sizes</string> |                 <string>...</string> | ||||||
|  |                </property> | ||||||
|  |                <property name="icon"> | ||||||
|  |                 <iconset resource="../../../../scwx-qt.qrc"> | ||||||
|  |                  <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> | ||||||
|                </property> |                </property> | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|  |              <item row="5" column="2"> | ||||||
|  |               <widget class="QLineEdit" name="mapboxApiKeyLineEdit"/> | ||||||
|  |              </item> | ||||||
|  |              <item row="5" column="0"> | ||||||
|  |               <widget class="QLabel" name="label_4"> | ||||||
|  |                <property name="text"> | ||||||
|  |                 <string>Mapbox API Key</string> | ||||||
|  |                </property> | ||||||
|  |               </widget> | ||||||
|  |              </item> | ||||||
|  |              <item row="3" column="2"> | ||||||
|  |               <widget class="QSpinBox" name="gridHeightSpinBox"/> | ||||||
|  |              </item> | ||||||
|              <item row="2" column="0"> |              <item row="2" column="0"> | ||||||
|               <widget class="QLabel" name="label_2"> |               <widget class="QLabel" name="label_2"> | ||||||
|                <property name="text"> |                <property name="text"> | ||||||
|  | @ -214,11 +235,32 @@ | ||||||
|                </property> |                </property> | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|              <item row="0" column="3"> |              <item row="0" column="0"> | ||||||
|               <widget class="QToolButton" name="radarSiteSelectButton"> |               <widget class="QLabel" name="label"> | ||||||
|  |                <property name="text"> | ||||||
|  |                 <string>Default Radar Site</string> | ||||||
|  |                </property> | ||||||
|  |               </widget> | ||||||
|  |              </item> | ||||||
|  |              <item row="4" column="0"> | ||||||
|  |               <widget class="QLabel" name="label_7"> | ||||||
|  |                <property name="text"> | ||||||
|  |                 <string>Map Provider</string> | ||||||
|  |                </property> | ||||||
|  |               </widget> | ||||||
|  |              </item> | ||||||
|  |              <item row="4" column="2"> | ||||||
|  |               <widget class="QComboBox" name="mapProviderComboBox"/> | ||||||
|  |              </item> | ||||||
|  |              <item row="4" column="4"> | ||||||
|  |               <widget class="QToolButton" name="resetMapProviderButton"> | ||||||
|                <property name="text"> |                <property name="text"> | ||||||
|                 <string>...</string> |                 <string>...</string> | ||||||
|                </property> |                </property> | ||||||
|  |                <property name="icon"> | ||||||
|  |                 <iconset resource="../../../../scwx-qt.qrc"> | ||||||
|  |                  <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> | ||||||
|  |                </property> | ||||||
|               </widget> |               </widget> | ||||||
|              </item> |              </item> | ||||||
|             </layout> |             </layout> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat