mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 13:20:06 +00:00 
			
		
		
		
	Check currently selected level 3 tilt
This commit is contained in:
		
							parent
							
								
									14545fd83a
								
							
						
					
					
						commit
						3b7518006b
					
				
					 1 changed files with 50 additions and 51 deletions
				
			
		|  | @ -27,8 +27,9 @@ public: | ||||||
|        self_ {self}, |        self_ {self}, | ||||||
|        layout_ {new ui::FlowLayout(self)}, |        layout_ {new ui::FlowLayout(self)}, | ||||||
|        categoryButtons_ {}, |        categoryButtons_ {}, | ||||||
|        availableCategoryMap_ {}, |        productTiltMap_ {}, | ||||||
|        availableCategoryMutex_ {} |        awipsProductMap_ {}, | ||||||
|  |        awipsProductMutex_ {} | ||||||
|    { |    { | ||||||
|       layout_->setContentsMargins(0, 0, 0, 0); |       layout_->setContentsMargins(0, 0, 0, 0); | ||||||
| 
 | 
 | ||||||
|  | @ -60,11 +61,19 @@ public: | ||||||
|             QMenu* productMenu = categoryMenu->addMenu(QString::fromStdString( |             QMenu* productMenu = categoryMenu->addMenu(QString::fromStdString( | ||||||
|                common::GetLevel3ProductDescription(product))); |                common::GetLevel3ProductDescription(product))); | ||||||
| 
 | 
 | ||||||
|  |             std::vector<QAction*>& productTilts = productTiltMap_[product]; | ||||||
|  | 
 | ||||||
|             for (size_t tilt = 1; tilt <= common::kLevel3ProductMaxTilts; |             for (size_t tilt = 1; tilt <= common::kLevel3ProductMaxTilts; | ||||||
|                  ++tilt) |                  ++tilt) | ||||||
|             { |             { | ||||||
|                QAction* action = |                QAction* action = | ||||||
|                   productMenu->addAction(tr("Tilt %1").arg(tilt)); |                   productMenu->addAction(tr("Tilt %1").arg(tilt)); | ||||||
|  |                action->setCheckable(true); | ||||||
|  | 
 | ||||||
|  |                std::unique_lock lock {awipsProductMutex_}; | ||||||
|  | 
 | ||||||
|  |                productTilts.push_back(action); | ||||||
|  |                awipsProductMap_.emplace(action, "?"); | ||||||
| 
 | 
 | ||||||
|                QObject::connect( |                QObject::connect( | ||||||
|                   action, |                   action, | ||||||
|  | @ -72,33 +81,14 @@ public: | ||||||
|                   this, |                   this, | ||||||
|                   [=]() |                   [=]() | ||||||
|                   { |                   { | ||||||
|                      std::shared_lock lock {availableCategoryMutex_}; |                      std::shared_lock lock {awipsProductMutex_}; | ||||||
| 
 |                      std::string awipsProductName {awipsProductMap_.at(action)}; | ||||||
|                      // Find product map associated with current category
 |  | ||||||
|                      auto productMapIt = availableCategoryMap_.find(category); |  | ||||||
|                      if (productMapIt != availableCategoryMap_.cend()) |  | ||||||
|                      { |  | ||||||
|                         // Find tilt list associated with current product
 |  | ||||||
|                         auto tiltListIt = productMapIt->second.find(product); |  | ||||||
|                         if (tiltListIt != productMapIt->second.cend()) |  | ||||||
|                         { |  | ||||||
|                            // Find AWIPS product in tilt list
 |  | ||||||
|                            if (tilt <= tiltListIt->second.size()) |  | ||||||
|                            { |  | ||||||
|                               std::string awipsProductName = |  | ||||||
|                                  tiltListIt->second.at(tilt - 1); |  | ||||||
| 
 | 
 | ||||||
|                      self_->UpdateProductSelection( |                      self_->UpdateProductSelection( | ||||||
|                                  common::RadarProductGroup::Level3, |                         common::RadarProductGroup::Level3, awipsProductName); | ||||||
|                                  awipsProductName); |  | ||||||
| 
 | 
 | ||||||
|                      emit self_->RadarProductSelected( |                      emit self_->RadarProductSelected( | ||||||
|                                  common::RadarProductGroup::Level3, |                         common::RadarProductGroup::Level3, awipsProductName, 0); | ||||||
|                                  awipsProductName, |  | ||||||
|                                  0); |  | ||||||
|                            } |  | ||||||
|                         } |  | ||||||
|                      } |  | ||||||
|                   }); |                   }); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | @ -114,7 +104,8 @@ public: | ||||||
| 
 | 
 | ||||||
|    void NormalizeProductButtons(); |    void NormalizeProductButtons(); | ||||||
|    void SelectProductCategory(common::Level3ProductCategory category); |    void SelectProductCategory(common::Level3ProductCategory category); | ||||||
|    void UpdateProductSelection(common::Level3ProductCategory category); |    void UpdateCategorySelection(common::Level3ProductCategory category); | ||||||
|  |    void UpdateProductSelection(const std::string& awipsId); | ||||||
| 
 | 
 | ||||||
|    Level3ProductsWidget*   self_; |    Level3ProductsWidget*   self_; | ||||||
|    QLayout*                layout_; |    QLayout*                layout_; | ||||||
|  | @ -123,8 +114,10 @@ public: | ||||||
|                       std::unordered_map<std::string, QMenu*>> |                       std::unordered_map<std::string, QMenu*>> | ||||||
|       categoryMenuMap_; |       categoryMenuMap_; | ||||||
| 
 | 
 | ||||||
|    common::Level3ProductCategoryMap availableCategoryMap_; |    std::unordered_map<std::string, std::vector<QAction*>> productTiltMap_; | ||||||
|    std::shared_mutex                availableCategoryMutex_; | 
 | ||||||
|  |    std::unordered_map<QAction*, std::string> awipsProductMap_; | ||||||
|  |    std::shared_mutex                         awipsProductMutex_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| Level3ProductsWidget::Level3ProductsWidget(QWidget* parent) : | Level3ProductsWidget::Level3ProductsWidget(QWidget* parent) : | ||||||
|  | @ -169,7 +162,7 @@ void Level3ProductsWidgetImpl::NormalizeProductButtons() | ||||||
| void Level3ProductsWidgetImpl::SelectProductCategory( | void Level3ProductsWidgetImpl::SelectProductCategory( | ||||||
|    common::Level3ProductCategory category) |    common::Level3ProductCategory category) | ||||||
| { | { | ||||||
|    UpdateProductSelection(category); |    UpdateCategorySelection(category); | ||||||
| 
 | 
 | ||||||
|    emit self_->RadarProductSelected( |    emit self_->RadarProductSelected( | ||||||
|       common::RadarProductGroup::Level3, |       common::RadarProductGroup::Level3, | ||||||
|  | @ -182,14 +175,8 @@ void Level3ProductsWidget::UpdateAvailableProducts( | ||||||
| { | { | ||||||
|    logger_->trace("UpdateAvailableProducts()"); |    logger_->trace("UpdateAvailableProducts()"); | ||||||
| 
 | 
 | ||||||
|    { |  | ||||||
|       std::unique_lock lock {p->availableCategoryMutex_}; |  | ||||||
|       p->availableCategoryMap_ = updatedCategoryMap; |  | ||||||
|    } |  | ||||||
| 
 |  | ||||||
|    // Iterate through each category tool button
 |    // Iterate through each category tool button
 | ||||||
|    std::for_each( |    std::for_each( | ||||||
|       // std::execution::par_unseq,
 |  | ||||||
|       p->categoryButtons_.cbegin(), |       p->categoryButtons_.cbegin(), | ||||||
|       p->categoryButtons_.cend(), |       p->categoryButtons_.cend(), | ||||||
|       [&](QToolButton* toolButton) |       [&](QToolButton* toolButton) | ||||||
|  | @ -212,7 +199,6 @@ void Level3ProductsWidget::UpdateAvailableProducts( | ||||||
| 
 | 
 | ||||||
|             // Iterate through each product menu
 |             // Iterate through each product menu
 | ||||||
|             std::for_each( |             std::for_each( | ||||||
|                // std::execution::par_unseq,
 |  | ||||||
|                productMenus.cbegin(), |                productMenus.cbegin(), | ||||||
|                productMenus.cend(), |                productMenus.cend(), | ||||||
|                [&](const auto productMenu) |                [&](const auto productMenu) | ||||||
|  | @ -228,21 +214,22 @@ void Level3ProductsWidget::UpdateAvailableProducts( | ||||||
|                   if (productEnabled) |                   if (productEnabled) | ||||||
|                   { |                   { | ||||||
|                      // Determine number of tilts to display
 |                      // Determine number of tilts to display
 | ||||||
|                      size_t numTilts = |                      const size_t numTilts = | ||||||
|                         std::min(availableAwipsIdIter->second.size(), |                         std::min(availableAwipsIdIter->second.size(), | ||||||
|                                  common::kLevel3ProductMaxTilts); |                                  common::kLevel3ProductMaxTilts); | ||||||
|                      size_t currentTilt = 0; |  | ||||||
| 
 | 
 | ||||||
|                      QList<QAction*> tiltActionList = |                      const std::vector<QAction*>& tiltActionList = | ||||||
|                         productMenu.second->findChildren<QAction*>( |                         p->productTiltMap_.at(productMenu.first); | ||||||
|                            Qt::FindDirectChildrenOnly); |  | ||||||
| 
 | 
 | ||||||
|                      for (QAction* tiltAction : tiltActionList) |                      for (size_t i = 0; i < tiltActionList.size(); i++) | ||||||
|                      { |                      { | ||||||
|                         // Set the first n tilts to visible. The QAction list
 |                         bool visible = (i < numTilts); | ||||||
|                         // includes the productMenu's action, so one is
 |                         tiltActionList[i]->setVisible(visible); | ||||||
|                         // added.
 | 
 | ||||||
|                         tiltAction->setVisible(++currentTilt <= numTilts + 1); |                         std::unique_lock lock {p->awipsProductMutex_}; | ||||||
|  | 
 | ||||||
|  |                         p->awipsProductMap_[tiltActionList[i]] = | ||||||
|  |                            visible ? availableAwipsIdIter->second[i] : "?"; | ||||||
|                      } |                      } | ||||||
|                   } |                   } | ||||||
|                }); |                }); | ||||||
|  | @ -257,15 +244,16 @@ void Level3ProductsWidget::UpdateProductSelection( | ||||||
|    { |    { | ||||||
|       common::Level3ProductCategory category = |       common::Level3ProductCategory category = | ||||||
|          common::GetLevel3CategoryByAwipsId(productName); |          common::GetLevel3CategoryByAwipsId(productName); | ||||||
|       p->UpdateProductSelection(category); |       p->UpdateCategorySelection(category); | ||||||
|  |       p->UpdateProductSelection(productName); | ||||||
|    } |    } | ||||||
|    else |    else | ||||||
|    { |    { | ||||||
|       p->UpdateProductSelection(common::Level3ProductCategory::Unknown); |       p->UpdateCategorySelection(common::Level3ProductCategory::Unknown); | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Level3ProductsWidgetImpl::UpdateProductSelection( | void Level3ProductsWidgetImpl::UpdateCategorySelection( | ||||||
|    common::Level3ProductCategory category) |    common::Level3ProductCategory category) | ||||||
| { | { | ||||||
|    const std::string& categoryName = common::GetLevel3CategoryName(category); |    const std::string& categoryName = common::GetLevel3CategoryName(category); | ||||||
|  | @ -288,6 +276,17 @@ void Level3ProductsWidgetImpl::UpdateProductSelection( | ||||||
|                  }); |                  }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Level3ProductsWidgetImpl::UpdateProductSelection( | ||||||
|  |    const std::string& awipsId) | ||||||
|  | { | ||||||
|  |    std::shared_lock lock {awipsProductMutex_}; | ||||||
|  | 
 | ||||||
|  |    std::for_each(awipsProductMap_.cbegin(), | ||||||
|  |                  awipsProductMap_.cend(), | ||||||
|  |                  [=](const auto& pair) | ||||||
|  |                  { pair.first->setChecked(pair.second == awipsId); }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace ui
 | } // namespace ui
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat