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

Implements class CLASS? More...

Include dependency graph for TestToyMultiLayerItem.cpp:

Go to the source code of this file.

Classes

class  ToyMultilayerItemTest
 Tests of toy MultiLayer in the context of model and viewmodel. More...
 

Functions

 TEST_F (ToyMultilayerItemTest, findMultiLayerView)
 Find ViewItem corresponding to given MultiLayer item. More...
 
 TEST_F (ToyMultilayerItemTest, initialState)
 Initial state. More...
 
 TEST_F (ToyMultilayerItemTest, multiLayer)
 Toy multilayer in a SampleModel. More...
 
 TEST_F (ToyMultilayerItemTest, multiLayerView)
 Constructing ViewModel from a MultiLayer. More...
 
 TEST_F (ToyMultilayerItemTest, viewItemsForMultiLayer)
 How ViewLabelItem sees MultiLayer. 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 TestToyMultiLayerItem.cpp.

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( ToyMultilayerItemTest  ,
findMultiLayerView   
)

Find ViewItem corresponding to given MultiLayer item.

Definition at line 82 of file TestToyMultiLayerItem.cpp.

83 {
85  auto multiLayerItem = model.insertItem<ToyItems::MultiLayerItem>();
86 
87  DefaultViewModel viewModel(&model);
88 
89  auto views = viewModel.findViews(multiLayerItem);
90  EXPECT_EQ(views.size(), 2);
91  EXPECT_EQ(views.at(0)->item(), multiLayerItem);
92 }
View model to show content of SessionModel in Qt widgets: two column tree with label/data.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
Represents multilayer with collection of layers.
Definition: toyitems.h:44

References ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [2/5]

TEST_F ( ToyMultilayerItemTest  ,
initialState   
)

Initial state.

Definition at line 37 of file TestToyMultiLayerItem.cpp.

38 {
41 }
static const std::string T_LAYERS
Definition: toyitems.h:46
MVVM_MODEL_EXPORT bool IsSinglePropertyTag(const SessionItem &item, const std::string &tag)
Returns true if given item has registered tag, and it belongs to single property.
Definition: itemutils.cpp:91

References ModelView::Utils::IsSinglePropertyTag(), and ToyItems::MultiLayerItem::T_LAYERS.

Here is the call graph for this function:

◆ TEST_F() [3/5]

TEST_F ( ToyMultilayerItemTest  ,
multiLayer   
)

Toy multilayer in a SampleModel.

Definition at line 45 of file TestToyMultiLayerItem.cpp.

46 {
48  auto multiLayer = model.insertItem<ToyItems::MultiLayerItem>();
49 
50  EXPECT_FALSE(multiLayer->data<QVariant>().isValid());
51  EXPECT_EQ(multiLayer->displayName(), ToyItems::Constants::MultiLayerItemType);
52 }
const ModelView::model_type MultiLayerItemType
Definition: toyitems.h:30

References ModelView::SessionModel::insertItem(), and ToyItems::Constants::MultiLayerItemType.

Here is the call graph for this function:

◆ TEST_F() [4/5]

TEST_F ( ToyMultilayerItemTest  ,
multiLayerView   
)

Constructing ViewModel from a MultiLayer.

Checking that view items point co correct SessionItem.

Definition at line 57 of file TestToyMultiLayerItem.cpp.

58 {
60  auto multiLayerItem = model.insertItem<ToyItems::MultiLayerItem>();
61 
62  DefaultViewModel viewModel(&model);
63  EXPECT_EQ(viewModel.rowCount(), 1);
64  EXPECT_EQ(viewModel.columnCount(), 2);
65 
66  // accessing first child under the root item
67  QModelIndex mlIndex = viewModel.index(0, 0);
68 
69  // it should be ViewLabelItem looking at our MultiLayer item
70  auto viewItem = dynamic_cast<ViewLabelItem*>(viewModel.itemFromIndex(mlIndex));
71  EXPECT_TRUE(viewItem != nullptr);
72  EXPECT_EQ(viewItem->item(), multiLayerItem);
73 
74  // adding layer
75  model.insertItem<ToyItems::LayerItem>(multiLayerItem);
76  EXPECT_EQ(viewModel.rowCount(mlIndex), 1);
77  EXPECT_EQ(viewModel.columnCount(mlIndex), 2);
78 }
Represents display name of SessionItem in any cell of Qt's trees and tables.
Represents a layer, with thickness and color, and possibly populated with particles.
Definition: toyitems.h:52

References ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [5/5]

TEST_F ( ToyMultilayerItemTest  ,
viewItemsForMultiLayer   
)

How ViewLabelItem sees MultiLayer.

Definition at line 96 of file TestToyMultiLayerItem.cpp.

97 {
99 
100  auto multiLayer = model.insertItem<ToyItems::MultiLayerItem>();
101 
102  ViewLabelItem labelItem(multiLayer);
103  EXPECT_EQ(labelItem.data(Qt::DisplayRole).toString().toStdString(),
105 }

References ModelView::SessionModel::insertItem(), and ToyItems::Constants::MultiLayerItemType.

Here is the call graph for this function: