BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
itemlistenerbase.h
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.h
6 //! @brief Defines 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 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_SIGNALS_ITEMLISTENERBASE_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_SIGNALS_ITEMLISTENERBASE_H
17 
18 #include "mvvm/model_export.h"
20 
21 namespace ModelView {
22 
23 class SessionItem;
24 
25 //! Provides sets of methods to subscribe to various signals generated by SessionItem.
26 //! Used to implement user actions on item change.
27 
28 //! Automatically tracks the time of life of SessionItem. Unsubscribes from the item on
29 //! own destruction. Can be switched from tracking one item to another of the same type.
30 
31 class MVVM_MODEL_EXPORT ItemListenerBase {
32 public:
33  explicit ItemListenerBase(SessionItem* item = nullptr);
34  virtual ~ItemListenerBase();
35 
36  ItemListenerBase& operator=(const ItemListenerBase& other) = delete;
37  ItemListenerBase(const ItemListenerBase& other) = delete;
38 
39  void setItem(SessionItem* item);
40 
41  void setOnItemDestroy(Callbacks::item_t f);
42  void setOnDataChange(Callbacks::item_int_t f);
43  void setOnPropertyChange(Callbacks::item_str_t f);
44  void setOnChildPropertyChange(Callbacks::item_str_t f);
45  void setOnItemInserted(Callbacks::item_tagrow_t f);
46  void setOnItemRemoved(Callbacks::item_tagrow_t f);
47  void setOnAboutToRemoveItem(Callbacks::item_tagrow_t f);
48 
49 protected:
50  virtual void subscribe() {} //! For necessary manipulations on new item.
51  virtual void unsubscribe() {} //! For necessary manipulations on unsubscription.
52  SessionItem* item() const;
53 
54 private:
55  void unsubscribe_from_current();
56  SessionItem* m_item{nullptr};
57 };
58 
59 } // namespace ModelView
60 
61 #endif // BORNAGAIN_MVVM_MODEL_MVVM_SIGNALS_ITEMLISTENERBASE_H
Defines class CLASS?
Provides sets of methods to subscribe to various signals generated by SessionItem.
ItemListenerBase(const ItemListenerBase &other)=delete
ItemListenerBase & operator=(const ItemListenerBase &other)=delete
virtual void unsubscribe()
For necessary manipulations on new item.
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
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
materialitems.h Collection of materials to populate MaterialModel.