BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
labeldatarowstrategy.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/testviewmodel/labeldatarowstrategy.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"
16 #include "mvvm/model/sessionitem.h"
19 #include "test_utils.h"
20 
21 namespace {
22 const int expected_column_count = 2;
23 const QStringList expected_labels = QStringList() << "Name"
24  << "Value";
25 } // namespace
26 
27 using namespace ModelView;
28 
29 class LabelDataRowStrategyTest : public ::testing::Test {
30 public:
32 };
33 
35 
37 {
38  LabelDataRowStrategy constructor;
39  EXPECT_EQ(constructor.constructRow(nullptr).size(), 0);
40  EXPECT_EQ(constructor.horizontalHeaderLabels(), expected_labels);
41 }
42 
43 //! Checks row construction for standard top level item, like Level, MultiLayer etc.
44 
46 {
47  SessionItem item("model_type");
48 
49  LabelDataRowStrategy constructor;
50  auto items = constructor.constructRow(&item);
51  EXPECT_EQ(items.size(), expected_column_count); // label and empty items
52  EXPECT_EQ(constructor.horizontalHeaderLabels(), expected_labels);
53 
54  // checking that it is label and data
55  auto labelItem = dynamic_cast<ViewLabelItem*>(items.at(0).get());
56  auto dataItem = dynamic_cast<ViewDataItem*>(items.at(1).get());
57  ASSERT_TRUE(labelItem != nullptr);
58  EXPECT_EQ(labelItem->item(), &item);
59  ASSERT_TRUE(dataItem != nullptr);
60  EXPECT_EQ(dataItem->item(), &item);
61 }
62 
63 //! Checks row construction for property item.
64 
66 {
67  SessionItem item("model_type");
68  item.setData(42.0);
69 
70  LabelDataRowStrategy constructor;
71  auto items = constructor.constructRow(&item);
72  EXPECT_EQ(items.size(), expected_column_count);
73  EXPECT_EQ(constructor.horizontalHeaderLabels(), expected_labels);
74 
75  // checking that it is label and data
76  auto labelItem = dynamic_cast<ViewLabelItem*>(items.at(0).get());
77  auto dataItem = dynamic_cast<ViewDataItem*>(items.at(1).get());
78  ASSERT_TRUE(labelItem != nullptr);
79  EXPECT_EQ(labelItem->item(), &item);
80  ASSERT_TRUE(dataItem != nullptr);
81  EXPECT_EQ(dataItem->item(), &item);
82 }
Constructs row of QStandardItem's for given SessionItem.
std::vector< std::unique_ptr< ViewItem > > constructRow(SessionItem *) override
QStringList horizontalHeaderLabels() const override
Example: For LayerItem two items will be generated: ViewLabelItem and ViewEmptyItem,...
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Definition: sessionitem.h:141
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.
Defines class CLASS?
Defines class CLASS?
TEST_F(LabelDataRowStrategyTest, initialState)
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?