BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
TestToyMultiLayerItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/tests/testviewmodel/TestToyMultiLayerItem.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "google_test.h"
16 #include "mvvm/model/itemutils.h"
20 #include "toyitems.h"
21 #include "toymodel.h"
22 #include <QSignalSpy>
23 
24 using namespace ModelView;
25 
26 //! Tests of toy MultiLayer in the context of model and viewmodel.
27 
28 class ToyMultilayerItemTest : public ::testing::Test {
29 public:
31 };
32 
34 
35 //! Initial state.
36 
38 {
41 }
42 
43 //! Toy multilayer in a SampleModel.
44 
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 }
53 
54 //! Constructing ViewModel from a MultiLayer.
55 //! Checking that view items point co correct SessionItem.
56 
57 TEST_F(ToyMultilayerItemTest, multiLayerView)
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 }
79 
80 //! Find ViewItem corresponding to given MultiLayer item.
81 
82 TEST_F(ToyMultilayerItemTest, findMultiLayerView)
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 }
93 
94 //! How ViewLabelItem sees MultiLayer
95 
96 TEST_F(ToyMultilayerItemTest, viewItemsForMultiLayer)
97 {
99 
100  auto multiLayer = model.insertItem<ToyItems::MultiLayerItem>();
101 
102  ViewLabelItem labelItem(multiLayer);
103  EXPECT_EQ(labelItem.data(Qt::DisplayRole).toString().toStdString(),
105 }
TEST_F(ToyMultilayerItemTest, initialState)
Initial state.
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 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
Represents multilayer with collection of layers.
Definition: toyitems.h:44
static const std::string T_LAYERS
Definition: toyitems.h:46
Tests of toy MultiLayer in the context of model and viewmodel.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
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
materialitems.h Collection of materials to populate MaterialModel.
const ModelView::model_type MultiLayerItemType
Definition: toyitems.h:30
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?