BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ComponentUtils.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/PropertyEditor/ComponentUtils.cpp
6 //! @brief Implements ComponentUtils namespace
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 
17 
18 namespace {
19 QList<const SessionItem*> groupItems(const SessionItem& item);
20 }
21 
23 {
24  QStringList result = QStringList() << "Property"
25  << "GroupProperty"
26  << "Vector"
27  << "BasicAxis"
28  << "AmplitudeAxis"
29  << "MaterialRefractiveData";
30  return result;
31 }
32 
33 QList<const SessionItem*> ComponentUtils::componentItems(const SessionItem& item)
34 {
35  static QStringList propertyRelated = ComponentUtils::propertyRelatedTypes();
36 
37  QList<const SessionItem*> result;
38 
39  if (item.modelType() == "Property") {
40  result.push_back(&item);
41 
42  } else if (item.modelType() == "GroupProperty") {
43  result.push_back(&item);
44  result += groupItems(item);
45 
46  } else {
47 
48  for (auto child : item.children()) {
49  if (!child->isVisible())
50  continue;
51 
52  if (propertyRelated.contains(child->modelType()))
53  result.append(child);
54 
55  if (child->modelType() == "GroupProperty")
56  result += groupItems(*child);
57  }
58  }
59 
60  return result;
61 }
62 
63 namespace {
64 QList<const SessionItem*> groupItems(const SessionItem& item)
65 {
66  ASSERT(item.modelType() == "GroupProperty");
67 
68  QList<const SessionItem*> result;
69  for (auto grandchild : item.children()) {
70  if (grandchild->isVisible())
71  result += ComponentUtils::componentItems(*grandchild);
72  }
73 
74  return result;
75 }
76 } // namespace
#define ASSERT(condition)
Definition: Assert.h:31
Defines ComponentUtils namespace.
Defines class SessionItem.
QVector< SessionItem * > children() const
Returns vector of all children.
QString modelType() const
Get model type.
QList< const SessionItem * > componentItems(const SessionItem &item)
Returns list of SessionItem's children suitable for editing in property editors.
QStringList propertyRelatedTypes()
Returns list of strings representing modelTypes suitable for editing in component editors.