BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
compounditem.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/model/compounditem.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_MODEL_COMPOUNDITEM_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_MODEL_COMPOUNDITEM_H
17 
20 #include "mvvm/model/sessionitem.h"
21 #include "mvvm/model/taginfo.h"
22 #include "mvvm/utils/reallimits.h"
23 
24 namespace ModelView {
25 
26 //! Complex item holding mixed SessionItem types (single properties and other CompountItems).
27 
28 class MVVM_MODEL_EXPORT CompoundItem : public SessionItem {
29 public:
30  CompoundItem(const std::string& modelType = Constants::CompoundItemType);
31 
32  //! Adds property item of given type.
33  template <typename T = PropertyItem> T* addProperty(const std::string& name);
34 
35  template <typename V> PropertyItem* addProperty(const std::string& name, const V& value);
36 
37  //! Register char property. Special case to turn it into std::string.
38  PropertyItem* addProperty(const std::string& name, const char* value);
39 
40  std::string displayName() const override;
41 };
42 
43 template <typename T> T* CompoundItem::addProperty(const std::string& name)
44 {
45  T* property = new T;
47  property->setDisplayName(name);
48  insertItem(property, {name, 0});
49  return property;
50 }
51 
52 inline PropertyItem* CompoundItem::addProperty(const std::string& name, const char* value)
53 {
54  return addProperty(name, std::string(value));
55 }
56 
57 template <typename V>
58 PropertyItem* CompoundItem::addProperty(const std::string& name, const V& value)
59 {
60  auto property = new PropertyItem;
62  property->setDisplayName(name);
63  property->setData(value);
64 
65  if constexpr (std::is_floating_point_v<V>)
66  property->setData(RealLimits::limitless(), ItemDataRole::LIMITS);
67 
68  insertItem(property, {name, 0});
69  return property;
70 }
71 
72 } // namespace ModelView
73 
74 #endif // BORNAGAIN_MVVM_MODEL_MVVM_MODEL_COMPOUNDITEM_H
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
T * addProperty(const std::string &name)
Adds property item of given type.
Definition: compounditem.h:43
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
static RealLimits limitless()
Creates an object withoud bounds (default)
Definition: reallimits.cpp:66
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
bool insertItem(SessionItem *item, const TagRow &tagrow)
Insert item into given tag under the given row.
static TagInfo propertyTag(std::string name, std::string model_type)
Constructs tag intended for single property.
Definition: taginfo.cpp:40
Defines class CLASS?
const model_type CompoundItemType
Definition: mvvm_types.h:48
const int LIMITS
possibly limits on item's data
Definition: mvvm_types.h:33
materialitems.h Collection of materials to populate MaterialModel.
QString const & name(EShape k)
Definition: particles.cpp:21
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?