mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 07:00:06 +00:00 
			
		
		
		
	Separate radar product manager selection to avoid multiple connections
This commit is contained in:
		
							parent
							
								
									eb576c5172
								
							
						
					
					
						commit
						f6262bba65
					
				
					 1 changed files with 82 additions and 36 deletions
				
			
		|  | @ -57,12 +57,11 @@ public: | ||||||
|        settings_(settings), |        settings_(settings), | ||||||
|        map_(), |        map_(), | ||||||
|        layerList_ {}, |        layerList_ {}, | ||||||
|        radarProductManager_ {manager::RadarProductManager::Instance( |        radarProductManager_ {nullptr}, | ||||||
|           scwx::qt::manager::SettingsManager::general_settings() |  | ||||||
|              ->default_radar_site())}, |  | ||||||
|        radarProductLayer_ {nullptr}, |        radarProductLayer_ {nullptr}, | ||||||
|        overlayLayer_ {nullptr}, |        overlayLayer_ {nullptr}, | ||||||
|        colorTableLayer_ {nullptr}, |        colorTableLayer_ {nullptr}, | ||||||
|  |        autoRefreshEnabled_ {true}, | ||||||
|        selectedLevel2Product_ {common::Level2Product::Unknown}, |        selectedLevel2Product_ {common::Level2Product::Unknown}, | ||||||
|        selectedTime_ {}, |        selectedTime_ {}, | ||||||
|        lastPos_(), |        lastPos_(), | ||||||
|  | @ -74,12 +73,17 @@ public: | ||||||
|        prevBearing_ {0.0}, |        prevBearing_ {0.0}, | ||||||
|        prevPitch_ {0.0} |        prevPitch_ {0.0} | ||||||
|    { |    { | ||||||
|  |       SetRadarSite(scwx::qt::manager::SettingsManager::general_settings() | ||||||
|  |                       ->default_radar_site()); | ||||||
|    } |    } | ||||||
|    ~MapWidgetImpl() = default; |    ~MapWidgetImpl() = default; | ||||||
| 
 | 
 | ||||||
|    void AddLayer(const std::string&            id, |    void AddLayer(const std::string&            id, | ||||||
|                  std::shared_ptr<GenericLayer> layer, |                  std::shared_ptr<GenericLayer> layer, | ||||||
|                  const std::string&            before = {}); |                  const std::string&            before = {}); | ||||||
|  |    void AutoRefreshConnect(); | ||||||
|  |    void AutoRefreshDisconnect(); | ||||||
|  |    void SetRadarSite(const std::string& radarSite); | ||||||
|    bool UpdateStoredMapParameters(); |    bool UpdateStoredMapParameters(); | ||||||
| 
 | 
 | ||||||
|    common::Level2Product |    common::Level2Product | ||||||
|  | @ -100,6 +104,8 @@ public: | ||||||
|    std::shared_ptr<OverlayLayer>      overlayLayer_; |    std::shared_ptr<OverlayLayer>      overlayLayer_; | ||||||
|    std::shared_ptr<ColorTableLayer>   colorTableLayer_; |    std::shared_ptr<ColorTableLayer>   colorTableLayer_; | ||||||
| 
 | 
 | ||||||
|  |    bool autoRefreshEnabled_; | ||||||
|  | 
 | ||||||
|    common::Level2Product                 selectedLevel2Product_; |    common::Level2Product                 selectedLevel2Product_; | ||||||
|    std::chrono::system_clock::time_point selectedTime_; |    std::chrono::system_clock::time_point selectedTime_; | ||||||
| 
 | 
 | ||||||
|  | @ -273,35 +279,6 @@ void MapWidget::SelectRadarProduct(common::Level2Product product) | ||||||
|       }, |       }, | ||||||
|       Qt::QueuedConnection); |       Qt::QueuedConnection); | ||||||
| 
 | 
 | ||||||
|    connect( |  | ||||||
|       p->radarProductManager_.get(), |  | ||||||
|       &manager::RadarProductManager::NewLevel2DataAvailable, |  | ||||||
|       this, |  | ||||||
|       [&](std::chrono::system_clock::time_point latestTime) |  | ||||||
|       { |  | ||||||
|          std::shared_ptr<request::NexradFileRequest> request = |  | ||||||
|             std::make_shared<request::NexradFileRequest>(); |  | ||||||
| 
 |  | ||||||
|          connect(request.get(), |  | ||||||
|                  &request::NexradFileRequest::RequestComplete, |  | ||||||
|                  this, |  | ||||||
|                  [&](std::shared_ptr<request::NexradFileRequest> request) |  | ||||||
|                  { |  | ||||||
|                     auto record = request->radar_product_record(); |  | ||||||
| 
 |  | ||||||
|                     if (record != nullptr) |  | ||||||
|                     { |  | ||||||
|                        SelectRadarProduct(record); |  | ||||||
|                     } |  | ||||||
|                  }); |  | ||||||
| 
 |  | ||||||
|          // TODO: If live data is enabled
 |  | ||||||
|          util::async( |  | ||||||
|             [=]() |  | ||||||
|             { p->radarProductManager_->LoadLevel2Data(latestTime, request); }); |  | ||||||
|       }, |  | ||||||
|       Qt::QueuedConnection); |  | ||||||
| 
 |  | ||||||
|    util::async( |    util::async( | ||||||
|       [=]() |       [=]() | ||||||
|       { |       { | ||||||
|  | @ -353,8 +330,8 @@ void MapWidget::SelectRadarProduct( | ||||||
|       common::Level2Product level2Product = |       common::Level2Product level2Product = | ||||||
|          p->GetLevel2ProductOrDefault(product); |          p->GetLevel2ProductOrDefault(product); | ||||||
| 
 | 
 | ||||||
|       p->radarProductManager_ = manager::RadarProductManager::Instance(radarId); |       p->SetRadarSite(radarId); | ||||||
|       p->selectedTime_        = time; |       p->selectedTime_ = time; | ||||||
| 
 | 
 | ||||||
|       SelectRadarProduct(level2Product); |       SelectRadarProduct(level2Product); | ||||||
|    } |    } | ||||||
|  | @ -374,8 +351,8 @@ void MapWidget::SelectRadarProduct( | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       p->context_->radarProductView_ = radarProductView; |       p->context_->radarProductView_ = radarProductView; | ||||||
|       p->radarProductManager_        = radarProductManager; |       p->SetRadarSite(radarId); | ||||||
|       p->selectedTime_               = time; |       p->selectedTime_ = time; | ||||||
|       radarProductView->SelectTime(p->selectedTime_); |       radarProductView->SelectTime(p->selectedTime_); | ||||||
| 
 | 
 | ||||||
|       connect( |       connect( | ||||||
|  | @ -655,6 +632,75 @@ void MapWidget::mapChanged(QMapboxGL::MapChange mapChange) | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void MapWidgetImpl::AutoRefreshConnect() | ||||||
|  | { | ||||||
|  |    if (radarProductManager_ != nullptr) | ||||||
|  |    { | ||||||
|  |       connect( | ||||||
|  |          radarProductManager_.get(), | ||||||
|  |          &manager::RadarProductManager::NewLevel2DataAvailable, | ||||||
|  |          this, | ||||||
|  |          [&](std::chrono::system_clock::time_point latestTime) | ||||||
|  |          { | ||||||
|  |             // Create file request
 | ||||||
|  |             std::shared_ptr<request::NexradFileRequest> request = | ||||||
|  |                std::make_shared<request::NexradFileRequest>(); | ||||||
|  | 
 | ||||||
|  |             // File request callback
 | ||||||
|  |             connect(request.get(), | ||||||
|  |                     &request::NexradFileRequest::RequestComplete, | ||||||
|  |                     this, | ||||||
|  |                     [&](std::shared_ptr<request::NexradFileRequest> request) | ||||||
|  |                     { | ||||||
|  |                        // Select loaded record
 | ||||||
|  |                        auto record = request->radar_product_record(); | ||||||
|  | 
 | ||||||
|  |                        if (record != nullptr) | ||||||
|  |                        { | ||||||
|  |                           widget_->SelectRadarProduct(record); | ||||||
|  |                        } | ||||||
|  |                     }); | ||||||
|  | 
 | ||||||
|  |             // Load file
 | ||||||
|  |             util::async( | ||||||
|  |                [=]() | ||||||
|  |                { radarProductManager_->LoadLevel2Data(latestTime, request); }); | ||||||
|  |          }, | ||||||
|  |          Qt::QueuedConnection); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void MapWidgetImpl::AutoRefreshDisconnect() | ||||||
|  | { | ||||||
|  |    if (radarProductManager_ != nullptr) | ||||||
|  |    { | ||||||
|  |       disconnect(radarProductManager_.get(), | ||||||
|  |                  &manager::RadarProductManager::NewLevel2DataAvailable, | ||||||
|  |                  this, | ||||||
|  |                  nullptr); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void MapWidgetImpl::SetRadarSite(const std::string& radarSite) | ||||||
|  | { | ||||||
|  |    // Check if radar site has changed
 | ||||||
|  |    if (radarProductManager_ == nullptr || | ||||||
|  |        radarSite != radarProductManager_->radar_site()->id()) | ||||||
|  |    { | ||||||
|  |       // Disconnect signals from old RadarProductManager
 | ||||||
|  |       AutoRefreshDisconnect(); | ||||||
|  | 
 | ||||||
|  |       // Set new RadarProductManager
 | ||||||
|  |       radarProductManager_ = manager::RadarProductManager::Instance(radarSite); | ||||||
|  | 
 | ||||||
|  |       // Connect signals to new RadarProductManager
 | ||||||
|  |       if (autoRefreshEnabled_) | ||||||
|  |       { | ||||||
|  |          AutoRefreshConnect(); | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void MapWidgetImpl::Update() | void MapWidgetImpl::Update() | ||||||
| { | { | ||||||
|    widget_->update(); |    widget_->update(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat