BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
itemlistenerbase.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/itemlistenerbase.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 
15 #include "itemlistenerbase.h"
16 #include "mvvm/model/sessionitem.h"
18 
20 {
21  setItem(item);
22 }
23 
25 {
26  if (m_item)
27  m_item->mapper()->unsubscribe(this);
28 }
29 
31 {
32  if (m_item == item)
33  return;
34 
35  unsubscribe_from_current();
36 
37  m_item = item;
38 
39  if (!m_item)
40  return;
41 
42  auto on_item_destroy = [this](auto) {
43  m_item = nullptr;
44  unsubscribe();
45  };
46  m_item->mapper()->setOnItemDestroy(on_item_destroy, this);
47 
48  subscribe();
49 }
50 
52 {
53  item()->mapper()->setOnItemDestroy(f, this);
54 }
55 
56 //! Sets callback to be notified on item's data change.
57 //! Callback will be called with (SessionItem*, data_role).
58 
60 {
61  item()->mapper()->setOnDataChange(f, this);
62 }
63 
64 //! Sets callback to be notified on item's property change.
65 //! Callback will be called with (compound_item, property_name).
66 
68 {
69  item()->mapper()->setOnPropertyChange(f, this);
70 }
71 
72 //! Sets callback to be notified on item's children property change.
73 //! Callback will be called with (compound_item, property_name). For MultiLayer containing the
74 //! layer with "thickness" property, the signal will be triggered on thickness change using
75 //! (layeritem*, "thickness") as callback parameters.
76 
78 {
79  item()->mapper()->setOnChildPropertyChange(f, this);
80 }
81 
82 //! Sets callback to be notified on child insertion.
83 //! Callback will be called with (compound_item, tag, row). For MultiLayer containing the T_LAYERS
84 //! tag, the signal will be triggered on layer insertion with
85 //! (multilayer*, {T_LAYER, row}) as callback parameters.
86 
88 {
89  item()->mapper()->setOnItemInserted(f, this);
90 }
91 
92 //! Sets callback to be notified on child removal.
93 //! Callback will be called with (compound_item, tag, row). For MultiLayer containing the T_LAYERS
94 //! tag, the signal will be triggered on layer removal with
95 //! (multilayer*, {T_LAYER, oldrow}) as callback parameters.
96 
98 {
99  item()->mapper()->setOnItemRemoved(f, this);
100 }
101 
103 {
104  item()->mapper()->setOnAboutToRemoveItem(f, this);
105 }
106 
107 //! Sets callback to be notified when row is about to be removed.
108 //! Callback will be called with (compound_item, tagrow). For MultiLayer containing the T_LAYERS
109 //! tag, the signal will be triggered on layer deletion with
110 //! (multilayer*, {T_LAYER, row}) as callback parameters.
111 
113 {
114  return m_item;
115 }
116 
118 {
119  if (!m_item)
120  return;
121 
122  unsubscribe();
123 
124  m_item->mapper()->unsubscribe(this);
125 }
void setOnItemInserted(Callbacks::item_tagrow_t f)
Sets callback to be notified on child insertion.
void setOnPropertyChange(Callbacks::item_str_t f)
Sets callback to be notified on item's property change.
void setOnItemDestroy(Callbacks::item_t f)
SessionItem * item() const
For necessary manipulations on unsubscription.
void setOnItemRemoved(Callbacks::item_tagrow_t f)
Sets callback to be notified on child removal.
void setItem(SessionItem *item)
void setOnChildPropertyChange(Callbacks::item_str_t f)
Sets callback to be notified on item's children property change.
void setOnDataChange(Callbacks::item_int_t f)
Sets callback to be notified on item's data change.
ItemListenerBase(SessionItem *item=nullptr)
void setOnAboutToRemoveItem(Callbacks::item_tagrow_t f)
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
Defines class CLASS?
Defines class CLASS?
std::function< void(SessionItem *, std::string)> item_str_t
std::function< void(SessionItem *, TagRow)> item_tagrow_t
std::function< void(SessionItem *, int)> item_int_t
std::function< void(SessionItem *)> item_t
Defines class CLASS?