BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
modellistenerbase.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/modellistenerbase.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 
18 #include <stdexcept>
19 
20 using namespace ModelView;
21 
23 {
24  if (!m_model)
25  throw std::runtime_error("Error in ModelListenerBase: no model defined");
26  setOnModelDestroyed([this](SessionModel*) { m_model = nullptr; });
27 }
28 
30 {
31  unsubscribe();
32 }
33 
34 //! Sets callback to be notified on item's data change. The callback will be called
35 //! with (SessionItem*, data_role).
36 
38 {
39  m_model->mapper()->setOnDataChange(f, this);
40 }
41 
42 //! Sets callback to be notified on item insert. The callback will be called with
43 //! (SessionItem* parent, tagrow), where 'tagrow' denotes inserted child position.
44 
46 {
47  m_model->mapper()->setOnItemInserted(f, this);
48 }
49 
50 //! Sets callback to be notified on item remove. The callback will be called with
51 //! (SessionItem* parent, tagrow), where 'tagrow' denotes child position before the removal.
52 
54 {
55  m_model->mapper()->setOnItemRemoved(f, this);
56 }
57 
58 //! Sets callback to be notified when the item is about to be removed. The callback will be called
59 //! with (SessionItem* parent, tagrow), where 'tagrow' denotes child position being removed.
60 
63 {
65 }
66 
67 //! Sets the callback for notifications on model destruction.
68 
70 {
71  m_model->mapper()->setOnModelDestroyed(f, this);
72 }
73 
74 //! Sets the callback to be notified before model's full reset (root item recreated).
75 
77 {
79 }
80 
81 //! Sets the callback to be notified after model was fully reset (root item recreated).
82 
84 {
85  m_model->mapper()->setOnModelReset(f, this);
86 }
87 
89 {
90  if (m_model)
91  m_model->mapper()->unsubscribe(this);
92 }
void setOnItemRemoved(Callbacks::item_tagrow_t f, Callbacks::slot_t client={}) override
Sets callback to be notified on item remove.
void setOnItemInserted(Callbacks::item_tagrow_t f, Callbacks::slot_t client={}) override
Sets callback to be notified on item insert.
void setOnModelDestroyed(Callbacks::model_t f, Callbacks::slot_t client={}) override
Sets the callback for notifications on model destruction.
void unsubscribe(Callbacks::slot_t client={}) override
Removes given client from all subscriptions.
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.
void setOnModelAboutToBeReset(Callbacks::model_t f, Callbacks::slot_t client={}) override
Sets the callback to be notified before model's full reset (root item recreated).
void setOnDataChange(Callbacks::item_int_t f, Callbacks::slot_t client={}) override
Sets callback to be notified on item's data change.
void setOnModelReset(Callbacks::model_t f, Callbacks::slot_t client={}) override
Sets the callback to be notified after model was fully reset (root item recreated).
ModelListenerBase(SessionModel *model)
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 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
void unsubscribe(Callbacks::slot_t client) override
Removes given client from all subscriptions.
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
ModelMapper * mapper()
Returns model mapper. Can be used to subscribe to various model's signal.
Defines class CLASS?
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.
Defines class CLASS?