mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 02:10:05 +00:00 
			
		
		
		
	
							parent
							
								
									effe78e1be
								
							
						
					
					
						commit
						6000abdeb3
					
				
					 7 changed files with 120 additions and 7 deletions
				
			
		|  | @ -113,6 +113,7 @@ public: | |||
| 
 | ||||
|    void AsyncSetup(); | ||||
|    void ConfigureMapLayout(); | ||||
|    void ConfigureMapStyles(); | ||||
|    void ConnectAnimationSignals(); | ||||
|    void ConnectMapSignals(); | ||||
|    void ConnectOtherSignals(); | ||||
|  | @ -275,6 +276,7 @@ MainWindow::MainWindow(QWidget* parent) : | |||
|    } | ||||
| 
 | ||||
|    p->PopulateMapStyles(); | ||||
|    p->ConfigureMapStyles(); | ||||
|    p->ConnectMapSignals(); | ||||
|    p->ConnectAnimationSignals(); | ||||
|    p->ConnectOtherSignals(); | ||||
|  | @ -597,6 +599,39 @@ void MainWindowImpl::ConfigureMapLayout() | |||
|    SetActiveMap(maps_.at(0)); | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::ConfigureMapStyles() | ||||
| { | ||||
|    const auto& mapProviderInfo = map::GetMapProviderInfo(mapProvider_); | ||||
|    auto&       mapSettings     = manager::SettingsManager::map_settings(); | ||||
| 
 | ||||
|    for (std::size_t i = 0; i < maps_.size(); i++) | ||||
|    { | ||||
|       std::string styleName = mapSettings.map_style(i).GetValue(); | ||||
| 
 | ||||
|       if (std::find_if(mapProviderInfo.mapStyles_.cbegin(), | ||||
|                        mapProviderInfo.mapStyles_.cend(), | ||||
|                        [&](const auto& mapStyle) { | ||||
|                           return mapStyle.name_ == styleName; | ||||
|                        }) != mapProviderInfo.mapStyles_.cend()) | ||||
|       { | ||||
|          // Initialize map style from settings
 | ||||
|          maps_.at(i)->SetInitialMapStyle(styleName); | ||||
| 
 | ||||
|          // Update the active map's style
 | ||||
|          if (maps_[i] == activeMap_) | ||||
|          { | ||||
|             UpdateMapStyle(styleName); | ||||
|          } | ||||
|       } | ||||
|       else if (!mapProviderInfo.mapStyles_.empty()) | ||||
|       { | ||||
|          // Stage first valid map style from map provider
 | ||||
|          mapSettings.map_style(i).StageValue( | ||||
|             mapProviderInfo.mapStyles_.at(0).name_); | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::ConnectMapSignals() | ||||
| { | ||||
|    for (const auto& mapWidget : maps_) | ||||
|  | @ -621,7 +656,13 @@ void MainWindowImpl::ConnectMapSignals() | |||
|       connect(mapWidget, | ||||
|               &map::MapWidget::MapStyleChanged, | ||||
|               this, | ||||
|               &MainWindowImpl::UpdateMapStyle); | ||||
|               [&](const std::string& mapStyle) | ||||
|               { | ||||
|                  if (mapWidget == activeMap_) | ||||
|                  { | ||||
|                     UpdateMapStyle(mapStyle); | ||||
|                  } | ||||
|               }); | ||||
| 
 | ||||
|       connect( | ||||
|          mapWidget, | ||||
|  | @ -758,7 +799,21 @@ void MainWindowImpl::ConnectOtherSignals() | |||
|            &QComboBox::currentTextChanged, | ||||
|            mainWindow_, | ||||
|            [&](const QString& text) | ||||
|            { activeMap_->SetMapStyle(text.toStdString()); }); | ||||
|            { | ||||
|               activeMap_->SetMapStyle(text.toStdString()); | ||||
| 
 | ||||
|               // Update settings for active map
 | ||||
|               for (std::size_t i = 0; i < maps_.size(); ++i) | ||||
|               { | ||||
|                  if (maps_[i] == activeMap_) | ||||
|                  { | ||||
|                     auto& mapSettings = | ||||
|                        manager::SettingsManager::map_settings(); | ||||
|                     mapSettings.map_style(i).StageValue(text.toStdString()); | ||||
|                     break; | ||||
|                  } | ||||
|               } | ||||
|            }); | ||||
|    connect(level2ProductsWidget_, | ||||
|            &ui::Level2ProductsWidget::RadarProductSelected, | ||||
|            mainWindow_, | ||||
|  | @ -925,6 +980,17 @@ void MainWindowImpl::UpdateMapStyle(const std::string& styleName) | |||
|    if (index != -1) | ||||
|    { | ||||
|       mainWindow_->ui->mapStyleComboBox->setCurrentIndex(index); | ||||
| 
 | ||||
|       // Update settings for active map
 | ||||
|       for (std::size_t i = 0; i < maps_.size(); ++i) | ||||
|       { | ||||
|          if (maps_[i] == activeMap_) | ||||
|          { | ||||
|             auto& mapSettings = manager::SettingsManager::map_settings(); | ||||
|             mapSettings.map_style(i).StageValue(styleName); | ||||
|             break; | ||||
|          } | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -95,6 +95,7 @@ void Shutdown() | |||
|    bool dataChanged = false; | ||||
| 
 | ||||
|    dataChanged |= general_settings().Shutdown(); | ||||
|    dataChanged |= map_settings().Shutdown(); | ||||
| 
 | ||||
|    if (dataChanged) | ||||
|    { | ||||
|  |  | |||
|  | @ -154,6 +154,7 @@ public: | |||
|    QPointF         lastPos_; | ||||
|    std::size_t     currentStyleIndex_; | ||||
|    const MapStyle* currentStyle_; | ||||
|    std::string     initialStyleName_ {}; | ||||
| 
 | ||||
|    uint64_t frameDraws_; | ||||
| 
 | ||||
|  | @ -585,6 +586,11 @@ void MapWidget::SetMapParameters( | |||
|    } | ||||
| } | ||||
| 
 | ||||
| void MapWidget::SetInitialMapStyle(const std::string& styleName) | ||||
| { | ||||
|    p->initialStyleName_ = styleName; | ||||
| } | ||||
| 
 | ||||
| void MapWidget::SetMapStyle(const std::string& styleName) | ||||
| { | ||||
|    const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_); | ||||
|  | @ -830,7 +836,14 @@ void MapWidget::initializeGL() | |||
|                                p->prevPitch_); | ||||
| 
 | ||||
|    // Update style
 | ||||
|    changeStyle(); | ||||
|    if (p->initialStyleName_.empty()) | ||||
|    { | ||||
|       changeStyle(); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       SetMapStyle(p->initialStyleName_); | ||||
|    } | ||||
| 
 | ||||
|    connect(p->map_.get(), | ||||
|            &QMapLibreGL::Map::mapChanged, | ||||
|  |  | |||
|  | @ -111,6 +111,7 @@ public: | |||
|                          double zoom, | ||||
|                          double bearing, | ||||
|                          double pitch); | ||||
|    void SetInitialMapStyle(const std::string& styleName); | ||||
|    void SetMapStyle(const std::string& styleName); | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -23,10 +23,12 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | |||
| static constexpr std::size_t kCount_            = 4u; | ||||
| static const std::string     kDefaultRadarSite_ = "KLSX"; | ||||
| 
 | ||||
| static const std::string kMapStyleName_ {"map_style"}; | ||||
| static const std::string kRadarSiteName_ {"radar_site"}; | ||||
| static const std::string kRadarProductGroupName_ {"radar_product_group"}; | ||||
| static const std::string kRadarProductName_ {"radar_product"}; | ||||
| 
 | ||||
| static const std::string                   kDefaultMapStyle_ {"?"}; | ||||
| static constexpr common::RadarProductGroup kDefaultRadarProductGroup_ = | ||||
|    common::RadarProductGroup::Level3; | ||||
| static const std::string kDefaultRadarProductGroupString_ = "L3"; | ||||
|  | @ -38,6 +40,7 @@ class MapSettingsImpl | |||
| public: | ||||
|    struct MapData | ||||
|    { | ||||
|       SettingsVariable<std::string> mapStyle_ {kMapStyleName_}; | ||||
|       SettingsVariable<std::string> radarSite_ {kRadarSiteName_}; | ||||
|       SettingsVariable<std::string> radarProductGroup_ { | ||||
|          kRadarProductGroupName_}; | ||||
|  | @ -48,6 +51,7 @@ public: | |||
|    { | ||||
|       for (std::size_t i = 0; i < kCount_; i++) | ||||
|       { | ||||
|          map_[i].mapStyle_.SetDefault(kDefaultMapStyle_); | ||||
|          map_[i].radarSite_.SetDefault(kDefaultRadarSite_); | ||||
|          map_[i].radarProductGroup_.SetDefault( | ||||
|             kDefaultRadarProductGroupString_); | ||||
|  | @ -90,7 +94,8 @@ public: | |||
|             }); | ||||
| 
 | ||||
|          variables_.insert(variables_.cend(), | ||||
|                            {&map_[i].radarSite_, | ||||
|                            {&map_[i].mapStyle_, | ||||
|                             &map_[i].radarSite_, | ||||
|                             &map_[i].radarProductGroup_, | ||||
|                             &map_[i].radarProduct_}); | ||||
|       } | ||||
|  | @ -100,6 +105,7 @@ public: | |||
| 
 | ||||
|    void SetDefaults(std::size_t i) | ||||
|    { | ||||
|       map_[i].mapStyle_.SetValueToDefault(); | ||||
|       map_[i].radarSite_.SetValueToDefault(); | ||||
|       map_[i].radarProductGroup_.SetValueToDefault(); | ||||
|       map_[i].radarProduct_.SetValueToDefault(); | ||||
|  | @ -127,6 +133,11 @@ std::size_t MapSettings::count() const | |||
|    return kCount_; | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<std::string>& MapSettings::map_style(std::size_t i) const | ||||
| { | ||||
|    return p->map_[i].mapStyle_; | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<std::string>& MapSettings::radar_site(std::size_t i) const | ||||
| { | ||||
|    return p->map_[i].radarSite_; | ||||
|  | @ -143,6 +154,21 @@ SettingsVariable<std::string>& MapSettings::radar_product(std::size_t i) const | |||
|    return p->map_[i].radarProduct_; | ||||
| } | ||||
| 
 | ||||
| bool MapSettings::Shutdown() | ||||
| { | ||||
|    bool dataChanged = false; | ||||
| 
 | ||||
|    // Commit settings that are managed separate from the settings dialog
 | ||||
|    for (std::size_t i = 0; i < kCount_; ++i) | ||||
|    { | ||||
|       MapSettingsImpl::MapData& mapRecordSettings = p->map_[i]; | ||||
| 
 | ||||
|       dataChanged |= mapRecordSettings.mapStyle_.Commit(); | ||||
|    } | ||||
| 
 | ||||
|    return dataChanged; | ||||
| } | ||||
| 
 | ||||
| bool MapSettings::ReadJson(const boost::json::object& json) | ||||
| { | ||||
|    bool validated = true; | ||||
|  | @ -161,6 +187,7 @@ bool MapSettings::ReadJson(const boost::json::object& json) | |||
|             MapSettingsImpl::MapData&  mapRecordSettings = p->map_[i]; | ||||
| 
 | ||||
|             // Load JSON Elements
 | ||||
|             validated &= mapRecordSettings.mapStyle_.ReadValue(mapRecord); | ||||
|             validated &= mapRecordSettings.radarSite_.ReadValue(mapRecord); | ||||
|             validated &= | ||||
|                mapRecordSettings.radarProductGroup_.ReadValue(mapRecord); | ||||
|  | @ -211,7 +238,8 @@ void tag_invoke(boost::json::value_from_tag, | |||
|                 boost::json::value&             jv, | ||||
|                 const MapSettingsImpl::MapData& data) | ||||
| { | ||||
|    jv = {{kRadarSiteName_, data.radarSite_.GetValue()}, | ||||
|    jv = {{kMapStyleName_, data.mapStyle_.GetValue()}, | ||||
|          {kRadarSiteName_, data.radarSite_.GetValue()}, | ||||
|          {kRadarProductGroupName_, data.radarProductGroup_.GetValue()}, | ||||
|          {kRadarProductName_, data.radarProduct_.GetValue()}}; | ||||
| } | ||||
|  | @ -224,7 +252,8 @@ bool operator==(const MapSettings& lhs, const MapSettings& rhs) | |||
| bool operator==(const MapSettingsImpl::MapData& lhs, | ||||
|                 const MapSettingsImpl::MapData& rhs) | ||||
| { | ||||
|    return (lhs.radarSite_ == rhs.radarSite_ && | ||||
|    return (lhs.mapStyle_ == rhs.mapStyle_ && //
 | ||||
|            lhs.radarSite_ == rhs.radarSite_ && | ||||
|            lhs.radarProductGroup_ == rhs.radarProductGroup_ && | ||||
|            lhs.radarProduct_ == rhs.radarProduct_); | ||||
| } | ||||
|  |  | |||
|  | @ -28,10 +28,13 @@ public: | |||
|    MapSettings& operator=(MapSettings&&) noexcept; | ||||
| 
 | ||||
|    std::size_t                    count() const; | ||||
|    SettingsVariable<std::string>& map_style(std::size_t i) const; | ||||
|    SettingsVariable<std::string>& radar_site(std::size_t i) const; | ||||
|    SettingsVariable<std::string>& radar_product_group(std::size_t i) const; | ||||
|    SettingsVariable<std::string>& radar_product(std::size_t i) const; | ||||
| 
 | ||||
|    bool Shutdown(); | ||||
| 
 | ||||
|    /**
 | ||||
|     * Reads the variables from the JSON object. | ||||
|     * | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat