Add alert palette reset buttons

This commit is contained in:
Dan Paulat 2024-09-29 08:19:51 -05:00
parent 2d8c3c8175
commit a1d9b25f0b
6 changed files with 177 additions and 0 deletions

View file

@ -48,6 +48,62 @@ SettingsCategory::SettingsCategory(SettingsCategory&&) noexcept = default;
SettingsCategory&
SettingsCategory::operator=(SettingsCategory&&) noexcept = default;
bool SettingsCategory::IsDefault() const
{
bool isDefault = true;
// Get subcategory array defaults
for (auto& subcategoryArray : p->subcategoryArrays_)
{
for (auto& subcategory : subcategoryArray.second)
{
isDefault = isDefault && subcategory->IsDefault();
}
}
// Get subcategory defaults
for (auto& subcategory : p->subcategories_)
{
isDefault = isDefault && subcategory->IsDefault();
}
// Get variable defaults
for (auto& variable : p->variables_)
{
isDefault = isDefault && variable->IsDefault();
}
return isDefault;
}
bool SettingsCategory::IsDefaultStaged() const
{
bool isDefaultStaged = true;
// Get subcategory array defaults
for (auto& subcategoryArray : p->subcategoryArrays_)
{
for (auto& subcategory : subcategoryArray.second)
{
isDefaultStaged = isDefaultStaged && subcategory->IsDefaultStaged();
}
}
// Get subcategory defaults
for (auto& subcategory : p->subcategories_)
{
isDefaultStaged = isDefaultStaged && subcategory->IsDefaultStaged();
}
// Get variable defaults
for (auto& variable : p->variables_)
{
isDefaultStaged = isDefaultStaged && variable->IsDefaultStaged();
}
return isDefaultStaged;
}
std::string SettingsCategory::name() const
{
return p->name_;
@ -102,6 +158,39 @@ void SettingsCategory::SetDefaults()
p->stagedSignal_();
}
void SettingsCategory::StageDefaults()
{
// Don't allow individual variables to invoke the signal when operating over
// the entire category
p->blockSignals_ = true;
// Stage subcategory array defaults
for (auto& subcategoryArray : p->subcategoryArrays_)
{
for (auto& subcategory : subcategoryArray.second)
{
subcategory->StageDefaults();
}
}
// Stage subcategory defaults
for (auto& subcategory : p->subcategories_)
{
subcategory->StageDefaults();
}
// Stage variable defaults
for (auto& variable : p->variables_)
{
variable->StageDefault();
}
// Unblock signals
p->blockSignals_ = false;
p->stagedSignal_();
}
bool SettingsCategory::Commit()
{
bool committed = false;

View file

@ -43,11 +43,34 @@ public:
*/
boost::signals2::signal<void()>& staged_signal();
/**
* Gets whether or not all settings variables are currently set to default
* values.
*
* @return true if all settings variables are currently set to default
* values, otherwise false.
*/
bool IsDefault() const;
/**
* Gets whether or not all settings variables currently have staged values
* set to default.
*
* @return true if all settings variables currently have staged values set
* to default, otherwise false.
*/
bool IsDefaultStaged() const;
/**
* Set all variables to their defaults.
*/
void SetDefaults();
/**
* Stage all variables to their defaults.
*/
void StageDefaults();
/**
* Sets the current value of all variables to the staged value.
*

View file

@ -65,6 +65,18 @@ inline auto FormatParameter(const T& value)
}
}
template<class T>
bool SettingsVariable<T>::IsDefault() const
{
return p->value_ == p->default_;
}
template<class T>
bool SettingsVariable<T>::IsDefaultStaged() const
{
return p->staged_.value_or(p->value_) == p->default_;
}
template<class T>
T SettingsVariable<T>::GetValue() const
{

View file

@ -37,6 +37,24 @@ public:
SettingsVariable(SettingsVariable&&) noexcept;
SettingsVariable& operator=(SettingsVariable&&) noexcept;
/**
* Gets whether or not the settings variable is currently set to its default
* value.
*
* @return true if the settings variable is currently set to its default
* value, otherwise false.
*/
bool IsDefault() const;
/**
* Gets whether or not the settings variable currently has its staged value
* set to default.
*
* @return true if the settings variable currently has its staged value set
* to default, otherwise false.
*/
bool IsDefaultStaged() const;
/**
* Gets the current value of the settings variable.
*

View file

@ -45,6 +45,24 @@ public:
*/
boost::signals2::signal<void()>& staged_signal();
/**
* Gets whether or not the settings variable is currently set to its default
* value.
*
* @return true if the settings variable is currently set to its default
* value, otherwise false.
*/
virtual bool IsDefault() const = 0;
/**
* Gets whether or not the settings variable currently has its staged value
* set to default.
*
* @return true if the settings variable currently has its staged value set
* to default, otherwise false.
*/
virtual bool IsDefaultStaged() const = 0;
/**
* Sets the current value of the settings variable to default.
*/

View file

@ -57,6 +57,8 @@ public:
settings::LineSettings* activeLineSettings_ {nullptr};
boost::unordered_flat_map<awips::Phenomenon, QWidget*> phenomenonPages_ {};
std::vector<boost::signals2::scoped_connection> connections_ {};
};
AlertPaletteSettingsWidget::AlertPaletteSettingsWidget(QWidget* parent) :
@ -243,9 +245,15 @@ void AlertPaletteSettingsWidget::Impl::AddPhenomenonLine(
LineLabel* lineLabel = new LineLabel(self_);
lineLabel->set_line_settings(lineSettings);
QToolButton* resetButton = new QToolButton(self_);
resetButton->setIcon(
QIcon {":/res/icons/font-awesome-6/rotate-left-solid.svg"});
resetButton->setVisible(!lineSettings.IsDefaultStaged());
layout->addWidget(new QLabel(tr(name.c_str()), self_), row, 0);
layout->addWidget(lineLabel, row, 1);
layout->addWidget(toolButton, row, 2);
layout->addWidget(resetButton, row, 3);
self_->AddSettingsCategory(&lineSettings);
@ -268,6 +276,15 @@ void AlertPaletteSettingsWidget::Impl::AddPhenomenonLine(
// Show the dialog
editLineDialog_->show();
});
connect(resetButton,
&QAbstractButton::clicked,
self_,
[&lineSettings]() { lineSettings.StageDefaults(); });
connections_.emplace_back(lineSettings.staged_signal().connect(
[resetButton, &lineSettings]()
{ resetButton->setVisible(!lineSettings.IsDefaultStaged()); }));
}
} // namespace ui