Add alert county to settings

This commit is contained in:
Dan Paulat 2023-12-08 05:59:22 -06:00
parent 769ce896e7
commit c970e73db8
7 changed files with 191 additions and 61 deletions

View file

@ -1,3 +1,4 @@
#include <scwx/qt/config/county_database.hpp>
#include <scwx/qt/settings/audio_settings.hpp>
#include <scwx/qt/settings/settings_definitions.hpp>
#include <scwx/qt/settings/settings_variable.hpp>
@ -47,6 +48,14 @@ public:
types::LocationMethodIterator(),
types::GetLocationMethodName));
alertCounty_.SetValidator(
[](const std::string& value)
{
// Empty, or county exists in the database
return value.empty() ||
config::CountyDatabase::GetCountyName(value) != value;
});
for (auto& phenomenon : types::GetAlertAudioPhenomena())
{
std::string phenomenonCode = awips::GetPhenomenonCode(phenomenon);
@ -73,6 +82,7 @@ public:
SettingsVariable<std::string> alertLocationMethod_ {"alert_location_method"};
SettingsVariable<double> alertLatitude_ {"alert_latitude"};
SettingsVariable<double> alertLongitude_ {"alert_longitude"};
SettingsVariable<std::string> alertCounty_ {"alert_county"};
std::unordered_map<awips::Phenomenon, SettingsVariable<bool>>
alertEnabled_ {};
@ -85,7 +95,8 @@ AudioSettings::AudioSettings() :
RegisterVariables({&p->alertSoundFile_,
&p->alertLocationMethod_,
&p->alertLatitude_,
&p->alertLongitude_});
&p->alertLongitude_,
&p->alertCounty_});
RegisterVariables(p->variables_);
SetDefaults();
@ -116,6 +127,11 @@ SettingsVariable<double>& AudioSettings::alert_longitude() const
return p->alertLongitude_;
}
SettingsVariable<std::string>& AudioSettings::alert_county() const
{
return p->alertCounty_;
}
SettingsVariable<bool>&
AudioSettings::alert_enabled(awips::Phenomenon phenomenon) const
{
@ -139,6 +155,7 @@ bool operator==(const AudioSettings& lhs, const AudioSettings& rhs)
lhs.p->alertLocationMethod_ == rhs.p->alertLocationMethod_ &&
lhs.p->alertLatitude_ == rhs.p->alertLatitude_ &&
lhs.p->alertLongitude_ == rhs.p->alertLongitude_ &&
lhs.p->alertCounty_ == rhs.p->alertCounty_ &&
lhs.p->alertEnabled_ == rhs.p->alertEnabled_);
}

View file

@ -30,6 +30,7 @@ public:
SettingsVariable<std::string>& alert_location_method() const;
SettingsVariable<double>& alert_latitude() const;
SettingsVariable<double>& alert_longitude() const;
SettingsVariable<std::string>& alert_county() const;
SettingsVariable<bool>& alert_enabled(awips::Phenomenon phenomenon) const;
static AudioSettings& Instance();

View file

@ -15,6 +15,7 @@ namespace types
static const std::unordered_map<LocationMethod, std::string>
locationMethodName_ {{LocationMethod::Fixed, "Fixed"},
{LocationMethod::Track, "Track"},
{LocationMethod::County, "County"},
{LocationMethod::Unknown, "?"}};
SCWX_GET_ENUM(LocationMethod, GetLocationMethod, locationMethodName_)

View file

@ -15,10 +15,11 @@ enum class LocationMethod
{
Fixed,
Track,
County,
Unknown
};
typedef scwx::util::
Iterator<LocationMethod, LocationMethod::Fixed, LocationMethod::Track>
Iterator<LocationMethod, LocationMethod::Fixed, LocationMethod::County>
LocationMethodIterator;
LocationMethod GetLocationMethod(const std::string& name);

View file

