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

Implements class CLASS? More...

Include dependency graph for TestToyLayerItem.cpp:

Go to the source code of this file.

Classes

class  ToyLayerItemTest
 Tests for toy Layer in the context of model and view model. More...
 

Functions

 TEST_F (ToyLayerItemTest, displayNameInMultiLayer)
 Validates display name. More...
 
 TEST_F (ToyLayerItemTest, initialState)
 Initial state. More...
 
 TEST_F (ToyLayerItemTest, inModel)
 Toy layer as prodused by toy SampleModel. More...
 
 TEST_F (ToyLayerItemTest, inViewModel)
 
 TEST_F (ToyLayerItemTest, layerItemDataChanged)
 Constructing ViewModel from a Layer with one "thickness" property. More...
 
 TEST_F (ToyLayerItemTest, setRootItemContext)
 LayerItem as rootItem. 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 TestToyLayerItem.cpp.

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( ToyLayerItemTest  ,
displayNameInMultiLayer   
)

Validates display name.

Definition at line 126 of file TestToyLayerItem.cpp.

127 {
128  ToyItems::SampleModel model;
129  auto multiLayer = model.insertItem<ToyItems::MultiLayerItem>();
130 
131  auto layer0 = model.insertItem<ToyItems::LayerItem>(multiLayer);
132  EXPECT_EQ(layer0->displayName(), "Layer");
133 
134  auto layer1 = model.insertItem<ToyItems::LayerItem>(multiLayer);
135  EXPECT_EQ(layer0->displayName(), "Layer0");
136  EXPECT_EQ(layer1->displayName(), "Layer1");
137 }
std::string displayName() const override
Returns display name.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
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::CompoundItem::displayName(), and ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( ToyLayerItemTest  ,
initialState   
)

Initial state.

Definition at line 38 of file TestToyLayerItem.cpp.

39 {
44 }
static const std::string T_PARTICLES
Definition: toyitems.h:56
static const std::string P_COLOR
Definition: toyitems.h:55
static const std::string P_THICKNESS
Definition: toyitems.h:54
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(), ToyItems::LayerItem::P_COLOR, ToyItems::LayerItem::P_THICKNESS, and ToyItems::LayerItem::T_PARTICLES.

Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( ToyLayerItemTest  ,
inModel   
)

Toy layer as prodused by toy SampleModel.

Definition at line 48 of file TestToyLayerItem.cpp.

49 {
51  auto layer = model.insertItem<ToyItems::LayerItem>();
52 
53  EXPECT_FALSE(layer->data<QVariant>().isValid());
54  EXPECT_EQ(layer->displayName(), ToyItems::Constants::LayerItemType);
55 }
const ModelView::model_type LayerItemType
Definition: toyitems.h:31

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

Here is the call graph for this function:

◆ TEST_F() [4/6]

TEST_F ( ToyLayerItemTest  ,
inViewModel   
)

Definition at line 57 of file TestToyLayerItem.cpp.

58 {
60  auto layerItem = model.insertItem<ToyItems::LayerItem>();
61 
62  // constructing viewModel from sample model
63  DefaultViewModel viewModel(&model);
64 
65  // root item should have one child, item looking at our layerItem
66  EXPECT_EQ(viewModel.rowCount(), 1);
67  EXPECT_EQ(viewModel.columnCount(), 2);
68 
69  // accessing to viewItem representing layerItem
70  QModelIndex layerIndex = viewModel.index(0, 0);
71  auto viewItem = dynamic_cast<ViewLabelItem*>(viewModel.itemFromIndex(layerIndex));
72  EXPECT_TRUE(viewItem != nullptr);
73  EXPECT_EQ(viewItem->item(), layerItem);
74 
75  // it has two rows and two columns, corresponding to our "thickness" and "color" properties
76  EXPECT_EQ(viewModel.rowCount(layerIndex), 2);
77  EXPECT_EQ(viewModel.columnCount(layerIndex), 2);
78 
79  // accessing to views representing label and value of thickness property
80  QModelIndex thicknessLabelIndex = viewModel.index(0, 0, layerIndex);
81  auto thicknessLabelView =
82  dynamic_cast<ViewLabelItem*>(viewModel.itemFromIndex(thicknessLabelIndex));
83  EXPECT_TRUE(thicknessLabelView != nullptr);
84 
85  QModelIndex thicknessValueIndex = viewModel.index(0, 1, layerIndex);
86  auto thicknessValueView =
87  dynamic_cast<ViewDataItem*>(viewModel.itemFromIndex(thicknessValueIndex));
88  EXPECT_TRUE(thicknessValueView != nullptr);
89 
90  // internally, views for label and data should point to single SessionItem corresponding to
91  // thickness property
92  EXPECT_EQ(thicknessLabelView->item(), layerItem->getItem(ToyItems::LayerItem::P_THICKNESS));
93  EXPECT_EQ(thicknessValueView->item(), layerItem->getItem(ToyItems::LayerItem::P_THICKNESS));
94 }
View model to show content of SessionModel in Qt widgets: two column tree with label/data.
Represents data role of SessionItem in any cell of Qt's trees and tables.
Represents display name of SessionItem in any cell of Qt's trees and tables.

References ModelView::SessionModel::insertItem(), and ToyItems::LayerItem::P_THICKNESS.

Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( ToyLayerItemTest  ,
layerItemDataChanged   
)

Constructing ViewModel from a Layer with one "thickness" property.

Change thickness property in SessionItem, control dataChanged signals from ViewModel.

Definition at line 99 of file TestToyLayerItem.cpp.

100 {
101  ToyItems::SampleModel model;
102  auto layerItem = model.insertItem<ToyItems::LayerItem>();
103 
104  // constructing viewModel from sample model
105  DefaultViewModel viewModel(&model);
106 
107  QModelIndex layerIndex = viewModel.index(0, 0);
108  QModelIndex thicknessIndex = viewModel.index(0, 1, layerIndex);
109 
110  QSignalSpy spyDataChanged(&viewModel, &DefaultViewModel::dataChanged);
111 
112  layerItem->setProperty(ToyItems::LayerItem::P_THICKNESS, 50.0);
113  EXPECT_EQ(spyDataChanged.count(), 1);
114 
115  // dataChanged should report thicknessIndex and two roles
116  QList<QVariant> arguments = spyDataChanged.takeFirst();
117  EXPECT_EQ(arguments.size(), 3); // QModelIndex left, QModelIndex right, QVector<int> roles
118  EXPECT_EQ(arguments.at(0).value<QModelIndex>(), thicknessIndex);
119  EXPECT_EQ(arguments.at(1).value<QModelIndex>(), thicknessIndex);
120  QVector<int> expectedRoles = {Qt::DisplayRole, Qt::EditRole};
121  EXPECT_EQ(arguments.at(2).value<QVector<int>>(), expectedRoles);
122 }

References ModelView::SessionModel::insertItem(), and ToyItems::LayerItem::P_THICKNESS.

Here is the call graph for this function:

◆ TEST_F() [6/6]

TEST_F ( ToyLayerItemTest  ,
setRootItemContext   
)

LayerItem as rootItem.

Definition at line 141 of file TestToyLayerItem.cpp.

142 {
143  ToyItems::SampleModel model;
144  auto layer = model.insertItem<ToyItems::LayerItem>();
145  DefaultViewModel viewModel(&model);
146  viewModel.setRootSessionItem(layer);
147 
148  EXPECT_EQ(viewModel.rowCount(QModelIndex()), 2);
149  EXPECT_EQ(viewModel.columnCount(QModelIndex()), 2);
150 
151  // index of item representing thickness
152  QModelIndex thicknessIndex = viewModel.index(0, 0, QModelIndex());
153  EXPECT_EQ(viewModel.sessionItemFromIndex(thicknessIndex),
154  layer->getItem(ToyItems::LayerItem::P_THICKNESS));
155 }

References ModelView::SessionModel::insertItem(), and ToyItems::LayerItem::P_THICKNESS.

Here is the call graph for this function: