BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
propertyflatview.test.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/testview/propertyflatview.test.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"
19 #include "toyitems.h"
20 #include "toymodel.h"
21 #include <QGridLayout>
22 
23 using namespace ModelView;
24 
25 //! Tests of PropertyFlatView class.
26 
27 class PropertyFlatViewTest : public ::testing::Test {
28 public:
30 
31  //! Returns vector representing enable status of widgets in layout.
32 
33  std::vector<int> enable_status(PropertyFlatView& flat_view)
34  {
35  std::vector<int> result;
36  auto layout = flat_view.findChild<QGridLayout*>();
37  for (int row = 0; row < layout->rowCount(); ++row)
38  for (int col = 0; col < layout->columnCount(); ++col)
39  result.push_back(
40  static_cast<int>(layout->itemAtPosition(row, col)->widget()->isEnabled()));
41  return result;
42  }
43 };
44 
46 
47 TEST_F(PropertyFlatViewTest, layoutForVector)
48 {
49  SessionModel model;
50  auto vector_item = model.insertItem<VectorItem>();
51 
52  PropertyFlatView flat_view;
53  flat_view.setItem(vector_item);
54 
55  auto layout = flat_view.findChild<QGridLayout*>();
56  ASSERT_TRUE(layout != nullptr);
57 
58  EXPECT_EQ(layout->rowCount(), 3);
59  EXPECT_EQ(layout->columnCount(), 2);
60  std::vector<int> expected_enabled = {1, 1, 1, 1, 1, 1};
61 }
62 
63 TEST_F(PropertyFlatViewTest, appearanceForItem)
64 {
65  SessionModel model;
66  auto vector_item = model.insertItem<VectorItem>();
67  auto x_item = vector_item->getItem(VectorItem::P_X);
68 
69  x_item->setEnabled(false);
70 
71  PropertyFlatView flat_view;
72  flat_view.setItem(vector_item);
73 
74  auto layout = flat_view.findChild<QGridLayout*>();
75  ASSERT_TRUE(layout != nullptr);
76 
77  EXPECT_EQ(layout->rowCount(), 3);
78  EXPECT_EQ(layout->columnCount(), 2);
79  std::vector<int> expected_enabled = {0, 0, 1, 1, 1, 1};
80  EXPECT_EQ(enable_status(flat_view), expected_enabled);
81 
82  // enabling x item
83  x_item->setEnabled(true);
84  expected_enabled = {1, 1, 1, 1, 1, 1};
85  EXPECT_EQ(enable_status(flat_view), expected_enabled);
86 }
Widget holding grid layout with editors and intended for displaying all properties of given SessionIt...
void setItem(SessionItem *item)
SessionItem * setEnabled(bool value)
Sets enabled flag to given value (fluent interface).
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
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
Vector item with three x,y,z property items.
Definition: vectoritem.h:24
static const std::string P_X
Definition: vectoritem.h:26
Tests of PropertyFlatView class.
std::vector< int > enable_status(PropertyFlatView &flat_view)
Returns vector representing enable status of widgets in layout.
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(PropertyFlatViewTest, layoutForVector)
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?