BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SessionItemController.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Common/SessionItemController.cpp
6 //! @brief Implements class SessionItemController
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 
19  : QObject(prt)
20  , m_item(nullptr)
21  , m_parent_subscribed(false)
22 {
23  ASSERT(parent());
24 }
25 
27 {
29 }
30 
32 {
33  if (m_item == item)
34  return;
35 
36  if (m_item) {
37  m_item->mapper()->unsubscribe(this);
38  unsubscribe();
39  }
40 
41  m_item = item;
42  if (!m_item)
43  return;
44 
45  m_item->mapper()->setOnItemDestroy([this](SessionItem*) { onItemDestroy(); }, this);
46 }
47 
49 {
50  return m_item;
51 }
52 
54 {
56 }
57 
59 {
61 }
62 
63 //! Subscribe parent to item's signals.
64 
66 {
67  if (!m_item)
68  return;
69 
72 }
73 
74 //! Fully unsubscribes the parent from listening item's signals.
75 //! Controller stays active to track item destruction.
76 
78 {
79  if (!m_item)
80  return;
81 
84 
85  m_item->mapper()->unsubscribe(parent());
86 }
87 
89 {
92  m_item = nullptr;
93 }
94 
96 {
97  if (m_item) {
98  m_item->mapper()->unsubscribe(this);
99  m_item->mapper()->unsubscribe(parent());
100  }
101 }
102 
104 {
105  ASSERT(m_subscribe_callback);
106  ASSERT(m_parent_subscribed == false);
108  m_parent_subscribed = true;
109 }
110 
111 //! Calls additional callback on un
112 
114 {
115  ASSERT(m_unsubscribe_callback);
116  ASSERT(m_parent_subscribed == true);
118  m_parent_subscribed = false;
119 }
Defines class SessionItemController.
Defines class SessionItem.
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:67
void setUnsubscribeCallback(callback_t fun)
void setItem(SessionItem *item)
void setSubscribeCallback(callback_t fun)
std::function< void(void)> callback_t
void unsubscribeParent()
Calls additional callback on un.
void unsubscribe()
Fully unsubscribes the parent from listening item's signals. Controller stays active to track item de...
void subscribe()
Subscribe parent to item's signals.
Base class for a GUI data item.
Definition: SessionItem.h:204
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.