BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
propertiesrowstrategy.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/propertiesrowstrategy.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"
21 #include "test_utils.h"
22 
23 using namespace ModelView;
24 
25 class PropertiesRowStrategyTest : public ::testing::Test {
26 public:
28 };
29 
31 
33 {
34  PropertiesRowStrategy strategy;
35  EXPECT_EQ(strategy.constructRow(nullptr).size(), 0);
36  EXPECT_EQ(strategy.horizontalHeaderLabels(), QStringList());
37 }
38 
39 //! Checks row construction for standard top level item. It shouldn't generate any rows.
40 
42 {
43  SessionItem item("model_type");
44 
45  PropertiesRowStrategy strategy;
46  auto items = strategy.constructRow(&item);
47  EXPECT_EQ(items.size(), 0);
48  EXPECT_EQ(strategy.horizontalHeaderLabels(), QStringList());
49 }
50 
51 //! Checks row construction for property item. It shouldn't generate any rows.
52 
54 {
55  SessionItem item("model_type");
56  item.setData(42.0);
57 
58  PropertiesRowStrategy strategy;
59  auto items = strategy.constructRow(&item);
60  EXPECT_EQ(items.size(), 0);
61  EXPECT_EQ(strategy.horizontalHeaderLabels(), QStringList());
62 }
63 
64 //! Checks row construction for vector item.
65 //! There should be 3 view items looking to x, y, z properties.
66 
67 TEST_F(PropertiesRowStrategyTest, vectorItemCustomLabels)
68 {
69  VectorItem item;
70 
71  EXPECT_EQ(item.property<double>(VectorItem::P_X), 0.0);
72  EXPECT_EQ(item.property<double>(VectorItem::P_Y), 0.0);
73  EXPECT_EQ(item.property<double>(VectorItem::P_Z), 0.0);
74 
75  PropertiesRowStrategy strategy({"a", "b", "c"});
76  auto items = strategy.constructRow(&item);
77 
78  EXPECT_EQ(items.size(), 3);
79  EXPECT_EQ(strategy.horizontalHeaderLabels(), QStringList() << "a"
80  << "b"
81  << "c");
82 
83  // views should look at 3 property items
84  auto view_x = items.at(0).get();
85  EXPECT_EQ(view_x->item(), item.getItem(VectorItem::P_X));
86 
87  auto view_y = items.at(1).get();
88  EXPECT_EQ(view_y->item(), item.getItem(VectorItem::P_Y));
89 
90  auto view_z = items.at(2).get();
91  EXPECT_EQ(view_z->item(), item.getItem(VectorItem::P_Z));
92 }
93 
94 //! Checks row label construction for vector item.
95 
96 TEST_F(PropertiesRowStrategyTest, vectorItemAutoLabels)
97 {
98  VectorItem item;
99 
100  EXPECT_EQ(item.property<double>(VectorItem::P_X), 0.0);
101  EXPECT_EQ(item.property<double>(VectorItem::P_Y), 0.0);
102  EXPECT_EQ(item.property<double>(VectorItem::P_Z), 0.0);
103 
104  QStringList expected = QStringList() << "X"
105  << "Y"
106  << "Z";
107 
108  PropertiesRowStrategy strategy;
109  auto items = strategy.constructRow(&item);
110  EXPECT_EQ(strategy.horizontalHeaderLabels(), expected);
111 }
112 
113 //! Row construction for rootItem with single item inserted. Shouldn't generate any row.
114 
115 TEST_F(PropertiesRowStrategyTest, baseItemInModelContext)
116 {
117  SessionModel model;
118 
119  PropertiesRowStrategy strategy;
120  auto items = strategy.constructRow(model.rootItem());
121  EXPECT_EQ(items.size(), 0);
122 
123  model.insertItem<SessionItem>();
124  items = strategy.constructRow(model.rootItem());
125  EXPECT_EQ(items.size(), 0);
126 }
127 
128 //! Row construction for rootItem with single item inserted. Shouldn't generate any row.
129 
131 {
132  SessionModel model;
133  auto parent = model.insertItem<SessionItem>();
134 
135  parent->registerTag(TagInfo::universalTag("universal_tag"));
136  parent->registerTag(TagInfo::propertyTag("property_tag", Constants::PropertyType));
137 
138  model.insertItem<SessionItem>(parent, "universal_tag");
139  model.insertItem<PropertyItem>(parent, "property_tag");
140 
141  PropertiesRowStrategy strategy;
142  auto items = strategy.constructRow(model.rootItem());
143 
144  // root item doesn't have properties
145  EXPECT_EQ(items.size(), 0);
146 
147  // parent has one registered property.
148  items = strategy.constructRow(parent);
149  EXPECT_EQ(items.size(), 1);
150 }
151 
152 //! Row construction for rootItem when vectorItem is present. Shouldn't generate any row.
153 
154 TEST_F(PropertiesRowStrategyTest, vectorItemInModelContext)
155 {
156  SessionModel model;
157  model.insertItem<VectorItem>();
158 
159  PropertiesRowStrategy strategy;
160  auto items = strategy.constructRow(model.rootItem());
161  EXPECT_EQ(items.size(), 0);
162 }
Constructs row of QStandardItem's for given SessionItem.
QStringList horizontalHeaderLabels() const override
std::vector< std::unique_ptr< ViewItem > > constructRow(SessionItem *item) override
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Definition: sessionitem.h:141
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
SessionItem * rootItem() const
Returns root item of the model.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
Definition: taginfo.cpp:34
static TagInfo propertyTag(std::string name, std::string model_type)
Constructs tag intended for single property.
Definition: taginfo.cpp:40
Vector item with three x,y,z property items.
Definition: vectoritem.h:24
static const std::string P_X
Definition: vectoritem.h:26
static const std::string P_Z
Definition: vectoritem.h:28
static const std::string P_Y
Definition: vectoritem.h:27
Defines class CLASS?
const model_type PropertyType
Definition: mvvm_types.h:59
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(PropertiesRowStrategyTest, initialState)
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?