Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radar site threshold #319

Merged
merged 6 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions scwx-qt/source/scwx/qt/map/radar_site_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <scwx/qt/map/radar_site_layer.hpp>
#include <scwx/qt/config/radar_site.hpp>
#include <scwx/qt/settings/general_settings.hpp>
#include <scwx/qt/settings/text_settings.hpp>
#include <scwx/qt/util/maplibre.hpp>
#include <scwx/qt/util/tooltip.hpp>
Expand Down Expand Up @@ -59,6 +60,18 @@ void RadarSiteLayer::Initialize()
void RadarSiteLayer::Render(
const QMapLibre::CustomLayerRenderParameters& params)
{
p->hoverText_.clear();

auto mapDistance = util::maplibre::GetMapDistance(params);
auto threshold = units::length::kilometers<double>(
settings::GeneralSettings::Instance().radar_site_threshold().GetValue());

if (!(threshold.value() == 0.0 || mapDistance <= threshold ||
(threshold.value() < 0 && mapDistance >= -threshold)))
{
return;
}

gl::OpenGLFunctions& gl = context()->gl();

context()->set_render_parameters(params);
Expand All @@ -73,8 +86,6 @@ void RadarSiteLayer::Render(
p->halfWidth_ = params.width * 0.5f;
p->halfHeight_ = params.height * 0.5f;

p->hoverText_.clear();

// Radar site ImGui windows shouldn't have padding
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2 {0.0f, 0.0f});

Expand Down
15 changes: 13 additions & 2 deletions scwx-qt/source/scwx/qt/settings/general_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GeneralSettings::Impl
updateNotificationsEnabled_.SetDefault(true);
warningsProvider_.SetDefault(defaultWarningsProviderValue);
cursorIconAlwaysOn_.SetDefault(false);
radarSiteThreshold_.SetDefault(0.0);

fontSizes_.SetElementMinimum(1);
fontSizes_.SetElementMaximum(72);
Expand All @@ -95,6 +96,8 @@ class GeneralSettings::Impl
loopTime_.SetMaximum(1440);
nmeaBaudRate_.SetMinimum(1);
nmeaBaudRate_.SetMaximum(999999999);
radarSiteThreshold_.SetMinimum(-10000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 10000 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

      radarSiteThreshold_.SetMinimum(-10000);
                                      ^

radarSiteThreshold_.SetMaximum(10000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 10000 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

      radarSiteThreshold_.SetMaximum(10000);
                                     ^


customStyleDrawLayer_.SetTransform([](const std::string& value)
{ return boost::trim_copy(value); });
Expand Down Expand Up @@ -168,6 +171,7 @@ class GeneralSettings::Impl
SettingsVariable<bool> updateNotificationsEnabled_ {"update_notifications"};
SettingsVariable<std::string> warningsProvider_ {"warnings_provider"};
SettingsVariable<bool> cursorIconAlwaysOn_ {"cursor_icon_always_on"};
SettingsVariable<double> radarSiteThreshold_ {"radar_site_threshold"};
};

GeneralSettings::GeneralSettings() :
Expand Down Expand Up @@ -201,7 +205,8 @@ GeneralSettings::GeneralSettings() :
&p->trackLocation_,
&p->updateNotificationsEnabled_,
&p->warningsProvider_,
&p->cursorIconAlwaysOn_});
&p->cursorIconAlwaysOn_,
&p->radarSiteThreshold_});
SetDefaults();
}
GeneralSettings::~GeneralSettings() = default;
Expand Down Expand Up @@ -356,6 +361,11 @@ SettingsVariable<bool>& GeneralSettings::cursor_icon_always_on() const
return p->cursorIconAlwaysOn_;
}

SettingsVariable<double>& GeneralSettings::radar_site_threshold() const
{
return p->radarSiteThreshold_;
}

bool GeneralSettings::Shutdown()
{
bool dataChanged = false;
Expand Down Expand Up @@ -406,7 +416,8 @@ bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs)
lhs.p->updateNotificationsEnabled_ ==
rhs.p->updateNotificationsEnabled_ &&
lhs.p->warningsProvider_ == rhs.p->warningsProvider_ &&
lhs.p->cursorIconAlwaysOn_ == rhs.p->cursorIconAlwaysOn_);
lhs.p->cursorIconAlwaysOn_ == rhs.p->cursorIconAlwaysOn_ &&
lhs.p->radarSiteThreshold_ == rhs.p->radarSiteThreshold_);
}

} // namespace settings
Expand Down
1 change: 1 addition & 0 deletions scwx-qt/source/scwx/qt/settings/general_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class GeneralSettings : public SettingsCategory
SettingsVariable<bool>& update_notifications_enabled() const;
SettingsVariable<std::string>& warnings_provider() const;
SettingsVariable<bool>& cursor_icon_always_on() const;
SettingsVariable<double>& radar_site_threshold() const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'radar_site_threshold' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
SettingsVariable<double>& radar_site_threshold() const;
[[nodiscard]] SettingsVariable<double>& radar_site_threshold() const;


static GeneralSettings& Instance();

Expand Down
29 changes: 26 additions & 3 deletions scwx-qt/source/scwx/qt/ui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class SettingsDialogImpl
&nmeaBaudRate_,
&nmeaSource_,
&warningsProvider_,
&radarSiteThreshold_,
&antiAliasingEnabled_,
&showMapAttribution_,
&showMapCenter_,
Expand Down Expand Up @@ -249,6 +250,7 @@ class SettingsDialogImpl
settings::SettingsInterface<std::string> theme_ {};
settings::SettingsInterface<std::string> themeFile_ {};
settings::SettingsInterface<std::string> warningsProvider_ {};
settings::SettingsInterface<double> radarSiteThreshold_ {};
settings::SettingsInterface<bool> antiAliasingEnabled_ {};
settings::SettingsInterface<bool> showMapAttribution_ {};
settings::SettingsInterface<bool> showMapCenter_ {};
Expand Down Expand Up @@ -749,6 +751,27 @@ void SettingsDialogImpl::SetupGeneralTab()
warningsProvider_.SetResetButton(self_->ui->resetWarningsProviderButton);
warningsProvider_.EnableTrimming();

radarSiteThreshold_.SetSettingsVariable(
generalSettings.radar_site_threshold());
radarSiteThreshold_.SetEditWidget(self_->ui->radarSiteThresholdSpinBox);
radarSiteThreshold_.SetResetButton(self_->ui->resetRadarSiteThresholdButton);
radarSiteThreshold_.SetUnitLabel(self_->ui->radarSiteThresholdUnitLabel);
auto radarSiteThresholdUpdateUnits = [this](const std::string& newValue)
{
const types::DistanceUnits radiusUnits =
types::GetDistanceUnitsFromName(newValue);
const double radiusScale = types::GetDistanceUnitsScale(radiusUnits);
const std::string abbreviation =
types::GetDistanceUnitsAbbreviation(radiusUnits);

radarSiteThreshold_.SetUnit(radiusScale, abbreviation);
};
settings::UnitSettings::Instance()
.distance_units()
.RegisterValueStagedCallback(radarSiteThresholdUpdateUnits);
radarSiteThresholdUpdateUnits(
settings::UnitSettings::Instance().distance_units().GetValue());

antiAliasingEnabled_.SetSettingsVariable(
generalSettings.anti_aliasing_enabled());
antiAliasingEnabled_.SetEditWidget(self_->ui->antiAliasingEnabledCheckBox);
Expand Down Expand Up @@ -1059,10 +1082,10 @@ void SettingsDialogImpl::SetupAudioTab()
alertAudioRadius_.SetUnitLabel(self_->ui->alertAudioRadiusUnitsLabel);
auto alertAudioRadiusUpdateUnits = [this](const std::string& newValue)
{
types::DistanceUnits radiusUnits =
const types::DistanceUnits radiusUnits =
types::GetDistanceUnitsFromName(newValue);
double radiusScale = types::GetDistanceUnitsScale(radiusUnits);
std::string abbreviation =
const double radiusScale = types::GetDistanceUnitsScale(radiusUnits);
const std::string abbreviation =
types::GetDistanceUnitsAbbreviation(radiusUnits);

alertAudioRadius_.SetUnit(radiusScale, abbreviation);
Expand Down
Loading
Loading