BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
propertytableviewmodel.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/propertytableviewmodel.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 
24 using namespace ModelView;
25 
26 class PropertyTableViewModelTest : public ::testing::Test {
27 public:
29 };
30 
32 
34 {
35  SessionModel model;
36  PropertyTableViewModel viewModel(&model);
37  EXPECT_EQ(viewModel.rowCount(), 0);
38  EXPECT_EQ(viewModel.columnCount(), 0);
39  EXPECT_EQ(viewModel.sessionItemFromIndex(QModelIndex()), model.rootItem());
40 }
41 
43 {
44  SessionModel model;
45  model.insertItem<SessionItem>();
46 
47  PropertyTableViewModel viewModel(&model);
48 
49  EXPECT_EQ(viewModel.rowCount(), 0);
50  EXPECT_EQ(viewModel.columnCount(), 0);
51 }
52 
54 {
55  SessionModel model;
56  auto parent = model.insertItem<SessionItem>();
57 
58  parent->registerTag(TagInfo::universalTag("universal_tag"));
59  parent->registerTag(TagInfo::propertyTag("property_tag", Constants::PropertyType));
60 
61  model.insertItem<SessionItem>(parent, "universal_tag");
62  model.insertItem<PropertyItem>(parent, "property_tag");
63  model.insertItem<SessionItem>(parent, "universal_tag");
64 
65  PropertyTableViewModel viewModel(&model);
66 
67  // one cell corresponding to single item at property_tag of our parent
68  EXPECT_EQ(viewModel.rowCount(), 1);
69  EXPECT_EQ(viewModel.columnCount(), 1);
70 
71  viewModel.setRootSessionItem(parent);
72  EXPECT_EQ(viewModel.rowCount(), 0);
73  EXPECT_EQ(viewModel.columnCount(), 0);
74 }
75 
76 //! VectorItem in a model.
77 
79 {
80  SessionModel model;
81  auto parent = model.insertItem<VectorItem>();
82 
83  PropertyTableViewModel viewModel(&model);
84 
85  EXPECT_EQ(viewModel.rowCount(), 1);
86  EXPECT_EQ(viewModel.columnCount(), 3);
87 
88  // switching to vectorItem and checking that it has 3 properties
89  viewModel.setRootSessionItem(parent);
90  EXPECT_EQ(viewModel.rowCount(), 0);
91  EXPECT_EQ(viewModel.columnCount(), 0);
92 }
93 
94 //! MultiLayer with layers, view model still looks to the RootItem.
95 //! No MultiLayer should be visible in table.
96 
97 TEST_F(PropertyTableViewModelTest, multiLayerAndRootItem)
98 {
99  SessionModel model;
100  auto multilayer = model.insertItem<ToyItems::MultiLayerItem>();
101  model.insertItem<ToyItems::LayerItem>(multilayer);
102  model.insertItem<ToyItems::LayerItem>(multilayer);
103 
104  PropertyTableViewModel viewModel(&model);
105 
106  // ViewModel should be empty, since we are looking to RootItem.
107  EXPECT_EQ(viewModel.rowCount(), 0);
108  EXPECT_EQ(viewModel.columnCount(), 0);
109 }
110 
111 //! MultiLayer with layers, multilayer is given as root index.
112 
114 {
115  SessionModel model;
116  auto multilayer = model.insertItem<ToyItems::MultiLayerItem>();
117  model.insertItem<ToyItems::LayerItem>(multilayer);
118  model.insertItem<ToyItems::LayerItem>(multilayer);
119 
120  PropertyTableViewModel viewModel(&model);
121  viewModel.setRootSessionItem(multilayer);
122 
123  EXPECT_EQ(viewModel.rowCount(), 2); // two layers
124  EXPECT_EQ(viewModel.columnCount(), 2); // layer thickness and color
125 
126  // add another layer
127  model.insertItem<ToyItems::LayerItem>(multilayer);
128  EXPECT_EQ(viewModel.rowCount(), 3); // two layers
129  EXPECT_EQ(viewModel.columnCount(), 2); // layer thickness and color
130 
131  // switching view model back to model's root, table should be empty
132  viewModel.setRootSessionItem(model.rootItem());
133  EXPECT_EQ(viewModel.rowCount(), 0); // two layers
134  EXPECT_EQ(viewModel.columnCount(), 0); // layer thickness and color
135 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
View model to show content of SessionModel in Qt widgets: all item properties as a table row.
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
SessionItem * sessionItemFromIndex(const QModelIndex &index) const
Definition: viewmodel.cpp:59
Represents a layer, with thickness and color, and possibly populated with particles.
Definition: toyitems.h:52
Represents multilayer with collection of layers.
Definition: toyitems.h:44
Defines class CLASS?
const model_type PropertyType
Definition: mvvm_types.h:59
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?
TEST_F(PropertyTableViewModelTest, initialState)
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?