mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 19:50:06 +00:00 
			
		
		
		
	Add select Map Layers to View menu
This commit is contained in:
		
							parent
							
								
									54047b7645
								
							
						
					
					
						commit
						9e3b2916e1
					
				
					 6 changed files with 199 additions and 5 deletions
				
			
		|  | @ -12,6 +12,7 @@ | |||
| #include <scwx/qt/manager/update_manager.hpp> | ||||
| #include <scwx/qt/map/map_provider.hpp> | ||||
| #include <scwx/qt/map/map_widget.hpp> | ||||
| #include <scwx/qt/model/layer_model.hpp> | ||||
| #include <scwx/qt/model/radar_site_model.hpp> | ||||
| #include <scwx/qt/settings/general_settings.hpp> | ||||
| #include <scwx/qt/settings/map_settings.hpp> | ||||
|  | @ -36,6 +37,8 @@ | |||
| #include <scwx/util/logger.hpp> | ||||
| #include <scwx/util/time.hpp> | ||||
| 
 | ||||
| #include <set> | ||||
| 
 | ||||
| #include <boost/asio/post.hpp> | ||||
| #include <boost/asio/thread_pool.hpp> | ||||
| #include <QDesktopServices> | ||||
|  | @ -142,6 +145,7 @@ public: | |||
|    void ConnectMapSignals(); | ||||
|    void ConnectOtherSignals(); | ||||
|    void HandleFocusChange(QWidget* focused); | ||||
|    void InitializeLayerDisplayActions(); | ||||
|    void PopulateMapStyles(); | ||||
|    void SelectElevation(map::MapWidget* mapWidget, float elevation); | ||||
|    void SelectRadarProduct(map::MapWidget*           mapWidget, | ||||
|  | @ -197,11 +201,17 @@ public: | |||
|    std::shared_ptr<manager::TimelineManager>  timelineManager_; | ||||
|    std::shared_ptr<manager::UpdateManager>    updateManager_; | ||||
| 
 | ||||
|    std::shared_ptr<model::LayerModel> layerModel_ { | ||||
|       model::LayerModel::Instance()}; | ||||
|    std::shared_ptr<model::RadarSiteModel> radarSiteModel_ { | ||||
|       model::RadarSiteModel::Instance()}; | ||||
|    std::map<std::string, std::shared_ptr<QAction>> radarSitePresetsActions_ {}; | ||||
|    QMenu* radarSitePresetsMenu_ {nullptr}; | ||||
| 
 | ||||
|    std::set<std::tuple<types::LayerType, types::LayerDescription, QAction*>> | ||||
|         layerActions_ {}; | ||||
|    bool layerActionsInitialized_ {false}; | ||||
| 
 | ||||
|    std::vector<map::MapWidget*> maps_; | ||||
| 
 | ||||
|    std::chrono::system_clock::time_point volumeTime_ {}; | ||||
|  | @ -221,6 +231,8 @@ MainWindow::MainWindow(QWidget* parent) : | |||
| { | ||||
|    ui->setupUi(this); | ||||
| 
 | ||||
|    p->InitializeLayerDisplayActions(); | ||||
| 
 | ||||
|    // Assign the bottom left corner to the left dock widget
 | ||||
|    setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); | ||||
| 
 | ||||
|  | @ -494,6 +506,26 @@ void MainWindow::on_actionExit_triggered() | |||
|    close(); | ||||
| } | ||||
| 
 | ||||
| void MainWindow::on_actionColorTable_triggered(bool checked) | ||||
| { | ||||
|    p->layerModel_->SetLayerDisplayed(types::LayerType::Information, | ||||
|                                      types::InformationLayer::ColorTable, | ||||
|                                      checked); | ||||
| } | ||||
| 
 | ||||
| void MainWindow::on_actionRadarRange_triggered(bool checked) | ||||
| { | ||||
|    p->layerModel_->SetLayerDisplayed( | ||||
|       types::LayerType::Data, types::DataLayer::RadarRange, checked); | ||||
| } | ||||
| 
 | ||||
| void MainWindow::on_actionRadarSites_triggered(bool checked) | ||||
| { | ||||
|    p->layerModel_->SetLayerDisplayed(types::LayerType::Information, | ||||
|                                      types::InformationLayer::RadarSite, | ||||
|                                      checked); | ||||
| } | ||||
| 
 | ||||
| void MainWindow::on_actionPlacefileManager_triggered() | ||||
| { | ||||
|    p->placefileDialog_->show(); | ||||
|  | @ -989,6 +1021,39 @@ void MainWindowImpl::ConnectOtherSignals() | |||
|            &MainWindow::ActiveMapMoved, | ||||
|            radarSiteDialog_, | ||||
|            &ui::RadarSiteDialog::HandleMapUpdate); | ||||
|    connect(layerModel_.get(), | ||||
|            &model::LayerModel::LayerDisplayChanged, | ||||
|            this, | ||||
|            [this](types::LayerInfo layer) | ||||
|            { | ||||
|               // Find matching layer action
 | ||||
|               auto it = | ||||
|                  std::find_if(layerActions_.begin(), | ||||
|                               layerActions_.end(), | ||||
|                               [&](const auto& layerAction) | ||||
|                               { | ||||
|                                  const auto& [type, description, action] = | ||||
|                                     layerAction; | ||||
|                                  return layer.type_ == type && | ||||
|                                         layer.description_ == description; | ||||
|                               }); | ||||
| 
 | ||||
|               // If matching layer action was found
 | ||||
|               if (it != layerActions_.end()) | ||||
|               { | ||||
|                  // Check the action if the layer is displayed on any map
 | ||||
|                  bool anyDisplayed = std::find(layer.displayed_.begin(), | ||||
|                                                layer.displayed_.end(), | ||||
|                                                true) != layer.displayed_.end(); | ||||
| 
 | ||||
|                  auto& action = std::get<2>(*it); | ||||
|                  action->setChecked(anyDisplayed); | ||||
|               } | ||||
|            }); | ||||
|    connect(layerModel_.get(), | ||||
|            &QAbstractItemModel::modelReset, | ||||
|            this, | ||||
|            [this]() { InitializeLayerDisplayActions(); }); | ||||
|    connect(radarSiteDialog_, | ||||
|            &ui::RadarSiteDialog::accepted, | ||||
|            this, | ||||
|  | @ -1046,6 +1111,36 @@ void MainWindowImpl::ConnectOtherSignals() | |||
|    clockTimer_.start(1000); | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::InitializeLayerDisplayActions() | ||||
| { | ||||
|    if (!layerActionsInitialized_) | ||||
|    { | ||||
|       layerActions_.emplace(types::LayerType::Information, | ||||
|                             types::InformationLayer::ColorTable, | ||||
|                             mainWindow_->ui->actionColorTable); | ||||
|       layerActions_.emplace(types::LayerType::Information, | ||||
|                             types::InformationLayer::RadarSite, | ||||
|                             mainWindow_->ui->actionRadarSites); | ||||
|       layerActions_.emplace(types::LayerType::Data, | ||||
|                             types::DataLayer::RadarRange, | ||||
|                             mainWindow_->ui->actionRadarRange); | ||||
|       layerActionsInitialized_ = true; | ||||
|    } | ||||
| 
 | ||||
|    for (auto& layerAction : layerActions_) | ||||
|    { | ||||
|       auto& [type, description, action] = layerAction; | ||||
| 
 | ||||
|       types::LayerInfo layer = layerModel_->GetLayerInfo(type, description); | ||||
| 
 | ||||
|       bool anyDisplayed = | ||||
|          std::find(layer.displayed_.begin(), layer.displayed_.end(), true) != | ||||
|          layer.displayed_.end(); | ||||
| 
 | ||||
|       action->setChecked(anyDisplayed); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void MainWindowImpl::AddRadarSitePreset(const std::string& siteId) | ||||
| { | ||||
|    auto        radarSite = config::RadarSite::Get(siteId); | ||||
|  |  | |||
|  | @ -36,6 +36,9 @@ private slots: | |||
|    void on_actionOpenTextEvent_triggered(); | ||||
|    void on_actionSettings_triggered(); | ||||
|    void on_actionExit_triggered(); | ||||
|    void on_actionColorTable_triggered(bool checked); | ||||
|    void on_actionRadarRange_triggered(bool checked); | ||||
|    void on_actionRadarSites_triggered(bool checked); | ||||
|    void on_actionPlacefileManager_triggered(); | ||||
|    void on_actionLayerManager_triggered(); | ||||
|    void on_actionImGuiDebug_triggered(); | ||||
|  |  | |||
|  | @ -75,8 +75,18 @@ | |||
|     <property name="title"> | ||||
|      <string>&View</string> | ||||
|     </property> | ||||
|     <widget class="QMenu" name="menuMapLayers"> | ||||
|      <property name="title"> | ||||
|       <string>&Map Layers</string> | ||||
|      </property> | ||||
|      <addaction name="actionColorTable"/> | ||||
|      <addaction name="actionRadarSites"/> | ||||
|      <addaction name="actionRadarRange"/> | ||||
|     </widget> | ||||
|     <addaction name="actionRadarToolbox"/> | ||||
|     <addaction name="actionAlerts"/> | ||||
|     <addaction name="separator"/> | ||||
|     <addaction name="menuMapLayers"/> | ||||
|    </widget> | ||||
|    <widget class="QMenu" name="menuDebug"> | ||||
|     <property name="title"> | ||||
|  | @ -166,7 +176,7 @@ | |||
|            <property name="frameShadow"> | ||||
|             <enum>QFrame::Raised</enum> | ||||
|            </property> | ||||
|            <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0,0"> | ||||
|            <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0"> | ||||
|             <item row="0" column="2"> | ||||
|              <widget class="QLabel" name="radarSiteValueLabel"> | ||||
|               <property name="sizePolicy"> | ||||
|  | @ -447,6 +457,30 @@ | |||
|     <string>Dump &Layer List</string> | ||||
|    </property> | ||||
|   </action> | ||||
|   <action name="actionRadarRange"> | ||||
|    <property name="checkable"> | ||||
|     <bool>true</bool> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>Radar &Range</string> | ||||
|    </property> | ||||
|   </action> | ||||
|   <action name="actionColorTable"> | ||||
|    <property name="checkable"> | ||||
|     <bool>true</bool> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>&Color Table</string> | ||||
|    </property> | ||||
|   </action> | ||||
|   <action name="actionRadarSites"> | ||||
|    <property name="checkable"> | ||||
|     <bool>true</bool> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>Radar &Sites</string> | ||||
|    </property> | ||||
|   </action> | ||||
|  </widget> | ||||
|  <resources> | ||||
|   <include location="../../../../scwx-qt.qrc"/> | ||||
|  |  | |||
|  | @ -395,11 +395,63 @@ void LayerModel::Impl::WriteLayerSettings() | |||
|    util::json::WriteJsonFile(layerSettingsPath_, layerJson); | ||||
| } | ||||
| 
 | ||||
| types::LayerInfo | ||||
| LayerModel::GetLayerInfo(types::LayerType        type, | ||||
|                          types::LayerDescription description) const | ||||
| { | ||||
|    // Find the matching layer
 | ||||
|    auto it = std::find_if(p->layers_.begin(), | ||||
|                           p->layers_.end(), | ||||
|                           [&](const types::LayerInfo& layer) { | ||||
|                              return layer.type_ == type && | ||||
|                                     layer.description_ == description; | ||||
|                           }); | ||||
|    if (it != p->layers_.end()) | ||||
|    { | ||||
|       // Return the layer info
 | ||||
|       return *it; | ||||
|    } | ||||
| 
 | ||||
|    return {}; | ||||
| } | ||||
| 
 | ||||
| types::LayerVector LayerModel::GetLayers() const | ||||
| { | ||||
|    return p->layers_; | ||||
| } | ||||
| 
 | ||||
| void LayerModel::SetLayerDisplayed(types::LayerType        type, | ||||
|                                    types::LayerDescription description, | ||||
|                                    bool                    displayed) | ||||
| { | ||||
|    // Find the matching layer
 | ||||
|    auto it = std::find_if(p->layers_.begin(), | ||||
|                           p->layers_.end(), | ||||
|                           [&](const types::LayerInfo& layer) { | ||||
|                              return layer.type_ == type && | ||||
|                                     layer.description_ == description; | ||||
|                           }); | ||||
| 
 | ||||
|    if (it != p->layers_.end()) | ||||
|    { | ||||
|       // Find the row
 | ||||
|       const int   row = std::distance(p->layers_.begin(), it); | ||||
|       QModelIndex topLeft = | ||||
|          createIndex(row, static_cast<int>(Column::DisplayMap1)); | ||||
|       QModelIndex bottomRight = | ||||
|          createIndex(row, static_cast<int>(Column::DisplayMap4)); | ||||
| 
 | ||||
|       // Set the layer to displayed
 | ||||
|       for (std::size_t i = 0; i < kMapCount_; ++i) | ||||
|       { | ||||
|          it->displayed_[i] = displayed; | ||||
|       } | ||||
| 
 | ||||
|       // Notify observers
 | ||||
|       Q_EMIT dataChanged(topLeft, bottomRight); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void LayerModel::ResetLayers() | ||||
| { | ||||
|    // Initialize a new layer vector from the default
 | ||||
|  | @ -751,6 +803,7 @@ bool LayerModel::setData(const QModelIndex& index, | |||
|    if (result) | ||||
|    { | ||||
|       Q_EMIT dataChanged(index, index); | ||||
|       Q_EMIT LayerDisplayChanged(layer); | ||||
|    } | ||||
| 
 | ||||
|    return result; | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ namespace model | |||
| 
 | ||||
| class LayerModel : public QAbstractTableModel | ||||
| { | ||||
|    Q_OBJECT | ||||
|    Q_DISABLE_COPY_MOVE(LayerModel) | ||||
| 
 | ||||
| public: | ||||
|  | @ -36,7 +37,12 @@ public: | |||
|    explicit LayerModel(QObject* parent = nullptr); | ||||
|    ~LayerModel(); | ||||
| 
 | ||||
|    types::LayerInfo   GetLayerInfo(types::LayerType        type, | ||||
|                                    types::LayerDescription description) const; | ||||
|    types::LayerVector GetLayers() const; | ||||
|    void               SetLayerDisplayed(types::LayerType        type, | ||||
|                                         types::LayerDescription description, | ||||
|                                         bool                    displayed); | ||||
| 
 | ||||
|    void ResetLayers(); | ||||
| 
 | ||||
|  | @ -77,6 +83,9 @@ public: | |||
| 
 | ||||
|    static std::shared_ptr<LayerModel> Instance(); | ||||
| 
 | ||||
| signals: | ||||
|    void LayerDisplayChanged(types::LayerInfo layer); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|    std::unique_ptr<Impl> p; | ||||
|  |  | |||
|  | @ -37,8 +37,8 @@ public: | |||
|    void UpdateMapDisplayColumns(); | ||||
|    void UpdateMoveButtonsEnabled(); | ||||
| 
 | ||||
|    std::vector<int>              GetSelectedRows(); | ||||
|    std::vector<std::vector<int>> GetContiguousRows(); | ||||
|    std::vector<int>              GetSelectedRows() const; | ||||
|    std::vector<std::vector<int>> GetContiguousRows() const; | ||||
| 
 | ||||
|    LayerDialog*                       self_; | ||||
|    std::shared_ptr<model::LayerModel> layerModel_; | ||||
|  | @ -247,7 +247,7 @@ void LayerDialogImpl::ConnectSignals() | |||
|       }); | ||||
| } | ||||
| 
 | ||||
| std::vector<int> LayerDialogImpl::GetSelectedRows() | ||||
| std::vector<int> LayerDialogImpl::GetSelectedRows() const | ||||
| { | ||||
|    QModelIndexList selectedRows = | ||||
|       self_->ui->layerTreeView->selectionModel()->selectedRows(); | ||||
|  | @ -260,7 +260,7 @@ std::vector<int> LayerDialogImpl::GetSelectedRows() | |||
|    return rows; | ||||
| } | ||||
| 
 | ||||
| std::vector<std::vector<int>> LayerDialogImpl::GetContiguousRows() | ||||
| std::vector<std::vector<int>> LayerDialogImpl::GetContiguousRows() const | ||||
| { | ||||
|    std::vector<std::vector<int>> contiguousRows {}; | ||||
|    std::vector<int>              currentContiguousRows {}; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat