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

Implements class CLASS? More...

Include dependency graph for propertyflatviewmodel.test.cpp:

Go to the source code of this file.

Classes

class  PropertyFlatViewModelTest
 Tests for PropertyFlatViewModel class. More...
 

Functions

 TEST_F (PropertyFlatViewModelTest, baseItem)
 
 TEST_F (PropertyFlatViewModelTest, initialState)
 
 TEST_F (PropertyFlatViewModelTest, particleItem)
 ParticleItem in a model. More...
 
 TEST_F (PropertyFlatViewModelTest, propertyItem)
 
 TEST_F (PropertyFlatViewModelTest, 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 propertyflatviewmodel.test.cpp.

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( PropertyFlatViewModelTest  ,
baseItem   
)

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

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 }
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 ( PropertyFlatViewModelTest  ,
initialState   
)

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

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 }
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 ( PropertyFlatViewModelTest  ,
particleItem   
)

ParticleItem in a model.

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

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
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
const ModelView::model_type SphereItemType
Definition: toyitems.h:36
const ModelView::model_type CylinderItemType
Definition: toyitems.h:35

References ModelView::ViewModelBase::columnCount(), ToyItems::Constants::CylinderItemType, ModelView::SessionModel::insertItem(), ToyItems::ParticleItem::P_SHAPES, ModelView::ViewModelBase::rowCount(), ModelView::ViewModel::setRootSessionItem(), and ToyItems::Constants::SphereItemType.

Here is the call graph for this function:

◆ TEST_F() [4/5]

TEST_F ( PropertyFlatViewModelTest  ,
propertyItem   
)

Definition at line 58 of file propertyflatviewmodel.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  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 }
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 ( PropertyFlatViewModelTest  ,
vectorItem   
)

VectorItem in a model.

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

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