Skip to content

Commit

Permalink
Merge pull request #108 from dpaulat/feature/radar-presets
Browse files Browse the repository at this point in the history
Radar Presets
  • Loading branch information
dpaulat authored Dec 20, 2023
2 parents 132d92d + c04da02 commit 0bec134
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 88 deletions.
1 change: 1 addition & 0 deletions scwx-qt/res/icons/font-awesome-6/house-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions scwx-qt/res/icons/font-awesome-6/star-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions scwx-qt/scwx-qt.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<file>res/icons/font-awesome-6/forward-step-solid.svg</file>
<file>res/icons/font-awesome-6/gears-solid.svg</file>
<file>res/icons/font-awesome-6/github.svg</file>
<file>res/icons/font-awesome-6/house-solid.svg</file>
<file>res/icons/font-awesome-6/layer-group-solid.svg</file>
<file>res/icons/font-awesome-6/palette-solid.svg</file>
<file>res/icons/font-awesome-6/pause-solid.svg</file>
Expand All @@ -44,6 +45,7 @@
<file>res/icons/font-awesome-6/square-caret-right-regular.svg</file>
<file>res/icons/font-awesome-6/square-minus-regular.svg</file>
<file>res/icons/font-awesome-6/square-plus-regular.svg</file>
<file>res/icons/font-awesome-6/star-solid.svg</file>
<file>res/icons/font-awesome-6/stop-solid.svg</file>
<file>res/icons/font-awesome-6/volume-high-solid.svg</file>
<file>res/palettes/wct/CC.pal</file>
Expand Down
96 changes: 88 additions & 8 deletions scwx-qt/source/scwx/qt/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -89,10 +90,7 @@ class MainWindowImpl : public QObject
textEventManager_ {manager::TextEventManager::Instance()},
timelineManager_ {manager::TimelineManager::Instance()},
updateManager_ {manager::UpdateManager::Instance()},
maps_ {},
elevationCuts_ {},
elevationButtonsChanged_ {false},
resizeElevationButtons_ {false}
maps_ {}
{
mapProvider_ = map::GetMapProvider(
settings::GeneralSettings::Instance().map_provider().GetValue());
Expand Down Expand Up @@ -129,6 +127,7 @@ class MainWindowImpl : public QObject
}
~MainWindowImpl() { threadPool_.join(); }

void AddRadarSitePreset(const std::string& id);
void AsyncSetup();
void ConfigureMapLayout();
void ConfigureMapStyles();
Expand Down Expand Up @@ -187,14 +186,15 @@ class MainWindowImpl : public QObject
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>> radarSitePresetsActions_ {};
QMenu* radarSitePresetsMenu_ {nullptr};

std::vector<map::MapWidget*> maps_;
std::vector<float> elevationCuts_;

std::chrono::system_clock::time_point volumeTime_ {};

bool elevationButtonsChanged_;
bool resizeElevationButtons_;

public slots:
void UpdateMapParameters(double latitude,
double longitude,
Expand All @@ -213,10 +213,22 @@ 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);

p->radarSitePresetsMenu_ = new QMenu(this);
ui->radarSitePresetsButton->setMenu(p->radarSitePresetsMenu_);

auto radarSitePresets = p->radarSiteModel_->presets();
for (auto preset : radarSitePresets)
{
p->AddRadarSitePreset(preset);
}

ui->radarSitePresetsButton->setVisible(!radarSitePresets.empty());

// Configure Alert Dock
p->alertDockWidget_ = new ui::AlertDockWidget(this);
p->alertDockWidget_->setVisible(false);
Expand Down Expand Up @@ -521,6 +533,19 @@ void MainWindow::on_actionAboutSupercellWx_triggered()
p->aboutDialog_->show();
}

void MainWindow::on_radarSiteHomeButton_clicked()
{
std::string homeRadarSite =
settings::GeneralSettings::Instance().default_radar_site().GetValue();

for (map::MapWidget* map : p->maps_)
{
map->SelectRadarSite(homeRadarSite);
}

p->UpdateRadarSite();
}

void MainWindow::on_radarSiteSelectButton_clicked()
{
p->radarSiteDialog_->show();
Expand Down Expand Up @@ -931,6 +956,27 @@ void MainWindowImpl::ConnectOtherSignals()

UpdateRadarSite();
});
connect(radarSiteModel_.get(),
&model::RadarSiteModel::PresetToggled,
[this](const std::string& siteId, bool isPreset)
{
if (isPreset && !radarSitePresetsActions_.contains(siteId))
{
AddRadarSitePreset(siteId);
}
else if (!isPreset)
{
auto entry = radarSitePresetsActions_.find(siteId);
if (entry != radarSitePresetsActions_.cend())
{
radarSitePresetsMenu_->removeAction(entry->second.get());
radarSitePresetsActions_.erase(entry);
}
}

mainWindow_->ui->radarSitePresetsButton->setVisible(
!radarSitePresetsActions_.empty());
});
connect(updateManager_.get(),
&manager::UpdateManager::UpdateAvailable,
this,
Expand All @@ -942,6 +988,40 @@ void MainWindowImpl::ConnectOtherSignals()
});
}

void MainWindowImpl::AddRadarSitePreset(const std::string& siteId)
{
auto radarSite = config::RadarSite::Get(siteId);
std::string actionText =
fmt::format("{}: {}", siteId, radarSite->location_name());

auto pair = radarSitePresetsActions_.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(radarSitePresetsActions_.cend()))
{
// Insert before the next entry in the list
before = std::next(pair.first)->second.get();
}

radarSitePresetsMenu_->insertAction(before, action.get());

connect(action.get(),
&QAction::triggered,
[this, siteId]()
{
for (map::MapWidget* map : maps_)
{
map->SelectRadarSite(siteId);
}

UpdateRadarSite();
});
}

void MainWindowImpl::HandleFocusChange(QWidget* focused)
{
map::MapWidget* mapWidget = dynamic_cast<map::MapWidget*>(focused);
Expand Down
1 change: 1 addition & 0 deletions scwx-qt/source/scwx/qt/main/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private slots:
void on_actionGitHubRepository_triggered();
void on_actionCheckForUpdates_triggered();
void on_actionAboutSupercellWx_triggered();
void on_radarSiteHomeButton_clicked();
void on_radarSiteSelectButton_clicked();

private:
Expand Down
129 changes: 101 additions & 28 deletions scwx-qt/source/scwx/qt/main/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<x>0</x>
<y>0</y>
<width>1024</width>
<height>22</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -141,8 +141,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>157</width>
<height>697</height>
<width>193</width>
<height>688</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
Expand All @@ -166,29 +166,28 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0,0">
<item row="0" column="2">
<widget class="QToolButton" name="radarSiteSelectButton">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>13</height>
</size>
<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>...</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLabel" name="radarLocationLabel">
<property name="text">
<string notr="true">St. Louis, MO</string>
<string notr="true">KLSX</string>
</property>
</widget>
</item>
<item row="2" 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>
Expand All @@ -197,34 +196,108 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="radarSiteValueLabel">
<property name="text">
<string notr="true">KLSX</string>
<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="radarSitePresetsButton">
<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">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="radarSiteLabel">
<property name="text">
<string>Radar Site</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLabel" name="vcpDescriptionLabel">
<item row="1" column="2" colspan="3">
<widget class="QLabel" name="radarLocationLabel">
<property name="text">
<string>Clear Air Mode</string>
<string notr="true">St. Louis, MO</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<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>
<item row="0" column="3">
<widget class="QToolButton" name="radarSiteSelectButton">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>13</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Loading

0 comments on commit 0bec134

Please sign in to comment.