@ -3,6 +3,7 @@
#include <scwx/awips/phenomenon.hpp>
#include <scwx/common/color_table.hpp>
#include <scwx/qt/config/county_database.hpp>
#include <scwx/qt/config/radar_site.hpp>
#include <scwx/qt/manager/media_manager.hpp>
#include <scwx/qt/manager/position_manager.hpp>
@ -18,6 +19,7 @@
#include <scwx/qt/types/location_types.hpp>
#include <scwx/qt/types/qt_types.hpp>
#include <scwx/qt/types/text_types.hpp>
#include <scwx/qt/ui/county_dialog.hpp>
#include <scwx/qt/ui/radar_site_dialog.hpp>
#include <scwx/qt/util/color.hpp>
#include <scwx/qt/util/file.hpp>
@ -113,6 +115,7 @@ public:
explicit SettingsDialogImpl(SettingsDialog* self) :
self_ {self},
radarSiteDialog_ {new RadarSiteDialog(self)},
countyDialog_ {new CountyDialog(self)},
fontDialog_ {new QFontDialog(self)},
fontCategoryModel_ {new QStandardItemModel(self)},
settings_ {std::initializer_list<settings::SettingsInterfaceBase*> {
@ -131,6 +134,7 @@ public:
&alertAudioLocationMethod_,
&alertAudioLatitude_,
&alertAudioLongitude_,
&alertAudioCounty_,
&hoverTextWrap_,
&tooltipMethod_,
&placefileTextDropShadowEnabled_}}
@ -192,6 +196,7 @@ public:
SettingsDialog* self_;
RadarSiteDialog* radarSiteDialog_;
CountyDialog* countyDialog_;
QFontDialog* fontDialog_;
QStandardItemModel* fontCategoryModel_;
@ -228,6 +233,7 @@ public:
settings::SettingsInterface<std::string> alertAudioLocationMethod_ {};
settings::SettingsInterface<double> alertAudioLatitude_ {};
settings::SettingsInterface<double> alertAudioLongitude_ {};
settings::SettingsInterface<std::string> alertAudioCounty_ {};
std::unordered_map<awips::Phenomenon, settings::SettingsInterface<bool>>
alertAudioEnabled_ {};
@ -826,26 +832,34 @@ void SettingsDialogImpl::SetupPalettesAlertsTab()
void SettingsDialogImpl::SetupAudioTab()
{
QObject::connect(self_->ui->alertAudioLocationMethodComboBox,
&QComboBox::currentTextChanged,
self_,
[this](const QString& text)
{
types::LocationMethod locationMethod =
types::GetLocationMethod(text.toStdString());
QObject::connect(
self_->ui->alertAudioLocationMethodComboBox,
&QComboBox::currentTextChanged,
self_,
[this](const QString& text)
{
types::LocationMethod locationMethod =
types::GetLocationMethod(text.toStdString());
bool coordinateEntryEnabled =
locationMethod == types::LocationMethod::Fixed;
bool coordinateEntryEnabled =
locationMethod == types::LocationMethod::Fixed;
bool countyEntryEnabled =
locationMethod == types::LocationMethod::County;
self_->ui->alertAudioLatitudeSpinBox->setEnabled(
coordinateEntryEnabled);
self_->ui->alertAudioLongitudeSpinBox->setEnabled(
coordinateEntryEnabled);
self_->ui->resetAlertAudioLatitudeButton->setEnabled(
coordinateEntryEnabled);
self_->ui->resetAlertAudioLongitudeButton->setEnabled(
coordinateEntryEnabled);
});
self_->ui->alertAudioLatitudeSpinBox->setEnabled(
coordinateEntryEnabled);
self_->ui->alertAudioLongitudeSpinBox->setEnabled(
coordinateEntryEnabled);
self_->ui->resetAlertAudioLatitudeButton->setEnabled(
coordinateEntryEnabled);
self_->ui->resetAlertAudioLongitudeButton->setEnabled(
coordinateEntryEnabled);
self_->ui->alertAudioCountyLineEdit->setEnabled(countyEntryEnabled);
self_->ui->alertAudioCountySelectButton->setEnabled(
countyEntryEnabled);
self_->ui->resetAlertAudioCountyButton->setEnabled(countyEntryEnabled);
});
settings::AudioSettings& audioSettings = settings::AudioSettings::Instance();
@ -927,6 +941,10 @@ void SettingsDialogImpl::SetupAudioTab()
alertAudioLongitude_.SetResetButton(
self_->ui->resetAlertAudioLongitudeButton);
alertAudioCounty_.SetSettingsVariable(audioSettings.alert_county());
alertAudioCounty_.SetEditWidget(self_->ui->alertAudioCountyLineEdit);
alertAudioCounty_.SetResetButton(self_->ui->resetAlertAudioCountyButton);
auto alertAudioLayout =
static_cast<QGridLayout*>(self_->ui->alertAudioGroupBox->layout());
@ -974,6 +992,47 @@ void SettingsDialogImpl::SetupAudioTab()
coordinate.longitude());
}
});
QObject::connect(
self_->ui->alertAudioCountySelectButton,
&QAbstractButton::clicked,
self_,
[this]()
{
std::string countyId =
self_->ui->alertAudioCountyLineEdit->text().toStdString();
if (countyId.length() >= 2)
{
countyDialog_->SelectState(countyId.substr(0, 2));
}
countyDialog_->show();
});
QObject::connect(countyDialog_,
&CountyDialog::accepted,
self_,
[this]()
{
std::string countyId = countyDialog_->county_fips_id();
QString qCountyId = QString::fromStdString(countyId);
self_->ui->alertAudioCountyLineEdit->setText(qCountyId);
// setText does not emit the textEdited signal
Q_EMIT self_->ui->alertAudioCountyLineEdit->textEdited(
qCountyId);
});
QObject::connect(self_->ui->alertAudioCountyLineEdit,
&QLineEdit::textChanged,
self_,
[this](const QString& text)
{
std::string countyName =
config::CountyDatabase::GetCountyName(
text.toStdString());
self_->ui->alertAudioCountyLabel->setText(
QString::fromStdString(countyName));
});
}
void SettingsDialogImpl::SetupTextTab()

View file

@ -460,22 +460,6 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QDoubleSpinBox" name="alertAudioLatitudeSpinBox">
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-90.000000000000000</double>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="singleStep">
<double>0.000100000000000</double>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QToolButton" name="resetAlertAudioLocationMethodButton">
<property name="text">
@ -508,22 +492,6 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QDoubleSpinBox" name="alertAudioLongitudeSpinBox">
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-180.000000000000000</double>
</property>
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="singleStep">
<double>0.000100000000000</double>
</property>
</widget>
</item>
<item row="3" column="6">
<widget class="QToolButton" name="resetAlertAudioLongitudeButton">
<property name="text">
@ -535,6 +503,14 @@
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QToolButton" name="alertAudioSoundStopButton">
<property name="icon">
<iconset resource="../../../../scwx-qt.qrc">
<normaloff>:/res/icons/font-awesome-6/stop-solid.svg</normaloff>:/res/icons/font-awesome-6/stop-solid.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QToolButton" name="resetAlertAudioLatitudeButton">
<property name="text">
@ -546,9 +522,6 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="alertAudioSoundLineEdit"/>
</item>
<item row="0" column="6">
<widget class="QToolButton" name="resetAlertAudioSoundButton">
<property name="text">
@ -575,7 +548,46 @@
</property>
</widget>
</item>
<item row="1" column="2">
<item row="4" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>County</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="alertAudioLongitudeSpinBox">
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-180.000000000000000</double>
</property>
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="singleStep">
<double>0.000100000000000</double>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="alertAudioLatitudeSpinBox">
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-90.000000000000000</double>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="singleStep">
<double>0.000100000000000</double>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="alertAudioLocationMethodComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -585,11 +597,50 @@
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QToolButton" name="alertAudioSoundStopButton">
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="alertAudioSoundLineEdit"/>
</item>
<item row="4" column="6">
<widget class="QToolButton" name="resetAlertAudioCountyButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../scwx-qt.qrc">
<normaloff>:/res/icons/font-awesome-6/stop-solid.svg</normaloff>:/res/icons/font-awesome-6/stop-solid.svg</iconset>
<normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QToolButton" name="alertAudioCountySelectButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="alertAudioCountyLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="alertAudioCountyLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
@ -604,7 +655,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>281</height>
<height>253</height>
</size>
</property>
</spacer>

@ -1 +1 @@
Subproject commit 8a633285ecbe8ff7d48631485620a7c7a5257229
Subproject commit 71d18bc659d5e2b68b57dfaeb20f87cb1f0675f2