mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 11:30:06 +00:00 
			
		
		
		
	Add map copyrights and map provider to map context
This commit is contained in:
		
							parent
							
								
									6b00c55bac
								
							
						
					
					
						commit
						5c7c7e6a19
					
				
					 5 changed files with 73 additions and 25 deletions
				
			
		|  | @ -29,6 +29,9 @@ public: | |||
|    int16_t                                radarProductCode_ {0}; | ||||
|    QMapLibre::CustomLayerRenderParameters renderParameters_ {}; | ||||
| 
 | ||||
|    MapProvider mapProvider_ {MapProvider::Unknown}; | ||||
|    std::string mapCopyrights_ {}; | ||||
| 
 | ||||
|    std::shared_ptr<view::OverlayProductView> overlayProductView_ {nullptr}; | ||||
|    std::shared_ptr<view::RadarProductView>   radarProductView_; | ||||
| }; | ||||
|  | @ -48,6 +51,16 @@ std::weak_ptr<QMapLibre::Map> MapContext::map() const | |||
|    return p->map_; | ||||
| } | ||||
| 
 | ||||
| std::string MapContext::map_copyrights() const | ||||
| { | ||||
|    return p->mapCopyrights_; | ||||
| } | ||||
| 
 | ||||
| MapProvider MapContext::map_provider() const | ||||
| { | ||||
|    return p->mapProvider_; | ||||
| } | ||||
| 
 | ||||
| MapSettings& MapContext::settings() | ||||
| { | ||||
|    return p->settings_; | ||||
|  | @ -94,6 +107,16 @@ void MapContext::set_map(const std::shared_ptr<QMapLibre::Map>& map) | |||
|    p->map_ = map; | ||||
| } | ||||
| 
 | ||||
| void MapContext::set_map_copyrights(const std::string& copyrights) | ||||
| { | ||||
|    p->mapCopyrights_ = copyrights; | ||||
| } | ||||
| 
 | ||||
| void MapContext::set_map_provider(MapProvider provider) | ||||
| { | ||||
|    p->mapProvider_ = provider; | ||||
| } | ||||
| 
 | ||||
| void MapContext::set_overlay_product_view( | ||||
|    const std::shared_ptr<view::OverlayProductView>& overlayProductView) | ||||
| { | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/gl/gl_context.hpp> | ||||
| #include <scwx/qt/map/map_provider.hpp> | ||||
| #include <scwx/common/products.hpp> | ||||
| 
 | ||||
| #include <qmaplibre.hpp> | ||||
|  | @ -36,6 +37,8 @@ public: | |||
|    MapContext& operator=(MapContext&&) noexcept; | ||||
| 
 | ||||
|    std::weak_ptr<QMapLibre::Map>             map() const; | ||||
|    std::string                               map_copyrights() const; | ||||
|    MapProvider                               map_provider() const; | ||||
|    MapSettings&                              settings(); | ||||
|    float                                     pixel_ratio() const; | ||||
|    std::shared_ptr<view::OverlayProductView> overlay_product_view() const; | ||||
|  | @ -46,6 +49,8 @@ public: | |||
|    QMapLibre::CustomLayerRenderParameters    render_parameters() const; | ||||
| 
 | ||||
|    void set_map(const std::shared_ptr<QMapLibre::Map>& map); | ||||
|    void set_map_copyrights(const std::string& copyrights); | ||||
|    void set_map_provider(MapProvider provider); | ||||
|    void set_overlay_product_view( | ||||
|       const std::shared_ptr<view::OverlayProductView>& overlayProductView); | ||||
|    void set_pixel_ratio(float pixelRatio); | ||||
|  |  | |||
|  | @ -44,6 +44,7 @@ | |||
| #include <QKeyEvent> | ||||
| #include <QMouseEvent> | ||||
| #include <QString> | ||||
| #include <QTextDocument> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -94,11 +95,13 @@ public: | |||
|       overlayProductView->SetAutoRefresh(autoRefreshEnabled_); | ||||
|       overlayProductView->SetAutoUpdate(autoUpdateEnabled_); | ||||
| 
 | ||||
|       // Initialize context
 | ||||
|       context_->set_overlay_product_view(overlayProductView); | ||||
| 
 | ||||
|       auto& generalSettings = settings::GeneralSettings::Instance(); | ||||
| 
 | ||||
|       // Initialize context
 | ||||
|       context_->set_map_provider( | ||||
|          GetMapProvider(generalSettings.map_provider().GetValue())); | ||||
|       context_->set_overlay_product_view(overlayProductView); | ||||
| 
 | ||||
|       SetRadarSite(generalSettings.default_radar_site().GetValue()); | ||||
| 
 | ||||
|       // Create ImGui Context
 | ||||
|  | @ -110,9 +113,6 @@ public: | |||
|       // Initialize ImGui Qt backend
 | ||||
|       ImGui_ImplQt_Init(); | ||||
| 
 | ||||
|       // Set Map Provider Details
 | ||||
|       mapProvider_ = GetMapProvider(generalSettings.map_provider().GetValue()); | ||||
| 
 | ||||
|       ConnectSignals(); | ||||
|    } | ||||
| 
 | ||||
|  | @ -143,6 +143,7 @@ public: | |||
|    void AddLayers(); | ||||
|    void AddPlacefileLayer(const std::string& placefileName, | ||||
|                           const std::string& before); | ||||
|    void ConnectMapSignals(); | ||||
|    void ConnectSignals(); | ||||
|    void ImGuiCheckFonts(); | ||||
|    void InitializeNewRadarProductView(const std::string& colorPalette); | ||||
|  | @ -170,7 +171,6 @@ public: | |||
|    std::shared_ptr<MapContext> context_; | ||||
| 
 | ||||
|    MapWidget*                      widget_; | ||||
|    MapProvider                     mapProvider_; | ||||
|    QMapLibre::Settings             settings_; | ||||
|    std::shared_ptr<QMapLibre::Map> map_; | ||||
|    std::list<std::string>          layerList_; | ||||
|  | @ -250,6 +250,24 @@ MapWidget::~MapWidget() | |||
|    makeCurrent(); | ||||
| } | ||||
| 
 | ||||
| void MapWidgetImpl::ConnectMapSignals() | ||||
| { | ||||
|    connect(map_.get(), | ||||
|            &QMapLibre::Map::needsRendering, | ||||
|            this, | ||||
|            &MapWidgetImpl::Update); | ||||
|    connect(map_.get(), | ||||
|            &QMapLibre::Map::copyrightsChanged, | ||||
|            this, | ||||
|            [this](const QString& copyrightsHtml) | ||||
|            { | ||||
|               QTextDocument document {}; | ||||
|               document.setHtml(copyrightsHtml); | ||||
|               context_->set_map_copyrights( | ||||
|                  document.toPlainText().toStdString()); | ||||
|            }); | ||||
| } | ||||
| 
 | ||||
| void MapWidgetImpl::ConnectSignals() | ||||
| { | ||||
|    connect(placefileManager_.get(), | ||||
|  | @ -725,7 +743,8 @@ void MapWidget::SetInitialMapStyle(const std::string& styleName) | |||
| 
 | ||||
| void MapWidget::SetMapStyle(const std::string& styleName) | ||||
| { | ||||
|    const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_); | ||||
|    const auto  mapProvider     = p->context_->map_provider(); | ||||
|    const auto& mapProviderInfo = GetMapProviderInfo(mapProvider); | ||||
|    auto&       styles          = mapProviderInfo.mapStyles_; | ||||
| 
 | ||||
|    for (size_t i = 0u; i < styles.size(); ++i) | ||||
|  | @ -737,8 +756,7 @@ void MapWidget::SetMapStyle(const std::string& styleName) | |||
| 
 | ||||
|          logger_->debug("Updating style: {}", styles[i].name_); | ||||
| 
 | ||||
|          util::maplibre::SetMapStyleUrl( | ||||
|             p->map_, p->mapProvider_, styles[i].url_); | ||||
|          util::maplibre::SetMapStyleUrl(p->context_, styles[i].url_); | ||||
| 
 | ||||
|          if (++p->currentStyleIndex_ == styles.size()) | ||||
|          { | ||||
|  | @ -757,15 +775,16 @@ qreal MapWidget::pixelRatio() | |||
| 
 | ||||
| void MapWidget::changeStyle() | ||||
| { | ||||
|    const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_); | ||||
|    const auto  mapProvider     = p->context_->map_provider(); | ||||
|    const auto& mapProviderInfo = GetMapProviderInfo(mapProvider); | ||||
|    auto&       styles          = mapProviderInfo.mapStyles_; | ||||
| 
 | ||||
|    p->currentStyle_ = &styles[p->currentStyleIndex_]; | ||||
| 
 | ||||
|    logger_->debug("Updating style: {}", styles[p->currentStyleIndex_].name_); | ||||
| 
 | ||||
|    util::maplibre::SetMapStyleUrl( | ||||
|       p->map_, p->mapProvider_, styles[p->currentStyleIndex_].url_); | ||||
|    util::maplibre::SetMapStyleUrl(p->context_, | ||||
|                                   styles[p->currentStyleIndex_].url_); | ||||
| 
 | ||||
|    if (++p->currentStyleIndex_ == styles.size()) | ||||
|    { | ||||
|  | @ -1135,10 +1154,7 @@ void MapWidget::initializeGL() | |||
|    p->map_.reset( | ||||
|       new QMapLibre::Map(nullptr, p->settings_, size(), pixelRatio())); | ||||
|    p->context_->set_map(p->map_); | ||||
|    connect(p->map_.get(), | ||||
|            &QMapLibre::Map::needsRendering, | ||||
|            p.get(), | ||||
|            &MapWidgetImpl::Update); | ||||
|    p->ConnectMapSignals(); | ||||
| 
 | ||||
|    // Set default location to radar site
 | ||||
|    std::shared_ptr<config::RadarSite> radarSite = | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat