mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Change GncOptionUIItem to be a pure virtual class instead of a templated one.
Simplifies the design because derived classes can have whatever save UI class they need and implement the void(void) set_ui_item_from option and set_option_from_ui_item with whatever functions are appropriate for the UI class. No need for callbacks or std::function members.
This commit is contained in:
parent
00aa0f603d
commit
fce33799af
@ -25,17 +25,10 @@
|
|||||||
#define GNC_OPTION_UI_HPP_
|
#define GNC_OPTION_UI_HPP_
|
||||||
|
|
||||||
#include "gnc-option-uitype.hpp"
|
#include "gnc-option-uitype.hpp"
|
||||||
template <typename UIType>
|
|
||||||
class GncUIItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GncUIItem(UIType* widget) : m_widget{widget} {}
|
|
||||||
UIType* m_widget;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GncUIType;
|
class GncOptionUIItem;
|
||||||
using OptionUIItem = GncUIItem<GncUIType>;
|
using GncOptionUIItemPtr = std::unique_ptr<GncOptionUIItem>;
|
||||||
using OptionSyncFunc = std::function<void(OptionUIItem&, GncOption&)>;
|
|
||||||
/**
|
/**
|
||||||
* Holds a pointer to the UI item which will control the option and an enum
|
* Holds a pointer to the UI item which will control the option and an enum
|
||||||
* representing the type of the option for dispatch purposes; all of that
|
* representing the type of the option for dispatch purposes; all of that
|
||||||
@ -47,47 +40,18 @@ using OptionSyncFunc = std::function<void(OptionUIItem&, GncOption&)>;
|
|||||||
* clear_ui_item function can be used as a weak_ptr's destruction callback to
|
* clear_ui_item function can be used as a weak_ptr's destruction callback to
|
||||||
* ensure that the ptr will be nulled if the ui_item is destroyed elsewhere.
|
* ensure that the ptr will be nulled if the ui_item is destroyed elsewhere.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class GncOptionUIItem
|
class GncOptionUIItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GncOptionUIItem(OptionUIItem&& ui_item, GncOptionUIType type,
|
GncOptionUIItem() = default;
|
||||||
OptionSyncFunc to_ui, OptionSyncFunc from_ui) :
|
virtual ~GncOptionUIItem() = default;
|
||||||
m_ui_item{std::move(ui_item)}, m_ui_type{type},
|
virtual GncOptionUIType get_ui_type() const noexcept = 0;
|
||||||
m_set_ui_item_from_option{to_ui}, m_set_option_from_ui_item{from_ui} {}
|
virtual void set_dirty(bool status) noexcept = 0;
|
||||||
GncOptionUIItem(GncOptionUIType ui_type) :
|
virtual bool get_dirty() const noexcept = 0;
|
||||||
m_ui_item{nullptr}, m_ui_type{ui_type} {}
|
virtual void clear_ui_item() = 0;
|
||||||
GncOptionUIItem(const GncOptionUIItem&) = default;
|
virtual void set_ui_item_from_option(GncOption& option) noexcept = 0;
|
||||||
GncOptionUIItem(GncOptionUIItem&&) = default;
|
virtual void set_option_from_ui_item(GncOption& option) noexcept = 0;
|
||||||
~GncOptionUIItem() = default;
|
|
||||||
GncOptionUIItem& operator=(const GncOptionUIItem&) = default;
|
|
||||||
GncOptionUIItem& operator=(GncOptionUIItem&&) = default;
|
|
||||||
GncOptionUIType get_ui_type() const { return m_ui_type; }
|
|
||||||
const OptionUIItem& get_ui_item() const {return m_ui_item; }
|
|
||||||
void clear_ui_item() { m_ui_item = nullptr; }
|
|
||||||
void set_ui_item(OptionUIItem&& ui_item)
|
|
||||||
{
|
|
||||||
if (m_ui_type == GncOptionUIType::INTERNAL)
|
|
||||||
{
|
|
||||||
std::string error{"INTERNAL option, setting the UI item forbidden."};
|
|
||||||
throw std::logic_error(std::move(error));
|
|
||||||
}
|
|
||||||
m_ui_item = std::move(ui_item);
|
|
||||||
}
|
|
||||||
void set_ui_item_from_option(GncOption& option)
|
|
||||||
{
|
|
||||||
m_set_ui_item_from_option(m_ui_item, option);
|
|
||||||
}
|
|
||||||
void set_option_from_ui_item(GncOption& option)
|
|
||||||
{
|
|
||||||
m_set_option_from_ui_item(m_ui_item, option);
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
OptionUIItem m_ui_item;
|
|
||||||
GncOptionUIType m_ui_type;
|
|
||||||
OptionSyncFunc m_set_ui_item_from_option;
|
|
||||||
OptionSyncFunc m_set_option_from_ui_item;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using GncOptionUIItemPtr = std::unique_ptr<GncOptionUIItem>;
|
|
||||||
|
|
||||||
#endif //GNC_OPTION_UI_HPP__
|
#endif //GNC_OPTION_UI_HPP__
|
||||||
|
Loading…
Reference in New Issue
Block a user