mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 05:10:04 +00:00 
			
		
		
		
	Add map style combo box
This commit is contained in:
		
							parent
							
								
									1cd3228e22
								
							
						
					
					
						commit
						e5ffe16efb
					
				
					 4 changed files with 107 additions and 7 deletions
				
			
		|  | @ -75,12 +75,12 @@ public: | |||
|        elevationButtonsChanged_ {false}, | ||||
|        resizeElevationButtons_ {false} | ||||
|    { | ||||
|       map::MapProvider mapProvider = | ||||
|       mapProvider_ = | ||||
|          map::GetMapProvider(manager::SettingsManager::general_settings() | ||||
|                                 .map_provider() | ||||
|                                 .GetValue()); | ||||
|       const map::MapProviderInfo& mapProviderInfo = | ||||
|          map::GetMapProviderInfo(mapProvider); | ||||
|          map::GetMapProviderInfo(mapProvider_); | ||||
| 
 | ||||
|       std::string appDataPath { | ||||
|          QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) | ||||
|  | @ -98,7 +98,7 @@ public: | |||
|          } | ||||
|       } | ||||
| 
 | ||||
|       std::string mapProviderApiKey = map::GetMapProviderApiKey(mapProvider); | ||||
|       std::string mapProviderApiKey = map::GetMapProviderApiKey(mapProvider_); | ||||
| 
 | ||||
|       settings_.resetToTemplate(mapProviderInfo.settingsTemplate_); | ||||
|       settings_.setApiKey(QString {mapProviderApiKey.c_str()}); | ||||
|  | @ -112,6 +112,7 @@ public: | |||
|    void ConnectMapSignals(); | ||||
|    void ConnectOtherSignals(); | ||||
|    void HandleFocusChange(QWidget* focused); | ||||
|    void PopulateMapStyles(); | ||||
|    void SelectElevation(map::MapWidget* mapWidget, float elevation); | ||||
|    void SelectRadarProduct(map::MapWidget*           mapWidget, | ||||
|                            common::RadarProductGroup group, | ||||
|  | @ -120,6 +121,7 @@ public: | |||
|    void SetActiveMap(map::MapWidget* mapWidget); | ||||
|    void UpdateAvailableLevel3Products(); | ||||
|    void UpdateElevationSelection(float elevation); | ||||
|    void UpdateMapStyle(const std::string& styleName); | ||||
|    void UpdateRadarProductSelection(common::RadarProductGroup group, | ||||
|                                     const std::string&        product); | ||||
|    void UpdateRadarProductSettings(); | ||||
|  | @ -128,6 +130,7 @@ public: | |||
| 
 | ||||
|    MainWindow*           mainWindow_; | ||||
|    QMapLibreGL::Settings settings_; | ||||
|    map::MapProvider      mapProvider_; | ||||
|    map::MapWidget*       activeMap_; | ||||
| 
 | ||||
|    ui::Level2ProductsWidget* level2ProductsWidget_; | ||||
|  | @ -252,6 +255,7 @@ MainWindow::MainWindow(QWidget* parent) : | |||
|                             0); | ||||
|    } | ||||
| 
 | ||||
|    p->PopulateMapStyles(); | ||||
|    p->ConnectMapSignals(); | ||||
|    p->ConnectOtherSignals(); | ||||
|    p->HandleFocusChange(p->activeMap_); | ||||
|  | @ -593,6 +597,11 @@ void MainWindowImpl::ConnectMapSignals() | |||
|          }, | ||||
|          Qt::QueuedConnection); | ||||
| 
 | ||||
|       connect(mapWidget, | ||||
|               &map::MapWidget::MapStyleChanged, | ||||
|               this, | ||||
|               &MainWindowImpl::UpdateMapStyle); | ||||
| 
 | ||||
|       connect( | ||||
|          mapWidget, | ||||
|          &map::MapWidget::RadarSweepUpdated, | ||||
|  | @ -631,6 +640,11 @@ void MainWindowImpl::ConnectOtherSignals() | |||
|            &QApplication::focusChanged, | ||||
|            mainWindow_, | ||||
|            [this](QWidget* /*old*/, QWidget* now) { HandleFocusChange(now); }); | ||||
|    connect(mainWindow_->ui->mapStyleComboBox, | ||||
|            &QComboBox::currentTextChanged, | ||||
|            mainWindow_, | ||||
|            [&](const QString& text) | ||||
|            { activeMap_->SetMapStyle(text.toStdString()); }); | ||||
|    connect(level2ProductsWidget_, | ||||
|            &ui::Level2ProductsWidget::RadarProductSelected, | ||||
|            mainWindow_, | ||||
|  | @ -703,6 +717,7 @@ void MainWindowImpl::HandleFocusChange(QWidget* focused) | |||
|    { | ||||
|       SetActiveMap(mapWidget); | ||||
|       UpdateAvailableLevel3Products(); | ||||
|       UpdateMapStyle(mapWidget->GetMapStyle()); | ||||
|       UpdateRadarProductSelection(mapWidget->GetRadarProductGroup(), | ||||
|                                   mapWidget->GetRadarProductName()); | ||||
|       UpdateRadarProductSettings(); | ||||
|  | @ -711,6 +726,16 @@ void MainWindowImpl::HandleFocusChange(QWidget* focused) | |||
|    } | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::PopulateMapStyles() | ||||
| { | ||||
|    const auto& mapProviderInfo = map::GetMapProviderInfo(mapProvider_); | ||||
|    for (const auto& mapStyle : mapProviderInfo.mapStyles_) | ||||
|    { | ||||
|       mainWindow_->ui->mapStyleComboBox->addItem( | ||||
|          QString::fromStdString(mapStyle.name_)); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::SelectElevation(map::MapWidget* mapWidget, float elevation) | ||||
| { | ||||
|    if (mapWidget == activeMap_) | ||||
|  | @ -774,6 +799,16 @@ void MainWindowImpl::UpdateMapParameters( | |||
|    } | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::UpdateMapStyle(const std::string& styleName) | ||||
| { | ||||
|    int index = mainWindow_->ui->mapStyleComboBox->findText( | ||||
|       QString::fromStdString(styleName)); | ||||
|    if (index != -1) | ||||
|    { | ||||
|       mainWindow_->ui->mapStyleComboBox->setCurrentIndex(index); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::UpdateRadarProductSelection( | ||||
|    common::RadarProductGroup group, const std::string& product) | ||||
| { | ||||
|  |  | |||
|  | @ -184,6 +184,25 @@ | |||
|        </layout> | ||||
|       </widget> | ||||
|      </item> | ||||
|      <item> | ||||
|       <widget class="QGroupBox" name="mapSettingsGroupBox"> | ||||
|        <property name="title"> | ||||
|         <string>Map Settings</string> | ||||
|        </property> | ||||
|        <layout class="QVBoxLayout" name="verticalLayout_5"> | ||||
|         <item> | ||||
|          <widget class="QLabel" name="mapStyleLabel"> | ||||
|           <property name="text"> | ||||
|            <string>Map Style</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <widget class="QComboBox" name="mapStyleComboBox"/> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </widget> | ||||
|      </item> | ||||
|      <item> | ||||
|       <widget class="QGroupBox" name="radarProductGroupBox"> | ||||
|        <property name="title"> | ||||
|  |  | |||
|  | @ -64,6 +64,7 @@ public: | |||
|        selectedTime_ {}, | ||||
|        lastPos_(), | ||||
|        currentStyleIndex_ {0}, | ||||
|        currentStyle_ {nullptr}, | ||||
|        frameDraws_(0), | ||||
|        prevLatitude_ {0.0}, | ||||
|        prevLongitude_ {0.0}, | ||||
|  | @ -148,8 +149,9 @@ public: | |||
|    common::Level2Product                 selectedLevel2Product_; | ||||
|    std::chrono::system_clock::time_point selectedTime_; | ||||
| 
 | ||||
|    QPointF lastPos_; | ||||
|    uint8_t currentStyleIndex_; | ||||
|    QPointF         lastPos_; | ||||
|    std::size_t     currentStyleIndex_; | ||||
|    const MapStyle* currentStyle_; | ||||
| 
 | ||||
|    uint64_t frameDraws_; | ||||
| 
 | ||||
|  | @ -260,6 +262,18 @@ std::vector<std::string> MapWidget::GetLevel3Products() | |||
|    } | ||||
| } | ||||
| 
 | ||||
| std::string MapWidget::GetMapStyle() const | ||||
| { | ||||
|    if (p->currentStyle_ != nullptr) | ||||
|    { | ||||
|       return p->currentStyle_->name_; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       return "?"; | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| common::RadarProductGroup MapWidget::GetRadarProductGroup() const | ||||
| { | ||||
|    auto radarProductView = p->context_->radar_product_view(); | ||||
|  | @ -530,6 +544,32 @@ void MapWidget::SetMapParameters( | |||
|    } | ||||
| } | ||||
| 
 | ||||
| void MapWidget::SetMapStyle(const std::string& styleName) | ||||
| { | ||||
|    const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_); | ||||
|    auto&       styles          = mapProviderInfo.mapStyles_; | ||||
| 
 | ||||
|    for (size_t i = 0u; i < styles.size(); ++i) | ||||
|    { | ||||
|       if (styles[i].name_ == styleName) | ||||
|       { | ||||
|          p->currentStyleIndex_ = i; | ||||
|          p->currentStyle_      = &styles[i]; | ||||
| 
 | ||||
|          logger_->debug("Updating style: {}", styles[i].name_); | ||||
| 
 | ||||
|          p->map_->setStyleUrl(styles[i].url_.c_str()); | ||||
| 
 | ||||
|          if (++p->currentStyleIndex_ == styles.size()) | ||||
|          { | ||||
|             p->currentStyleIndex_ = 0; | ||||
|          } | ||||
| 
 | ||||
|          break; | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| qreal MapWidget::pixelRatio() | ||||
| { | ||||
|    return devicePixelRatioF(); | ||||
|  | @ -540,6 +580,8 @@ void MapWidget::changeStyle() | |||
|    const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_); | ||||
|    auto&       styles          = mapProviderInfo.mapStyles_; | ||||
| 
 | ||||
|    p->currentStyle_ = &styles[p->currentStyleIndex_]; | ||||
| 
 | ||||
|    logger_->debug("Updating style: {}", styles[p->currentStyleIndex_].name_); | ||||
| 
 | ||||
|    p->map_->setStyleUrl(styles[p->currentStyleIndex_].url_.c_str()); | ||||
|  | @ -548,6 +590,8 @@ void MapWidget::changeStyle() | |||
|    { | ||||
|       p->currentStyleIndex_ = 0; | ||||
|    } | ||||
| 
 | ||||
|    emit MapStyleChanged(p->currentStyle_->name_); | ||||
| } | ||||
| 
 | ||||
| void MapWidget::AddLayers() | ||||
|  | @ -571,8 +615,7 @@ void MapWidget::AddLayers() | |||
|       std::shared_ptr<config::RadarSite> radarSite = | ||||
|          p->radarProductManager_->radar_site(); | ||||
| 
 | ||||
|       const auto& mapStyle = | ||||
|          GetMapProviderInfo(p->mapProvider_).mapStyles_[p->currentStyleIndex_]; | ||||
|       const auto& mapStyle = *p->currentStyle_; | ||||
| 
 | ||||
|       std::string before = "ferry"; | ||||
| 
 | ||||
|  |  | |||
|  | @ -38,6 +38,7 @@ public: | |||
|    float                              GetElevation() const; | ||||
|    std::vector<float>                 GetElevationCuts() const; | ||||
|    std::vector<std::string>           GetLevel3Products(); | ||||
|    std::string                        GetMapStyle() const; | ||||
|    common::RadarProductGroup          GetRadarProductGroup() const; | ||||
|    std::string                        GetRadarProductName() const; | ||||
|    std::shared_ptr<config::RadarSite> GetRadarSite() const; | ||||
|  | @ -98,6 +99,7 @@ public: | |||
|                          double zoom, | ||||
|                          double bearing, | ||||
|                          double pitch); | ||||
|    void SetMapStyle(const std::string& styleName); | ||||
| 
 | ||||
| private: | ||||
|    void  changeStyle(); | ||||
|  | @ -129,6 +131,7 @@ signals: | |||
|                              double zoom, | ||||
|                              double bearing, | ||||
|                              double pitch); | ||||
|    void MapStyleChanged(const std::string& styleName); | ||||
|    void RadarSweepUpdated(); | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat