Implement discard functionality for line settings

This commit is contained in:
Dan Paulat 2024-09-22 09:54:32 -05:00
parent 6063de2095
commit 76809de2df
7 changed files with 89 additions and 7 deletions

View file

@ -13,6 +13,8 @@
#include <QToolButton>
#include <QVBoxLayout>
#include <boost/signals2.hpp>
namespace scwx
{
namespace qt
@ -35,7 +37,13 @@ public:
SetupUi();
ConnectSignals();
}
~Impl() = default;
~Impl()
{
for (auto& c : bs2Connections_)
{
c.disconnect();
}
};
void AddPhenomenonLine(const std::string& name,
settings::LineSettings& lineSettings,
@ -54,6 +62,8 @@ public:
EditLineDialog* editLineDialog_;
LineLabel* activeLineLabel_ {nullptr};
std::vector<boost::signals2::connection> bs2Connections_ {};
boost::unordered_flat_map<awips::Phenomenon, QWidget*> phenomenonPages_ {};
};
@ -250,6 +260,11 @@ void AlertPaletteSettingsWidget::Impl::AddPhenomenonLine(
self_->AddSettingsCategory(&lineSettings);
boost::signals2::connection c = lineSettings.RegisterResetCallback(
[lineLabel, &lineSettings]()
{ lineLabel->set_line_settings(lineSettings); });
bs2Connections_.push_back(c);
connect(
toolButton,
&QAbstractButton::clicked,

View file

@ -61,6 +61,11 @@ bool SettingsPageWidget::CommitChanges()
void SettingsPageWidget::DiscardChanges()
{
for (auto& category : p->categories_)
{
category->Reset();
}
for (auto& setting : p->settings_)
{
setting->Reset();

View file

@ -60,9 +60,17 @@ public:
void ResetToDefault();
protected:
void AddSettingsCategory(settings::SettingsCategory* category);
void AddSettingsInterface(settings::SettingsInterfaceBase* setting);
/**
* Commits and resets all settings within a category upon page commit or
* reset. The use of SettingsInterface is preferred, as it allows the binding
* of widgets to these actions.
*
* @param [in] category Settings category
*/
void AddSettingsCategory(settings::SettingsCategory* category);
private:
class Impl;
std::shared_ptr<Impl> p;