mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:50:05 +00:00 
			
		
		
		
	Implement discard functionality for line settings
This commit is contained in:
		
							parent
							
								
									6063de2095
								
							
						
					
					
						commit
						76809de2df
					
				
					 7 changed files with 89 additions and 7 deletions
				
			
		|  | @ -4,6 +4,8 @@ | ||||||
| 
 | 
 | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
| 
 | 
 | ||||||
|  | #include <boost/signals2/signal.hpp> | ||||||
|  | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
| namespace qt | namespace qt | ||||||
|  | @ -27,6 +29,8 @@ public: | ||||||
|                                       subcategoryArrays_; |                                       subcategoryArrays_; | ||||||
|    std::vector<SettingsCategory*>     subcategories_; |    std::vector<SettingsCategory*>     subcategories_; | ||||||
|    std::vector<SettingsVariableBase*> variables_; |    std::vector<SettingsVariableBase*> variables_; | ||||||
|  | 
 | ||||||
|  |    boost::signals2::signal<void()> resetSignal_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| SettingsCategory::SettingsCategory(const std::string& name) : | SettingsCategory::SettingsCategory(const std::string& name) : | ||||||
|  | @ -96,6 +100,32 @@ bool SettingsCategory::Commit() | ||||||
|    return committed; |    return committed; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void SettingsCategory::Reset() | ||||||
|  | { | ||||||
|  |    // Reset subcategory arrays
 | ||||||
|  |    for (auto& subcategoryArray : p->subcategoryArrays_) | ||||||
|  |    { | ||||||
|  |       for (auto& subcategory : subcategoryArray.second) | ||||||
|  |       { | ||||||
|  |          subcategory->Reset(); | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    // Reset subcategories
 | ||||||
|  |    for (auto& subcategory : p->subcategories_) | ||||||
|  |    { | ||||||
|  |       subcategory->Reset(); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    // Reset variables
 | ||||||
|  |    for (auto& variable : p->variables_) | ||||||
|  |    { | ||||||
|  |       variable->Reset(); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    p->resetSignal_(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool SettingsCategory::ReadJson(const boost::json::object& json) | bool SettingsCategory::ReadJson(const boost::json::object& json) | ||||||
| { | { | ||||||
|    bool validated = true; |    bool validated = true; | ||||||
|  | @ -252,6 +282,12 @@ void SettingsCategory::RegisterVariables( | ||||||
|       p->variables_.end(), variables.cbegin(), variables.cend()); |       p->variables_.end(), variables.cbegin(), variables.cend()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | boost::signals2::connection | ||||||
|  | SettingsCategory::RegisterResetCallback(std::function<void()> callback) | ||||||
|  | { | ||||||
|  |    return p->resetSignal_.connect(callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace settings
 | } // namespace settings
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
| #include <string> | #include <string> | ||||||
| 
 | 
 | ||||||
| #include <boost/json/object.hpp> | #include <boost/json/object.hpp> | ||||||
|  | #include <boost/signals2/connection.hpp> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -34,14 +35,18 @@ public: | ||||||
|    void SetDefaults(); |    void SetDefaults(); | ||||||
| 
 | 
 | ||||||
|    /**
 |    /**
 | ||||||
|     * Sets the current value of all variables to the staged |     * Sets the current value of all variables to the staged value. | ||||||
|     * value. |  | ||||||
|     * |     * | ||||||
|     * @return true if any staged value was committed, false if no staged values |     * @return true if any staged value was committed, false if no staged values | ||||||
|     * are present. |     * are present. | ||||||
|     */ |     */ | ||||||
|    bool Commit(); |    bool Commit(); | ||||||
| 
 | 
 | ||||||
|  |    /**
 | ||||||
|  |     * Clears the staged value of all variables. | ||||||
|  |     */ | ||||||
|  |    void Reset(); | ||||||
|  | 
 | ||||||
|    /**
 |    /**
 | ||||||
|     * Reads the variables from the JSON object. |     * Reads the variables from the JSON object. | ||||||
|     * |     * | ||||||
|  | @ -68,6 +73,14 @@ public: | ||||||
|    RegisterVariables(std::initializer_list<SettingsVariableBase*> variables); |    RegisterVariables(std::initializer_list<SettingsVariableBase*> variables); | ||||||
|    void RegisterVariables(std::vector<SettingsVariableBase*> variables); |    void RegisterVariables(std::vector<SettingsVariableBase*> variables); | ||||||
| 
 | 
 | ||||||
|  |    /**
 | ||||||
|  |     * Registers a function to be called when the category is reset. | ||||||
|  |     * | ||||||
|  |     * @param callback Function to be called | ||||||
|  |     */ | ||||||
|  |    boost::signals2::connection | ||||||
|  |    RegisterResetCallback(std::function<void()> callback); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|    std::unique_ptr<Impl> p; |    std::unique_ptr<Impl> p; | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ public: | ||||||
|    typedef std::function<void(const T& value)> ValueCallbackFunction; |    typedef std::function<void(const T& value)> ValueCallbackFunction; | ||||||
| 
 | 
 | ||||||
|    explicit SettingsVariable(const std::string& name); |    explicit SettingsVariable(const std::string& name); | ||||||
|    ~SettingsVariable(); |    virtual ~SettingsVariable(); | ||||||
| 
 | 
 | ||||||
|    SettingsVariable(const SettingsVariable&)            = delete; |    SettingsVariable(const SettingsVariable&)            = delete; | ||||||
|    SettingsVariable& operator=(const SettingsVariable&) = delete; |    SettingsVariable& operator=(const SettingsVariable&) = delete; | ||||||
|  | @ -96,7 +96,7 @@ public: | ||||||
|    /**
 |    /**
 | ||||||
|     * Clears the staged value of the settings variable. |     * Clears the staged value of the settings variable. | ||||||
|     */ |     */ | ||||||
|    void Reset(); |    void Reset() override; | ||||||
| 
 | 
 | ||||||
|    /**
 |    /**
 | ||||||
|     * Gets the staged value of the settings variable, if defined. |     * Gets the staged value of the settings variable, if defined. | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ class SettingsVariableBase | ||||||
| { | { | ||||||
| protected: | protected: | ||||||
|    explicit SettingsVariableBase(const std::string& name); |    explicit SettingsVariableBase(const std::string& name); | ||||||
|    ~SettingsVariableBase(); |    virtual ~SettingsVariableBase(); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|    SettingsVariableBase(const SettingsVariableBase&)            = delete; |    SettingsVariableBase(const SettingsVariableBase&)            = delete; | ||||||
|  | @ -48,6 +48,11 @@ public: | ||||||
|     */ |     */ | ||||||
|    virtual bool Commit() = 0; |    virtual bool Commit() = 0; | ||||||
| 
 | 
 | ||||||
|  |    /**
 | ||||||
|  |     * Clears the staged value of the settings variable. | ||||||
|  |     */ | ||||||
|  |    virtual void Reset() = 0; | ||||||
|  | 
 | ||||||
|    /**
 |    /**
 | ||||||
|     * Reads the value from the JSON object. If the read value is out of range, |     * Reads the value from the JSON object. If the read value is out of range, | ||||||
|     * the value is set to the minimum or maximum. If the read value fails |     * the value is set to the minimum or maximum. If the read value fails | ||||||
|  |  | ||||||
|  | @ -13,6 +13,8 @@ | ||||||
| #include <QToolButton> | #include <QToolButton> | ||||||
| #include <QVBoxLayout> | #include <QVBoxLayout> | ||||||
| 
 | 
 | ||||||
|  | #include <boost/signals2.hpp> | ||||||
|  | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
| namespace qt | namespace qt | ||||||
|  | @ -35,7 +37,13 @@ public: | ||||||
|       SetupUi(); |       SetupUi(); | ||||||
|       ConnectSignals(); |       ConnectSignals(); | ||||||
|    } |    } | ||||||
|    ~Impl() = default; |    ~Impl() | ||||||
|  |    { | ||||||
|  |       for (auto& c : bs2Connections_) | ||||||
|  |       { | ||||||
|  |          c.disconnect(); | ||||||
|  |       } | ||||||
|  |    }; | ||||||
| 
 | 
 | ||||||
|    void     AddPhenomenonLine(const std::string&      name, |    void     AddPhenomenonLine(const std::string&      name, | ||||||
|                               settings::LineSettings& lineSettings, |                               settings::LineSettings& lineSettings, | ||||||
|  | @ -54,6 +62,8 @@ public: | ||||||
|    EditLineDialog* editLineDialog_; |    EditLineDialog* editLineDialog_; | ||||||
|    LineLabel*      activeLineLabel_ {nullptr}; |    LineLabel*      activeLineLabel_ {nullptr}; | ||||||
| 
 | 
 | ||||||
|  |    std::vector<boost::signals2::connection> bs2Connections_ {}; | ||||||
|  | 
 | ||||||
|    boost::unordered_flat_map<awips::Phenomenon, QWidget*> phenomenonPages_ {}; |    boost::unordered_flat_map<awips::Phenomenon, QWidget*> phenomenonPages_ {}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -250,6 +260,11 @@ void AlertPaletteSettingsWidget::Impl::AddPhenomenonLine( | ||||||
| 
 | 
 | ||||||
|    self_->AddSettingsCategory(&lineSettings); |    self_->AddSettingsCategory(&lineSettings); | ||||||
| 
 | 
 | ||||||
|  |    boost::signals2::connection c = lineSettings.RegisterResetCallback( | ||||||
|  |       [lineLabel, &lineSettings]() | ||||||
|  |       { lineLabel->set_line_settings(lineSettings); }); | ||||||
|  |    bs2Connections_.push_back(c); | ||||||
|  | 
 | ||||||
|    connect( |    connect( | ||||||
|       toolButton, |       toolButton, | ||||||
|       &QAbstractButton::clicked, |       &QAbstractButton::clicked, | ||||||
|  |  | ||||||
|  | @ -61,6 +61,11 @@ bool SettingsPageWidget::CommitChanges() | ||||||
| 
 | 
 | ||||||
| void SettingsPageWidget::DiscardChanges() | void SettingsPageWidget::DiscardChanges() | ||||||
| { | { | ||||||
|  |    for (auto& category : p->categories_) | ||||||
|  |    { | ||||||
|  |       category->Reset(); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    for (auto& setting : p->settings_) |    for (auto& setting : p->settings_) | ||||||
|    { |    { | ||||||
|       setting->Reset(); |       setting->Reset(); | ||||||
|  |  | ||||||
|  | @ -60,9 +60,17 @@ public: | ||||||
|    void ResetToDefault(); |    void ResetToDefault(); | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
|    void AddSettingsCategory(settings::SettingsCategory* category); |  | ||||||
|    void AddSettingsInterface(settings::SettingsInterfaceBase* setting); |    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: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|    std::shared_ptr<Impl> p; |    std::shared_ptr<Impl> p; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat