BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
propertytableviewmodel.test.cpp File Reference

Implements class CLASS? More...

Include dependency graph for propertytableviewmodel.test.cpp:

Go to the source code of this file.

Classes

class  PropertyTableViewModelTest
 

Functions

 TEST_F (PropertyTableViewModelTest, baseItem)
 
 TEST_F (PropertyTableViewModelTest, initialState)
 
 TEST_F (PropertyTableViewModelTest, multiLayer)
 MultiLayer with layers, multilayer is given as root index. More...
 
 TEST_F (PropertyTableViewModelTest, multiLayerAndRootItem)
 MultiLayer with layers, view model still looks to the RootItem. More...
 
 TEST_F (PropertyTableViewModelTest, propertyItem)
 
 TEST_F (PropertyTableViewModelTest, vectorItem)
 VectorItem in a model. More...
 

Detailed Description

Implements class CLASS?

Homepage:\n http://www.bornagainproject.org
License:\n GNU General Public License v3 or higher (see COPYING)
Authors
Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)

Definition in file propertytableviewmodel.test.cpp.

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( PropertyTableViewModelTest  ,
baseItem   
)

Definition at line 42 of file propertytableviewmodel.test.cpp.

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 }
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
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104

References ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( PropertyTableViewModelTest  ,
initialState   
)

Definition at line 33 of file propertytableviewmodel.test.cpp.

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 }
SessionItem * rootItem() const
Returns root item of the model.

References ModelView::ViewModelBase::columnCount(), ModelView::SessionModel::rootItem(), ModelView::ViewModelBase::rowCount(), and ModelView::ViewModel::sessionItemFromIndex().

Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( PropertyTableViewModelTest  ,
multiLayer   
)

MultiLayer with layers, multilayer is given as root index.

Definition at line 113 of file propertytableviewmodel.test.cpp.

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 }
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

References ModelView::SessionModel::insertItem(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function:

◆ TEST_F() [4/6]

TEST_F ( PropertyTableViewModelTest  ,
multiLayerAndRootItem   
)

MultiLayer with layers, view model still looks to the RootItem.

No MultiLayer should be visible in table.

Definition at line 97 of file propertytableviewmodel.test.cpp.

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 }

References ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( PropertyTableViewModelTest  ,
propertyItem   
)

Definition at line 53 of file propertytableviewmodel.test.cpp.

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 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
const model_type PropertyType
Definition: mvvm_types.h:59

References ModelView::SessionModel::insertItem(), ModelView::TagInfo::propertyTag(), ModelView::Constants::PropertyType, ModelView::SessionItem::registerTag(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [6/6]

TEST_F ( PropertyTableViewModelTest  ,
vectorItem   
)

VectorItem in a model.

Definition at line 78 of file propertytableviewmodel.test.cpp.

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 }
Vector item with three x,y,z property items.
Definition: vectoritem.h:24

References ModelView::SessionModel::insertItem().

Here is the call graph for this function: