BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SessionItemController Class Reference

Description

Provides subscribe/unsubscribe mechanism for any QObject to track time of life of SessionItem. Mainly intended for SessionItemWidget.

Definition at line 26 of file SessionItemController.h.

Inheritance diagram for SessionItemController:
[legend]
Collaboration diagram for SessionItemController:
[legend]

Public Types

using callback_t = std::function< void(void)>
 

Public Member Functions

 SessionItemController (QObject *prt)
 
 ~SessionItemController () override
 
SessionItemcurrentItem ()
 
void setItem (SessionItem *item)
 
void setSubscribeCallback (callback_t fun)
 
void setUnsubscribeCallback (callback_t fun)
 
void subscribe ()
 Subscribe parent to item's signals. More...
 
void unsubscribe ()
 Fully unsubscribes the parent from listening item's signals. Controller stays active to track item destruction. More...
 

Private Member Functions

void onControllerDestroy ()
 
void onItemDestroy ()
 
void subscribeParent ()
 
void unsubscribeParent ()
 Calls additional callback on un. More...
 

Private Attributes

SessionItemm_item
 
bool m_parent_subscribed
 
callback_t m_subscribe_callback
 
callback_t m_unsubscribe_callback
 

Member Typedef Documentation

◆ callback_t

using SessionItemController::callback_t = std::function<void(void)>

Definition at line 29 of file SessionItemController.h.

Constructor & Destructor Documentation

◆ SessionItemController()

SessionItemController::SessionItemController ( QObject *  prt)
explicit

Definition at line 18 of file SessionItemController.cpp.

19  : QObject(prt)
20  , m_item(nullptr)
21  , m_parent_subscribed(false)
22 {
23  ASSERT(parent());
24 }

◆ ~SessionItemController()

SessionItemController::~SessionItemController ( )
override

Definition at line 26 of file SessionItemController.cpp.

27 {
29 }

References onControllerDestroy().

Here is the call graph for this function:

Member Function Documentation

◆ currentItem()

SessionItem * SessionItemController::currentItem ( )

Definition at line 48 of file SessionItemController.cpp.

49 {
50  return m_item;
51 }

References m_item.

Referenced by SessionItemWidget::currentItem().

◆ onControllerDestroy()

void SessionItemController::onControllerDestroy ( )
private

Definition at line 95 of file SessionItemController.cpp.

96 {
97  if (m_item) {
98  m_item->mapper()->unsubscribe(this);
99  m_item->mapper()->unsubscribe(parent());
100  }
101 }
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.

References m_item, SessionItem::mapper(), and ModelMapper::unsubscribe().

Referenced by ~SessionItemController().

Here is the call graph for this function:

◆ onItemDestroy()

void SessionItemController::onItemDestroy ( )
private

Definition at line 88 of file SessionItemController.cpp.

89 {
92  m_item = nullptr;
93 }
void unsubscribeParent()
Calls additional callback on un.

References m_item, m_parent_subscribed, and unsubscribeParent().

Referenced by setItem().

Here is the call graph for this function:

◆ setItem()

void SessionItemController::setItem ( SessionItem item)

Definition at line 31 of file SessionItemController.cpp.

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 }
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:67
void unsubscribe()
Fully unsubscribes the parent from listening item's signals. Controller stays active to track item de...
Base class for a GUI data item.
Definition: SessionItem.h:204

References m_item, SessionItem::mapper(), onItemDestroy(), ModelMapper::setOnItemDestroy(), unsubscribe(), and ModelMapper::unsubscribe().

Referenced by SessionItemWidget::setItem().

Here is the call graph for this function:

◆ setSubscribeCallback()

void SessionItemController::setSubscribeCallback ( callback_t  fun)

Definition at line 53 of file SessionItemController.cpp.

54 {
56 }

References m_subscribe_callback.

Referenced by SessionItemWidget::SessionItemWidget().

◆ setUnsubscribeCallback()

void SessionItemController::setUnsubscribeCallback ( callback_t  fun)

Definition at line 58 of file SessionItemController.cpp.

59 {
61 }

References m_unsubscribe_callback.

Referenced by SessionItemWidget::SessionItemWidget().

◆ subscribe()

void SessionItemController::subscribe ( )

Subscribe parent to item's signals.

Definition at line 65 of file SessionItemController.cpp.

66 {
67  if (!m_item)
68  return;
69 
72 }

References m_item, m_parent_subscribed, and subscribeParent().

Referenced by SessionItemWidget::setItem(), and SessionItemWidget::showEvent().

Here is the call graph for this function:

◆ subscribeParent()

void SessionItemController::subscribeParent ( )
private

Definition at line 103 of file SessionItemController.cpp.

104 {
105  ASSERT(m_subscribe_callback);
106  ASSERT(m_parent_subscribed == false);
108  m_parent_subscribed = true;
109 }

References m_parent_subscribed, and m_subscribe_callback.

Referenced by subscribe().

◆ unsubscribe()

void SessionItemController::unsubscribe ( )

Fully unsubscribes the parent from listening item's signals. Controller stays active to track item destruction.

Definition at line 77 of file SessionItemController.cpp.

78 {
79  if (!m_item)
80  return;
81 
84 
85  m_item->mapper()->unsubscribe(parent());
86 }

References m_item, m_parent_subscribed, SessionItem::mapper(), ModelMapper::unsubscribe(), and unsubscribeParent().

Referenced by SessionItemWidget::hideEvent(), and setItem().

Here is the call graph for this function:

◆ unsubscribeParent()

void SessionItemController::unsubscribeParent ( )
private

Calls additional callback on un.

Definition at line 113 of file SessionItemController.cpp.

114 {
115  ASSERT(m_unsubscribe_callback);
116  ASSERT(m_parent_subscribed == true);
118  m_parent_subscribed = false;
119 }

References m_parent_subscribed, and m_unsubscribe_callback.

Referenced by onItemDestroy(), and unsubscribe().

Member Data Documentation

◆ m_item

SessionItem* SessionItemController::m_item
private

◆ m_parent_subscribed

bool SessionItemController::m_parent_subscribed
private

◆ m_subscribe_callback

callback_t SessionItemController::m_subscribe_callback
private

Definition at line 50 of file SessionItemController.h.

Referenced by setSubscribeCallback(), and subscribeParent().

◆ m_unsubscribe_callback

callback_t SessionItemController::m_unsubscribe_callback
private

Definition at line 51 of file SessionItemController.h.

Referenced by setUnsubscribeCallback(), and unsubscribeParent().


The documentation for this class was generated from the following files: