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

Implements class CLASS? More...

Include dependency graph for propertiesrowstrategy.test.cpp:

Go to the source code of this file.

Classes

class  PropertiesRowStrategyTest
 

Functions

 TEST_F (PropertiesRowStrategyTest, baseItemInModelContext)
 Row construction for rootItem with single item inserted. Shouldn't generate any row. More...
 
 TEST_F (PropertiesRowStrategyTest, initialState)
 
 TEST_F (PropertiesRowStrategyTest, propertyItem)
 Checks row construction for property item. It shouldn't generate any rows. More...
 
 TEST_F (PropertiesRowStrategyTest, propertyItemTree)
 Row construction for rootItem with single item inserted. Shouldn't generate any row. More...
 
 TEST_F (PropertiesRowStrategyTest, topLevelItem)
 Checks row construction for standard top level item. It shouldn't generate any rows. More...
 
 TEST_F (PropertiesRowStrategyTest, vectorItemAutoLabels)
 Checks row label construction for vector item. More...
 
 TEST_F (PropertiesRowStrategyTest, vectorItemCustomLabels)
 Checks row construction for vector item. More...
 
 TEST_F (PropertiesRowStrategyTest, vectorItemInModelContext)
 Row construction for rootItem when vectorItem is present. Shouldn't generate any row. 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 propertiesrowstrategy.test.cpp.

Function Documentation

◆ TEST_F() [1/8]

TEST_F ( PropertiesRowStrategyTest  ,
baseItemInModelContext   
)

Row construction for rootItem with single item inserted. Shouldn't generate any row.

Definition at line 115 of file propertiesrowstrategy.test.cpp.

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 }
Constructs row of QStandardItem's for given SessionItem.
std::vector< std::unique_ptr< ViewItem > > constructRow(SessionItem *item) override
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
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

References ModelView::PropertiesRowStrategy::constructRow(), ModelView::SessionModel::insertItem(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function:

◆ TEST_F() [2/8]

TEST_F ( PropertiesRowStrategyTest  ,
initialState   
)

Definition at line 32 of file propertiesrowstrategy.test.cpp.

33 {
34  PropertiesRowStrategy strategy;
35  EXPECT_EQ(strategy.constructRow(nullptr).size(), 0);
36  EXPECT_EQ(strategy.horizontalHeaderLabels(), QStringList());
37 }
QStringList horizontalHeaderLabels() const override

References ModelView::PropertiesRowStrategy::constructRow(), and ModelView::PropertiesRowStrategy::horizontalHeaderLabels().

Here is the call graph for this function:

◆ TEST_F() [3/8]

TEST_F ( PropertiesRowStrategyTest  ,
propertyItem   
)

Checks row construction for property item. It shouldn't generate any rows.

Definition at line 53 of file propertiesrowstrategy.test.cpp.

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 }

References ModelView::PropertiesRowStrategy::constructRow(), ModelView::PropertiesRowStrategy::horizontalHeaderLabels(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [4/8]

TEST_F ( PropertiesRowStrategyTest  ,
propertyItemTree   
)

Row construction for rootItem with single item inserted. Shouldn't generate any row.

Definition at line 130 of file propertiesrowstrategy.test.cpp.

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 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
const model_type PropertyType
Definition: mvvm_types.h:59

References ModelView::PropertiesRowStrategy::constructRow(), ModelView::SessionModel::insertItem(), ModelView::TagInfo::propertyTag(), ModelView::Constants::PropertyType, ModelView::SessionItem::registerTag(), ModelView::SessionModel::rootItem(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [5/8]

TEST_F ( PropertiesRowStrategyTest  ,
topLevelItem   
)

Checks row construction for standard top level item. It shouldn't generate any rows.

Definition at line 41 of file propertiesrowstrategy.test.cpp.

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 }

References ModelView::PropertiesRowStrategy::constructRow(), and ModelView::PropertiesRowStrategy::horizontalHeaderLabels().

Here is the call graph for this function:

◆ TEST_F() [6/8]

TEST_F ( PropertiesRowStrategyTest  ,
vectorItemAutoLabels   
)

Checks row label construction for vector item.

Definition at line 96 of file propertiesrowstrategy.test.cpp.

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 }
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
Vector item with three x,y,z property items.
Definition: vectoritem.h:24
static const QString P_Z
Definition: VectorItem.h:26
static const QString P_Y
Definition: VectorItem.h:25
static const QString P_X
Definition: VectorItem.h:24

References ModelView::PropertiesRowStrategy::constructRow(), ModelView::PropertiesRowStrategy::horizontalHeaderLabels(), ModelView::VectorItem::P_X, ModelView::VectorItem::P_Y, ModelView::VectorItem::P_Z, and ModelView::SessionItem::property().

Here is the call graph for this function:

◆ TEST_F() [7/8]

TEST_F ( PropertiesRowStrategyTest  ,
vectorItemCustomLabels   
)

Checks row construction for vector item.

There should be 3 view items looking to x, y, z properties.

Definition at line 67 of file propertiesrowstrategy.test.cpp.

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 }
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.

References ModelView::PropertiesRowStrategy::constructRow(), ModelView::SessionItem::getItem(), ModelView::VectorItem::P_X, ModelView::VectorItem::P_Y, ModelView::VectorItem::P_Z, and ModelView::SessionItem::property().

Here is the call graph for this function:

◆ TEST_F() [8/8]

TEST_F ( PropertiesRowStrategyTest  ,
vectorItemInModelContext   
)

Row construction for rootItem when vectorItem is present. Shouldn't generate any row.

Definition at line 154 of file propertiesrowstrategy.test.cpp.

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 }

References ModelView::PropertiesRowStrategy::constructRow(), ModelView::SessionModel::insertItem(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function: