BornAgain  1.19.0
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/coregui/Views/CommonWidgets/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 
18 
20  : QObject(prt), m_item(nullptr), m_parent_subscribed(false)
21 {
22  ASSERT(parent());
23 }
24 
26 {
28 }
29 
31 {
32  if (m_item == item)
33  return;
34 
35  if (m_item) {
36  m_item->mapper()->unsubscribe(this);
37  unsubscribe();
38  }
39 
40  m_item = item;
41  if (!m_item)
42  return;
43 
44  m_item->mapper()->setOnItemDestroy([this](SessionItem*) { onItemDestroy(); }, this);
45 }
46 
48 {
49  return m_item;
50 }
51 
53 {
55 }
56 
58 {
60 }
61 
62 //! Subscribe parent to item's signals.
63 
65 {
66  if (!m_item)
67  return;
68 
71 }
72 
73 //! Fully unsubscribes the parent from listening item's signals.
74 //! Controller stays active to track item destruction.
75 
77 {
78  if (!m_item)
79  return;
80 
83 
84  m_item->mapper()->unsubscribe(parent());
85 }
86 
88 {
91  m_item = nullptr;
92 }
93 
95 {
96  if (m_item) {
97  m_item->mapper()->unsubscribe(this);
98  m_item->mapper()->unsubscribe(parent());
99  }
100 }
101 
103 {
105  ASSERT(m_parent_subscribed == false);
107  m_parent_subscribed = true;
108 }
109 
110 //! Calls additional callback on un
111 
113 {
115  ASSERT(m_parent_subscribed == true);
117  m_parent_subscribed = false;
118 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines class GUIHelpers functions.
Defines class SessionItemController.
Defines class SessionItem.
void unsubscribe(const void *caller)
Cancells all subscribtion of given caller.
Definition: ModelMapper.cpp:98
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=0)
Definition: ModelMapper.cpp:87
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.
void subscribe()
Subscribe parent to item's signals.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.