BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
propertyflatviewmodel.test.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/tests/testviewmodel/propertyflatviewmodel.test.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 
15 #include "google_test.h"
17 #include "mvvm/model/sessionitem.h"
19 #include "mvvm/model/taginfo.h"
22 #include "toyitems.h"
23 #include "toymodel.h"
24 
25 using namespace ModelView;
26 
27 //! Tests for PropertyFlatViewModel class.
28 
29 class PropertyFlatViewModelTest : public ::testing::Test {
30 public:
32 };
33 
35 
37 {
38  SessionModel model;
39  PropertyFlatViewModel viewModel(&model);
40  EXPECT_EQ(viewModel.rowCount(), 0);
41  EXPECT_EQ(viewModel.columnCount(), 0);
42  EXPECT_EQ(viewModel.sessionItemFromIndex(QModelIndex()), model.rootItem());
43 }
44 
46 {
47  SessionModel model;
48  model.insertItem<SessionItem>();
49 
50  PropertyFlatViewModel viewModel(&model);
51 
52  // Root item has default tag and all items considered as top items.
53  // PropertyViewModel shouldn't see any items.
54  EXPECT_EQ(viewModel.rowCount(), 0);
55  EXPECT_EQ(viewModel.columnCount(), 0);
56 }
57 
59 {
60  SessionModel model;
61  auto parent = model.insertItem<SessionItem>();
62 
63  parent->registerTag(TagInfo::universalTag("universal_tag"));
64  parent->registerTag(TagInfo::propertyTag("property_tag", Constants::PropertyType));
65 
66  model.insertItem<SessionItem>(parent, "universal_tag");
67  model.insertItem<PropertyItem>(parent, "property_tag");
68  model.insertItem<SessionItem>(parent, "universal_tag");
69 
70  PropertyFlatViewModel viewModel(&model);
71  viewModel.setRootSessionItem(parent);
72 
73  // View model should see only property item belonging to parent.
74  EXPECT_EQ(viewModel.rowCount(), 1);
75  EXPECT_EQ(viewModel.columnCount(), 2);
76 }
77 
78 //! VectorItem in a model.
79 
81 {
82  SessionModel model;
83  auto parent = model.insertItem<VectorItem>();
84 
85  PropertyFlatViewModel viewModel(&model);
86 
87  EXPECT_EQ(viewModel.rowCount(), 0); // root item doesn't have properties
88  EXPECT_EQ(viewModel.columnCount(), 0);
89 
90  // switching to vectorItem and checking that it has 3 properties
91  viewModel.setRootSessionItem(parent);
92  EXPECT_EQ(viewModel.rowCount(), 3);
93  EXPECT_EQ(viewModel.columnCount(), 2);
94 }
95 
96 //! ParticleItem in a model
97 
99 {
100  ToyItems::SampleModel model;
101  auto particle = model.insertItem<ToyItems::ParticleItem>();
102  auto group = dynamic_cast<GroupItem*>(particle->getItem(ToyItems::ParticleItem::P_SHAPES));
103  group->setCurrentType(ToyItems::Constants::SphereItemType);
104 
105  PropertyFlatViewModel viewModel(&model);
106  viewModel.setRootSessionItem(particle);
107 
108  // We should see 3 rows: VectorItem, GroupItem itself, and Radius of sphere
109  EXPECT_EQ(viewModel.rowCount(), 3);
110  EXPECT_EQ(viewModel.columnCount(), 2);
111 
112  // switching group
113  group->setCurrentType(ToyItems::Constants::CylinderItemType);
114  // We should see 3 rows: VectorItem, GroupItem itself, Cylinderr length and radius
115  EXPECT_EQ(viewModel.rowCount(), 4);
116  EXPECT_EQ(viewModel.columnCount(), 2);
117 
118  // switching back
119  group->setCurrentType(ToyItems::Constants::SphereItemType);
120  EXPECT_EQ(viewModel.rowCount(), 3);
121  EXPECT_EQ(viewModel.columnCount(), 2);
122 }
Group item holds collection of predefined items.
Definition: groupitem.h:26
View model to show content of SessionModel in Qt widgets.
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
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.
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
SessionItem * rootItem() const
Returns root item of the model.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
Definition: taginfo.cpp:34
static TagInfo propertyTag(std::string name, std::string model_type)
Constructs tag intended for single property.
Definition: taginfo.cpp:40
Vector item with three x,y,z property items.
Definition: vectoritem.h:24
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setRootSessionItem(SessionItem *item)
Definition: viewmodel.cpp:52
SessionItem * sessionItemFromIndex(const QModelIndex &index) const
Definition: viewmodel.cpp:59
Tests for PropertyFlatViewModel class.
Represents a particle, with a position, and a selection of possible shapes.
Definition: toyitems.h:62
static const std::string P_SHAPES
Definition: toyitems.h:65
Defines class CLASS?
const model_type PropertyType
Definition: mvvm_types.h:59
materialitems.h Collection of materials to populate MaterialModel.
const ModelView::model_type SphereItemType
Definition: toyitems.h:36
const ModelView::model_type CylinderItemType
Definition: toyitems.h:35
Defines class CLASS?
TEST_F(PropertyFlatViewModelTest, initialState)
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?