mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:40:06 +00:00 
			
		
		
		
	Add favorite selection to radar toolbox
This commit is contained in:
		
							parent
							
								
									9d673af291
								
							
						
					
					
						commit
						436a3e0a9f
					
				
					 5 changed files with 205 additions and 53 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/radar_site_model.hpp> | ||||
| #include <scwx/qt/settings/general_settings.hpp> | ||||
| #include <scwx/qt/settings/map_settings.hpp> | ||||
| #include <scwx/qt/settings/ui_settings.hpp> | ||||
|  | @ -187,6 +188,11 @@ public: | |||
|    std::shared_ptr<manager::TimelineManager>  timelineManager_; | ||||
|    std::shared_ptr<manager::UpdateManager>    updateManager_; | ||||
| 
 | ||||
|    std::shared_ptr<model::RadarSiteModel> radarSiteModel_ { | ||||
|       model::RadarSiteModel::Instance()}; | ||||
|    std::map<std::string, std::shared_ptr<QAction>> radarSiteFavoriteActions_ {}; | ||||
|    QMenu* radarSiteFavoriteMenu_ {nullptr}; | ||||
| 
 | ||||
|    std::vector<map::MapWidget*> maps_; | ||||
|    std::vector<float>           elevationCuts_; | ||||
| 
 | ||||
|  | @ -213,9 +219,14 @@ MainWindow::MainWindow(QWidget* parent) : | |||
|    // Assign the bottom left corner to the left dock widget
 | ||||
|    setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); | ||||
| 
 | ||||
|    // Configure Radar Site Box
 | ||||
|    ui->vcpLabel->setVisible(false); | ||||
|    ui->vcpValueLabel->setVisible(false); | ||||
|    ui->vcpDescriptionLabel->setVisible(false); | ||||
|    ui->radarSiteFavoriteButton->setVisible(false); | ||||
| 
 | ||||
|    p->radarSiteFavoriteMenu_ = new QMenu(this); | ||||
|    ui->radarSiteFavoriteButton->setMenu(p->radarSiteFavoriteMenu_); | ||||
| 
 | ||||
|    // Configure Alert Dock
 | ||||
|    p->alertDockWidget_ = new ui::AlertDockWidget(this); | ||||
|  | @ -944,6 +955,58 @@ void MainWindowImpl::ConnectOtherSignals() | |||
| 
 | ||||
|               UpdateRadarSite(); | ||||
|            }); | ||||
|    connect( | ||||
|       radarSiteModel_.get(), | ||||
|       &model::RadarSiteModel::FavoriteToggled, | ||||
|       [this](const std::string& siteId, bool isFavorite) | ||||
|       { | ||||
|          if (isFavorite && !radarSiteFavoriteActions_.contains(siteId)) | ||||
|          { | ||||
|             auto        radarSite = config::RadarSite::Get(siteId); | ||||
|             std::string actionText = | ||||
|                fmt::format("{}: {}", siteId, radarSite->location_name()); | ||||
| 
 | ||||
|             auto pair = radarSiteFavoriteActions_.emplace( | ||||
|                siteId, | ||||
|                std::make_shared<QAction>(QString::fromStdString(actionText))); | ||||
|             auto& action = pair.first->second; | ||||
| 
 | ||||
|             QAction* before = nullptr; | ||||
| 
 | ||||
|             // If the radar site is not at the end
 | ||||
|             if (pair.first != std::prev(radarSiteFavoriteActions_.cend())) | ||||
|             { | ||||
|                // Insert before the next entry in the list
 | ||||
|                before = std::next(pair.first)->second.get(); | ||||
|             } | ||||
| 
 | ||||
|             radarSiteFavoriteMenu_->insertAction(before, action.get()); | ||||
| 
 | ||||
|             connect(action.get(), | ||||
|                     &QAction::triggered, | ||||
|                     [this, siteId]() | ||||
|                     { | ||||
|                        for (map::MapWidget* map : maps_) | ||||
|                        { | ||||
|                           map->SelectRadarSite(siteId); | ||||
|                        } | ||||
| 
 | ||||
|                        UpdateRadarSite(); | ||||
|                     }); | ||||
|          } | ||||
|          else if (!isFavorite) | ||||
|          { | ||||
|             auto entry = radarSiteFavoriteActions_.find(siteId); | ||||
|             if (entry != radarSiteFavoriteActions_.cend()) | ||||
|             { | ||||
|                radarSiteFavoriteMenu_->removeAction(entry->second.get()); | ||||
|                radarSiteFavoriteActions_.erase(entry); | ||||
|             } | ||||
|          } | ||||
| 
 | ||||
|          mainWindow_->ui->radarSiteFavoriteButton->setVisible( | ||||
|             !radarSiteFavoriteActions_.empty()); | ||||
|       }); | ||||
|    connect(updateManager_.get(), | ||||
|            &manager::UpdateManager::UpdateAvailable, | ||||
|            this, | ||||
|  |  | |||
|  | @ -141,8 +141,8 @@ | |||
|          <rect> | ||||
|           <x>0</x> | ||||
|           <y>0</y> | ||||
|           <width>187</width> | ||||
|           <height>702</height> | ||||
|           <width>193</width> | ||||
|           <height>688</height> | ||||
|          </rect> | ||||
|         </property> | ||||
|         <layout class="QVBoxLayout" name="verticalLayout_6"> | ||||
|  | @ -166,28 +166,122 @@ | |||
|            <property name="frameShadow"> | ||||
|             <enum>QFrame::Raised</enum> | ||||
|            </property> | ||||
|            <layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0,0,0"> | ||||
|             <item row="0" column="1"> | ||||
|            <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0,0"> | ||||
|             <item row="0" column="2"> | ||||
|              <widget class="QLabel" name="radarSiteValueLabel"> | ||||
|               <property name="sizePolicy"> | ||||
|                <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> | ||||
|                 <horstretch>0</horstretch> | ||||
|                 <verstretch>0</verstretch> | ||||
|                </sizepolicy> | ||||
|               </property> | ||||
|               <property name="text"> | ||||
|                <string notr="true">KLSX</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="0" column="0"> | ||||
|             <item row="3" column="0" colspan="2"> | ||||
|              <widget class="QLabel" name="vcpLabel"> | ||||
|               <property name="sizePolicy"> | ||||
|                <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> | ||||
|                 <horstretch>0</horstretch> | ||||
|                 <verstretch>0</verstretch> | ||||
|                </sizepolicy> | ||||
|               </property> | ||||
|               <property name="toolTip"> | ||||
|                <string>Volume Coverage Pattern</string> | ||||
|               </property> | ||||
|               <property name="text"> | ||||
|                <string>VCP</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="0" column="4"> | ||||
|              <widget class="QFrame" name="frame"> | ||||
|               <property name="frameShape"> | ||||
|                <enum>QFrame::NoFrame</enum> | ||||
|               </property> | ||||
|               <property name="frameShadow"> | ||||
|                <enum>QFrame::Raised</enum> | ||||
|               </property> | ||||
|               <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|                <property name="leftMargin"> | ||||
|                 <number>0</number> | ||||
|                </property> | ||||
|                <property name="topMargin"> | ||||
|                 <number>0</number> | ||||
|                </property> | ||||
|                <property name="rightMargin"> | ||||
|                 <number>0</number> | ||||
|                </property> | ||||
|                <property name="bottomMargin"> | ||||
|                 <number>0</number> | ||||
|                </property> | ||||
|                <item> | ||||
|                 <widget class="QToolButton" name="radarSiteHomeButton"> | ||||
|                  <property name="maximumSize"> | ||||
|                   <size> | ||||
|                    <width>16777215</width> | ||||
|                    <height>13</height> | ||||
|                   </size> | ||||
|                  </property> | ||||
|                  <property name="text"> | ||||
|                   <string>...</string> | ||||
|                  </property> | ||||
|                  <property name="icon"> | ||||
|                   <iconset resource="../../../../scwx-qt.qrc"> | ||||
|                    <normaloff>:/res/icons/font-awesome-6/house-solid.svg</normaloff>:/res/icons/font-awesome-6/house-solid.svg</iconset> | ||||
|                  </property> | ||||
|                 </widget> | ||||
|                </item> | ||||
|                <item> | ||||
|                 <widget class="QToolButton" name="radarSiteFavoriteButton"> | ||||
|                  <property name="maximumSize"> | ||||
|                   <size> | ||||
|                    <width>16777215</width> | ||||
|                    <height>13</height> | ||||
|                   </size> | ||||
|                  </property> | ||||
|                  <property name="text"> | ||||
|                   <string>...</string> | ||||
|                  </property> | ||||
|                  <property name="icon"> | ||||
|                   <iconset resource="../../../../scwx-qt.qrc"> | ||||
|                    <normaloff>:/res/icons/font-awesome-6/star-solid.svg</normaloff>:/res/icons/font-awesome-6/star-solid.svg</iconset> | ||||
|                  </property> | ||||
|                  <property name="popupMode"> | ||||
|                   <enum>QToolButton::InstantPopup</enum> | ||||
|                  </property> | ||||
|                 </widget> | ||||
|                </item> | ||||
|               </layout> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="0" column="0" colspan="2"> | ||||
|              <widget class="QLabel" name="radarSiteLabel"> | ||||
|               <property name="text"> | ||||
|                <string>Radar Site</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="2" column="0"> | ||||
|              <widget class="QLabel" name="vcpLabel"> | ||||
|               <property name="toolTip"> | ||||
|                <string>Volume Coverage Pattern</string> | ||||
|               </property> | ||||
|             <item row="1" column="2" colspan="3"> | ||||
|              <widget class="QLabel" name="radarLocationLabel"> | ||||
|               <property name="text"> | ||||
|                <string>VCP</string> | ||||
|                <string notr="true">St. Louis, MO</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="3" column="2" colspan="3"> | ||||
|              <widget class="QLabel" name="vcpValueLabel"> | ||||
|               <property name="text"> | ||||
|                <string notr="true">35</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="4" column="2" colspan="3"> | ||||
|              <widget class="QLabel" name="vcpDescriptionLabel"> | ||||
|               <property name="text"> | ||||
|                <string>Clear Air Mode</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|  | @ -204,44 +298,6 @@ | |||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="0" column="4"> | ||||
|              <widget class="QToolButton" name="radarSiteHomeButton"> | ||||
|               <property name="maximumSize"> | ||||
|                <size> | ||||
|                 <width>16777215</width> | ||||
|                 <height>13</height> | ||||
|                </size> | ||||
|               </property> | ||||
|               <property name="text"> | ||||
|                <string>...</string> | ||||
|               </property> | ||||
|               <property name="icon"> | ||||
|                <iconset resource="../../../../scwx-qt.qrc"> | ||||
|                 <normaloff>:/res/icons/font-awesome-6/house-solid.svg</normaloff>:/res/icons/font-awesome-6/house-solid.svg</iconset> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="1" column="1" colspan="4"> | ||||
|              <widget class="QLabel" name="radarLocationLabel"> | ||||
|               <property name="text"> | ||||
|                <string notr="true">St. Louis, MO</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="2" column="1" colspan="4"> | ||||
|              <widget class="QLabel" name="vcpValueLabel"> | ||||
|               <property name="text"> | ||||
|                <string notr="true">35</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|             <item row="3" column="1" colspan="4"> | ||||
|              <widget class="QLabel" name="vcpDescriptionLabel"> | ||||
|               <property name="text"> | ||||
|                <string>Clear Air Mode</string> | ||||
|               </property> | ||||
|              </widget> | ||||
|             </item> | ||||
|            </layout> | ||||
|           </widget> | ||||
|          </item> | ||||
|  |  | |||
|  | @ -224,7 +224,13 @@ void RadarSiteModel::ToggleFavorite(int row) | |||
| { | ||||
|    if (row >= 0 && row < p->favorites_.size()) | ||||
|    { | ||||
|       p->favorites_.at(row) = !p->favorites_.at(row); | ||||
|       bool isFavorite       = !p->favorites_.at(row); | ||||
|       p->favorites_.at(row) = isFavorite; | ||||
| 
 | ||||
|       QModelIndex index = createIndex(row, static_cast<int>(Column::Favorite)); | ||||
|       Q_EMIT dataChanged(index, index); | ||||
| 
 | ||||
|       Q_EMIT FavoriteToggled(p->radarSites_.at(row)->id(), isFavorite); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
|  | @ -248,6 +254,25 @@ RadarSiteModelImpl::RadarSiteModelImpl() : | |||
|    } | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<RadarSiteModel> RadarSiteModel::Instance() | ||||
| { | ||||
|    static std::weak_ptr<RadarSiteModel> radarSiteModelReference_ {}; | ||||
|    static std::mutex                    instanceMutex_ {}; | ||||
| 
 | ||||
|    std::unique_lock lock(instanceMutex_); | ||||
| 
 | ||||
|    std::shared_ptr<RadarSiteModel> radarSiteModel = | ||||
|       radarSiteModelReference_.lock(); | ||||
| 
 | ||||
|    if (radarSiteModel == nullptr) | ||||
|    { | ||||
|       radarSiteModel           = std::make_shared<RadarSiteModel>(); | ||||
|       radarSiteModelReference_ = radarSiteModel; | ||||
|    } | ||||
| 
 | ||||
|    return radarSiteModel; | ||||
| } | ||||
| 
 | ||||
| } // namespace model
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -15,6 +15,8 @@ class RadarSiteModelImpl; | |||
| 
 | ||||
| class RadarSiteModel : public QAbstractTableModel | ||||
| { | ||||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    enum class Column : int | ||||
|    { | ||||
|  | @ -44,6 +46,11 @@ public: | |||
|    void HandleMapUpdate(double latitude, double longitude); | ||||
|    void ToggleFavorite(int row); | ||||
| 
 | ||||
|    static std::shared_ptr<RadarSiteModel> Instance(); | ||||
| 
 | ||||
| signals: | ||||
|    void FavoriteToggled(const std::string& siteId, bool isFavorite); | ||||
| 
 | ||||
| private: | ||||
|    std::unique_ptr<RadarSiteModelImpl> p; | ||||
| 
 | ||||
|  |  | |||
|  | @ -24,13 +24,13 @@ class RadarSiteDialogImpl | |||
| public: | ||||
|    explicit RadarSiteDialogImpl(RadarSiteDialog* self) : | ||||
|        self_ {self}, | ||||
|        radarSiteModel_ {new model::RadarSiteModel(self_)}, | ||||
|        radarSiteModel_ {model::RadarSiteModel::Instance()}, | ||||
|        proxyModel_ {new QSortFilterProxyModel(self_)}, | ||||
|        mapPosition_ {}, | ||||
|        mapUpdateDeferred_ {false}, | ||||
|        selectedRadarSite_ {"?"} | ||||
|    { | ||||
|       proxyModel_->setSourceModel(radarSiteModel_); | ||||
|       proxyModel_->setSourceModel(radarSiteModel_.get()); | ||||
|       proxyModel_->setSortRole(types::SortRole); | ||||
|       proxyModel_->setFilterCaseSensitivity(Qt::CaseInsensitive); | ||||
|       proxyModel_->setFilterKeyColumn(-1); | ||||
|  | @ -38,9 +38,10 @@ public: | |||
|    ~RadarSiteDialogImpl() = default; | ||||
| 
 | ||||
|    RadarSiteDialog*       self_; | ||||
|    model::RadarSiteModel* radarSiteModel_; | ||||
|    QSortFilterProxyModel* proxyModel_; | ||||
| 
 | ||||
|    std::shared_ptr<model::RadarSiteModel> radarSiteModel_; | ||||
| 
 | ||||
|    scwx::common::Coordinate mapPosition_; | ||||
|    bool                     mapUpdateDeferred_; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat