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

Implements class CLASS? More...

Include dependency graph for viewmodeldelegate.test.cpp:

Go to the source code of this file.

Classes

struct  ViewModelDelegateTest::TestData
 
class  ViewModelDelegateTest
 Tests of ViewModelDelegate class. More...
 

Functions

 TEST_F (ViewModelDelegateTest, createEditor)
 
 TEST_F (ViewModelDelegateTest, widgetMapper)
 Check that ViewModelDelegate can work with widget mapper. 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 viewmodeldelegate.test.cpp.

Function Documentation

◆ TEST_F() [1/2]

TEST_F ( ViewModelDelegateTest  ,
createEditor   
)

Definition at line 65 of file viewmodeldelegate.test.cpp.

66 {
67  TestData test_data;
68  test_data.model.insertItem<VectorItem>();
69 
70  auto parent_index = test_data.view_model.index(0, 0);
71  auto x_value_index = test_data.view_model.index(0, 1, parent_index);
72 
73  EXPECT_TRUE(test_data.create_editor(x_value_index).get() != nullptr);
74 }
Vector item with three x,y,z property items.
Definition: vectoritem.h:24

◆ TEST_F() [2/2]

TEST_F ( ViewModelDelegateTest  ,
widgetMapper   
)

Check that ViewModelDelegate can work with widget mapper.

Definition at line 78 of file viewmodeldelegate.test.cpp.

79 {
80  TestData test_data;
81  auto vector_item = test_data.model.insertItem<VectorItem>();
82  auto x_item = vector_item->getItem(VectorItem::P_X);
83 
84  // accessing to index list (index of label field and index of data field)
85  // of PropertyItem corresponding to x-coordinate.
86  auto x_value_index = test_data.view_model.indexOfSessionItem(x_item).at(1);
87  auto editor = test_data.create_editor(x_value_index);
88 
89  test_data.map_to_index(editor.get(), x_value_index);
90 
91  editor->setData(43.0);
92  editor->dataChanged(editor->data());
93  EXPECT_EQ(x_item->data<double>(), 43.0);
94 }
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Definition: sessionitem.h:141
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Definition: sessionitem.h:148
static const QString P_X
Definition: VectorItem.h:24

References ModelView::SessionItem::data(), ModelView::SessionItem::getItem(), ModelView::VectorItem::P_X, and ModelView::SessionItem::setData().

Here is the call graph for this function: