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

Implements class CLASS? More...

Include dependency graph for propertyviewmodel.test.cpp:

Go to the source code of this file.

Classes

class  PropertyViewModelTest
 Tests for PropertyViewModel class. More...
 

Functions

 TEST_F (PropertyViewModelTest, baseItem)
 
 TEST_F (PropertyViewModelTest, initialState)
 
 TEST_F (PropertyViewModelTest, layerInMultiLayerAsRootItem)
 LayerItem in a MultiLayer. More...
 
 TEST_F (PropertyViewModelTest, propertyItem)
 
 TEST_F (PropertyViewModelTest, 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 propertyviewmodel.test.cpp.

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( PropertyViewModelTest  ,
baseItem   
)

Definition at line 45 of file propertyviewmodel.test.cpp.

46 {
47  SessionModel model;
48  model.insertItem<SessionItem>();
49 
50  PropertyViewModel 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 }
View model to show content of SessionModel in Qt widgets.
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/5]

TEST_F ( PropertyViewModelTest  ,
initialState   
)

Definition at line 36 of file propertyviewmodel.test.cpp.

37 {
38  SessionModel model;
39  PropertyViewModel viewModel(&model);
40  EXPECT_EQ(viewModel.rowCount(), 0);
41  EXPECT_EQ(viewModel.columnCount(), 0);
42  EXPECT_EQ(viewModel.sessionItemFromIndex(QModelIndex()), model.rootItem());
43 }
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/5]

TEST_F ( PropertyViewModelTest  ,
layerInMultiLayerAsRootItem   
)

LayerItem in a MultiLayer.

Definition at line 98 of file propertyviewmodel.test.cpp.

99 {
100  SessionModel model;
101  auto multilayer = model.insertItem<ToyItems::MultiLayerItem>();
102  auto layer = model.insertItem<ToyItems::LayerItem>(multilayer);
103 
104  PropertyViewModel viewmodel(&model);
105  viewmodel.setRootSessionItem(layer);
106 
107  // check layer thickness and color
108  EXPECT_EQ(viewmodel.rowCount(), 2);
109  EXPECT_EQ(viewmodel.columnCount(), 2);
110 
111  // remove multilayer
112  model.removeItem(model.rootItem(), {"", 0});
113 
114  EXPECT_EQ(viewmodel.rowCount(), 0);
115  EXPECT_EQ(viewmodel.columnCount(), 0);
116 }
void removeItem(SessionItem *parent, const TagRow &tagrow)
Removes given row from parent.
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(), ModelView::SessionModel::removeItem(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function:

◆ TEST_F() [4/5]

TEST_F ( PropertyViewModelTest  ,
propertyItem   
)

Definition at line 58 of file propertyviewmodel.test.cpp.

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  PropertyViewModel 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 }
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() [5/5]

TEST_F ( PropertyViewModelTest  ,
vectorItem   
)

VectorItem in a model.

Definition at line 80 of file propertyviewmodel.test.cpp.

81 {
82  SessionModel model;
83  auto parent = model.insertItem<VectorItem>();
84 
85  PropertyViewModel 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 }
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: