BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
modelmapper.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/signals/modelmapper.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 
18 using namespace ModelView;
19 
28 
29  bool m_active{true};
30  SessionModel* m_model{nullptr};
31 
32  ModelMapperImpl(SessionModel* model) : m_model(model){};
33 
35  {
36  m_on_data_change.remove_client(client);
37  m_on_item_inserted.remove_client(client);
38  m_on_item_removed.remove_client(client);
39  m_on_item_about_removed.remove_client(client);
40  m_on_model_destroyed.remove_client(client);
41  m_on_model_about_reset.remove_client(client);
42  m_on_model_reset.remove_client(client);
43  }
44 };
45 
46 ModelMapper::ModelMapper(SessionModel* model) : p_impl(std::make_unique<ModelMapperImpl>(model)) {}
47 
48 ModelMapper::~ModelMapper() = default;
49 
50 //! Sets callback to be notified on item's data change. The callback will be called
51 //! with (SessionItem*, data_role).
52 
54 {
55  p_impl->m_on_data_change.connect(std::move(f), client);
56 }
57 
58 //! Sets callback to be notified on item insert. The callback will be called with
59 //! (SessionItem* parent, tagrow), where 'tagrow' denotes inserted child position.
60 
62 {
63  p_impl->m_on_item_inserted.connect(std::move(f), client);
64 }
65 
66 //! Sets callback to be notified on item remove. The callback will be called with
67 //! (SessionItem* parent, tagrow), where 'tagrow' denotes child position before the removal.
68 
70 {
71  p_impl->m_on_item_removed.connect(std::move(f), client);
72 }
73 
74 //! Sets callback to be notified when the item is about to be removed. The callback will be called
75 //! with (SessionItem* parent, tagrow), where 'tagrow' denotes child position being removed.
76 
78 {
79  p_impl->m_on_item_about_removed.connect(std::move(f), client);
80 }
81 
82 //! Sets the callback for notifications on model destruction.
83 
85 {
86  p_impl->m_on_model_destroyed.connect(std::move(f), client);
87 }
88 
89 //! Sets the callback to be notified just before the reset of the root item.
90 
92 {
93  p_impl->m_on_model_about_reset.connect(std::move(f), client);
94 }
95 
96 //! Sets the callback to be notified right after the root item recreation.
97 
99 {
100  p_impl->m_on_model_reset.connect(std::move(f), client);
101 }
102 
103 //! Sets activity flag to given value. Will disable all callbacks if false.
104 
105 void ModelMapper::setActive(bool value)
106 {
107  p_impl->m_active = value;
108 }
109 
110 //! Removes given client from all subscriptions.
111 
113 {
114  p_impl->unsubscribe(client);
115 }
116 
117 //! Notifies all callbacks subscribed to "item data is changed" event.
118 
120 {
121  if (p_impl->m_active)
122  p_impl->m_on_data_change(item, role);
123 }
124 
125 //! Notifies all callbacks subscribed to "item data is changed" event.
126 
128 {
129  if (p_impl->m_active)
130  p_impl->m_on_item_inserted(parent, tagrow);
131 }
132 
134 {
135  if (p_impl->m_active)
136  p_impl->m_on_item_removed(parent, tagrow);
137 }
138 
140 {
141  if (p_impl->m_active)
142  p_impl->m_on_item_about_removed(parent, tagrow);
143 }
144 
146 {
147  p_impl->m_on_model_destroyed(p_impl->m_model);
148 }
149 
151 {
152  p_impl->m_on_model_about_reset(p_impl->m_model);
153 }
154 
156 {
157  p_impl->m_on_model_reset(p_impl->m_model);
158 }
Defines class CLASS?
void callOnItemInserted(SessionItem *parent, const TagRow &tagrow)
Notifies all callbacks subscribed to "item data is changed" event.
std::unique_ptr< ModelMapperImpl > p_impl
Definition: modelmapper.h:61
void setOnModelAboutToBeReset(Callbacks::model_t f, Callbacks::slot_t client) override
Sets the callback to be notified just before the reset of the root item.
Definition: modelmapper.cpp:91
void setOnModelReset(Callbacks::model_t f, Callbacks::slot_t client) override
Sets the callback to be notified right after the root item recreation.
Definition: modelmapper.cpp:98
void setOnItemRemoved(Callbacks::item_tagrow_t f, Callbacks::slot_t client) override
Sets callback to be notified on item remove.
Definition: modelmapper.cpp:69
void setOnItemInserted(Callbacks::item_tagrow_t f, Callbacks::slot_t client) override
Sets callback to be notified on item insert.
Definition: modelmapper.cpp:61
void setOnModelDestroyed(Callbacks::model_t f, Callbacks::slot_t client) override
Sets the callback for notifications on model destruction.
Definition: modelmapper.cpp:84
void callOnItemAboutToBeRemoved(SessionItem *parent, const TagRow &tagrow)
void setOnDataChange(Callbacks::item_int_t f, Callbacks::slot_t client) override
Sets callback to be notified on item's data change.
Definition: modelmapper.cpp:53
void setOnAboutToRemoveItem(Callbacks::item_tagrow_t f, Callbacks::slot_t client) override
Sets callback to be notified when the item is about to be removed.
Definition: modelmapper.cpp:77
ModelMapper(SessionModel *model)
Definition: modelmapper.cpp:46
void callOnDataChange(SessionItem *item, int role)
Notifies all callbacks subscribed to "item data is changed" event.
void unsubscribe(Callbacks::slot_t client) override
Removes given client from all subscriptions.
void setActive(bool value)
Sets activity flag to given value. Will disable all callbacks if false.
void callOnItemRemoved(SessionItem *parent, const TagRow &tagrow)
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
void remove_client(U client)
Remove client from the list to call back.
Aggregate to hold (tag, row) information for SessionModel.
Definition: tagrow.h:25
Defines class CLASS?
std::function< void(SessionModel *)> model_t
std::function< void(SessionItem *, TagRow)> item_tagrow_t
std::function< void(SessionItem *, int)> item_int_t
materialitems.h Collection of materials to populate MaterialModel.
Definition: filesystem.h:81
Signal< Callbacks::model_t > m_on_model_destroyed
Definition: modelmapper.cpp:25
Signal< Callbacks::item_tagrow_t > m_on_item_removed
Definition: modelmapper.cpp:23
Signal< Callbacks::model_t > m_on_model_reset
Definition: modelmapper.cpp:27
void unsubscribe(Callbacks::slot_t client)
Definition: modelmapper.cpp:34
Signal< Callbacks::item_tagrow_t > m_on_item_inserted
Definition: modelmapper.cpp:22
ModelMapperImpl(SessionModel *model)
Definition: modelmapper.cpp:32
Signal< Callbacks::model_t > m_on_model_about_reset
Definition: modelmapper.cpp:26
Signal< Callbacks::item_int_t > m_on_data_change
Definition: modelmapper.cpp:21
Signal< Callbacks::item_tagrow_t > m_on_item_about_removed
Definition: modelmapper.cpp:24