BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialItemContainer.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/MaterialItemContainer.cpp
6 //! @brief Implements class MaterialItemContainer
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
19 
20 const QString MaterialItemContainer::T_MATERIALS = "MaterialVector";
21 
23 {
24  setItemName("Materials");
25  registerTag(T_MATERIALS, 0, -1, QStringList{"Material"});
26 }
27 
29 {
30  MaterialItem* item_copy = model()->copyItem(material_item, this, T_MATERIALS);
32 
33  return item_copy;
34 }
35 
37 {
38  return const_cast<MaterialItem*>(
39  static_cast<const MaterialItemContainer*>(this)->findMaterialById(id));
40 }
41 
43 {
44  auto materials = getItems(T_MATERIALS);
45  for (auto item : materials) {
46  auto material = dynamic_cast<MaterialItem*>(item);
47  if (material->identifier() == id)
48  return material;
49  }
50  return nullptr;
51 }
Defines class GUIHelpers functions.
Defines class MaterialItemContainer.
Defines class MaterialItem.
Defines class SessionModel.
static const QString T_MATERIALS
MaterialItem * insertCopy(MaterialItem *material_item)
Copies MaterialItem, inserts it into the container and returns a pointer to the copy.
const MaterialItem * findMaterialById(QString id) const
static const QString P_IDENTIFIER
Definition: MaterialItem.h:27
void setItemName(const QString &name)
Set item name, add property if necessary.
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types.
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:66
T * item(const QString &tag) const
Definition: SessionItem.h:151
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
T * copyItem(const T *item_to_copy, SessionItem *new_parent=0, const QString &tag="")
Definition: SessionModel.h:136
QString createUuid()
Definition: GUIHelpers.cpp:242