BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
linkeditem.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/standarditems/linkeditem.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_STANDARDITEMS_LINKEDITEM_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_LINKEDITEM_H
17 
18 #include "mvvm/model/sessionitem.h"
20 
21 namespace ModelView {
22 
23 //! Item to store a persistent link to other arbitrary items.
24 
25 //! The identifier of the item intended for linking is stored as DataRole on board of LinkedItem
26 //! and can be used to find the corresponding item via SessionModel::findItem machinery.
27 //! Provided mechanism is persistent and outlive serialization. Can be used to find items in
28 //! different models. For that being the case, models should use same ItemPool.
29 
30 class MVVM_MODEL_EXPORT LinkedItem : public SessionItem {
31 public:
32  LinkedItem();
33 
34  void setLink(const SessionItem* item);
35 
36  template <typename T = SessionItem> T* get() const;
37 };
38 
39 //! Returns item linked to given item. Works only in model context.
40 
41 template <typename T> T* LinkedItem::get() const
42 {
43  return model() ? dynamic_cast<T*>(model()->findItem(data<std::string>())) : nullptr;
44 }
45 
46 } // namespace ModelView
47 
48 #endif // BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_LINKEDITEM_H
Item to store a persistent link to other arbitrary items.
Definition: linkeditem.h:30
T * get() const
Returns item linked to given item. Works only in model context.
Definition: linkeditem.h:41
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
SessionModel * model() const
Returns the model to which given item belongs to.
SessionItem * findItem(const identifier_type &id)
Returns SessionItem for given identifier.
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?