BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
standardchildrenstrategies.cpp
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/viewmodel/mvvm/viewmodel/standardchildrenstrategies.cpp
6 //! @brief Implements 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 
16 #include "mvvm/model/groupitem.h"
17 #include "mvvm/model/itemutils.h"
18 
19 using namespace ModelView;
20 
21 // ----------------------------------------------------------------------------
22 
23 std::vector<SessionItem*> AllChildrenStrategy::children(const SessionItem* item) const
24 {
25  return item ? item->children() : std::vector<SessionItem*>();
26 }
27 
28 std::vector<SessionItem*> TopItemsStrategy::children(const SessionItem* item) const
29 {
30  return item ? Utils::TopLevelItems(*item) : std::vector<SessionItem*>();
31 }
32 
33 // ----------------------------------------------------------------------------
34 
35 /*
36 PropertyItemsStrategy example: if group property has Cylinder active:
37 
38 Particle
39  ShapeGroup
40  Sphere
41  Radius
42  Cylinder
43  Height
44  Radius
45 
46 will become:
47 Particle
48  ShapeGroup -> Cylinder
49  Height
50  Radius
51 */
52 
53 std::vector<SessionItem*> PropertyItemsStrategy::children(const SessionItem* item) const
54 {
55  if (!item)
56  return std::vector<SessionItem*>();
57 
58  auto group = dynamic_cast<const GroupItem*>(item);
59  auto next_item = group ? group->currentItem() : item;
60  return Utils::SinglePropertyItems(*next_item);
61 }
62 
63 // ----------------------------------------------------------------------------
64 
65 /*
66 PropertyItemsFlatStrategy example: if group property has Cylinder active:
67 
68 Particle
69  ShapeGroup
70  Sphere
71  Radius
72  Cylinder
73  Height
74  Radius
75 
76 will become:
77 Particle
78  ShapeGroup -> Cylinder
79  Height
80  Radius
81 */
82 
83 std::vector<SessionItem*> PropertyItemsFlatStrategy::children(const SessionItem* item) const
84 {
85  if (!item)
86  return std::vector<SessionItem*>();
87 
88  if (auto group = dynamic_cast<const GroupItem*>(item); group)
89  return Utils::SinglePropertyItems(*group->currentItem());
90 
91  std::vector<SessionItem*> result;
92  for (auto child : Utils::SinglePropertyItems(*item)) {
93  if (auto group_item = dynamic_cast<GroupItem*>(child); group_item) {
94  result.push_back(group_item);
95  for (auto sub_property : Utils::SinglePropertyItems(*group_item->currentItem()))
96  result.push_back(sub_property);
97  } else {
98  result.push_back(child);
99  }
100  }
101 
102  return result;
103 }
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.
Group item holds collection of predefined items.
Definition: groupitem.h:26
const SessionItem * currentItem() const
Returns currently selected item.
Definition: groupitem.cpp:41
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.
Defines class CLASS?
Defines class CLASS?
MVVM_MODEL_EXPORT std::vector< SessionItem * > SinglePropertyItems(const SessionItem &item)
Returns vector of children representing property items.
Definition: itemutils.cpp:122
MVVM_MODEL_EXPORT std::vector< SessionItem * > TopLevelItems(const SessionItem &item)
Returns vector of children representing top level items.
Definition: itemutils.cpp:113
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?