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

Implements class CLASS? More...

Include dependency graph for standardviewitems.test.cpp:

Go to the source code of this file.

Classes

class  StandardViewItemsTest
 

Functions

 TEST_F (StandardViewItemsTest, ViewDataItem_dataForColor)
 ViewDataItem::data method for QColor. More...
 
 TEST_F (StandardViewItemsTest, ViewDataItem_dataForDouble)
 ViewDataItem::data method for double values. More...
 
 TEST_F (StandardViewItemsTest, ViewDataItem_flags)
 Testing ViewLabelItem::flags. More...
 
 TEST_F (StandardViewItemsTest, ViewDataItem_initialState)
 
 TEST_F (StandardViewItemsTest, ViewDataItem_invalidTheValidData)
 Behavior of ViewDataItem with SessionItem which initially contains invalid data. More...
 
 TEST_F (StandardViewItemsTest, ViewDataItem_setDataForColor)
 ViewDataItem::setData for QColor. More...
 
 TEST_F (StandardViewItemsTest, ViewDataItem_setDataForDouble)
 ViewDataItem::setData for double values. More...
 
 TEST_F (StandardViewItemsTest, ViewDataItem_setSameData)
 ViewDataItem::setData for double values. More...
 
 TEST_F (StandardViewItemsTest, ViewDataItem_toolTipRole)
 Testing tooltip tole. More...
 
 TEST_F (StandardViewItemsTest, ViewLabelItem_data)
 ViewLabelItem::data method Checks that the data method is correctly forwarded to underlying SessionItem. More...
 
 TEST_F (StandardViewItemsTest, ViewLabelItem_flags)
 Testing ViewLabelItem::flags. More...
 
 TEST_F (StandardViewItemsTest, ViewLabelItem_initialState)
 
 TEST_F (StandardViewItemsTest, ViewLabelItem_setData)
 ViewLabelItem::setData Checks that the setData method is correctly forwarded to underlying SessionItem. More...
 
 TEST_F (StandardViewItemsTest, ViewLabelItem_toolTipRole)
 Testing tooltip tole. 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 standardviewitems.test.cpp.

Function Documentation

◆ TEST_F() [1/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_dataForColor   
)

ViewDataItem::data method for QColor.

Checks that the data method is correctly forwarded to underlying SessionItem.

Definition at line 184 of file standardviewitems.test.cpp.

185 {
186  // create SessionItem with data on board
187  SessionItem item;
188  QVariant expected = QVariant::fromValue(QColor(Qt::green));
189  EXPECT_TRUE(item.setData(expected));
190 
191  ViewDataItem viewItem(&item);
192  EXPECT_EQ(viewItem.data(Qt::EditRole), expected);
193  EXPECT_EQ(viewItem.data(Qt::DisplayRole), expected);
194  EXPECT_EQ(viewItem.data(Qt::DecorationRole), expected);
195 }
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.
QVariant DecorationRole(const SessionItem &item)
Returns tooltip for given item.

References ModelView::ViewDataItem::data(), SessionItemUtils::DecorationRole(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [2/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_dataForDouble   
)

ViewDataItem::data method for double values.

Checks that the data method is correctly forwarded to underlying SessionItem.

Definition at line 126 of file standardviewitems.test.cpp.

127 {
128  // create SessionItem with data on board
129  SessionItem item;
130  QVariant expected(42.0);
131  EXPECT_TRUE(item.setData(expected));
132 
133  // initialize viewItem with sessionItem and check the data
134  ViewDataItem viewItem(&item);
135  EXPECT_EQ(viewItem.data(Qt::EditRole), expected);
136  EXPECT_EQ(viewItem.data(Qt::DisplayRole), expected);
137 }

References ModelView::ViewDataItem::data(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [3/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_flags   
)

Testing ViewLabelItem::flags.

Definition at line 225 of file standardviewitems.test.cpp.

226 {
227  SessionItem item;
228  QVariant expected = QVariant::fromValue(std::string("Layer"));
229  EXPECT_TRUE(item.setData(expected, ItemDataRole::DATA));
230 
231  ViewDataItem viewItem(&item);
232  EXPECT_TRUE(viewItem.flags() & Qt::ItemIsEditable);
233 }
const int DATA
main data role
Definition: mvvm_types.h:30

References ModelView::ItemDataRole::DATA, ModelView::ViewDataItem::flags(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [4/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_initialState   
)

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

116 {
117  SessionItem item;
118  ViewDataItem viewItem(&item);
119  EXPECT_EQ(viewItem.item(), &item);
120  EXPECT_EQ(viewItem.item_role(), ItemDataRole::DATA);
121 }

References ModelView::ItemDataRole::DATA, ModelView::ViewItem::item(), and ModelView::ViewItem::item_role().

Here is the call graph for this function:

◆ TEST_F() [5/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_invalidTheValidData   
)

Behavior of ViewDataItem with SessionItem which initially contains invalid data.

It should be possible to set data after.

Definition at line 251 of file standardviewitems.test.cpp.

252 {
253  SessionItem item;
254  ViewDataItem viewItem(&item);
255 
256  // initially data is invalid, and non-editable
257  EXPECT_FALSE(viewItem.flags() & Qt::ItemIsEditable);
258  EXPECT_FALSE(viewItem.data(Qt::EditRole).isValid());
259 
260  // current behavior that setting data is still possible
261  EXPECT_TRUE(viewItem.setData(QVariant::fromValue(42.0), Qt::EditRole));
262 
263  // setting data to original item
264  item.setData(43.0);
265 
266  // data became editable via ViewDataItem
267  EXPECT_TRUE(viewItem.flags() & Qt::ItemIsEditable);
268  EXPECT_EQ(viewItem.data(Qt::EditRole), QVariant::fromValue(43.0));
269 }

References ModelView::ViewDataItem::data(), ModelView::ViewDataItem::flags(), ModelView::ViewItem::setData(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [6/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_setDataForColor   
)

ViewDataItem::setData for QColor.

Checks that the setData method is correctly forwarded to underlying SessionItem.

Definition at line 200 of file standardviewitems.test.cpp.

201 {
202  // create SessionItem with data on board
203  SessionItem item;
204  QVariant expected = QVariant::fromValue(QColor(Qt::green));
205  EXPECT_TRUE(item.setData(expected));
206 
207  // initialize viewItem with sessionItem and set the data
208  ViewDataItem viewItem(&item);
209  QVariant new_data = QVariant::fromValue(QColor(Qt::red));
210  EXPECT_TRUE(viewItem.setData(new_data, Qt::EditRole));
211  EXPECT_EQ(viewItem.data(Qt::DisplayRole), new_data); // new data
212  EXPECT_EQ(viewItem.data(Qt::EditRole), new_data); // new data
213  EXPECT_EQ(viewItem.data(Qt::DecorationRole), new_data); // new data
214 
215  // SessionItem itself should have new data
216  EXPECT_EQ(item.data<QVariant>(), new_data); // new data
217 
218  // it is not allowed to set another type of data to ViewDataItem
219  QVariant not_allowed_value("Layer");
220  EXPECT_THROW(viewItem.setData(not_allowed_value, Qt::EditRole), std::runtime_error);
221 }
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Definition: sessionitem.h:148

References ModelView::ViewDataItem::data(), ModelView::SessionItem::data(), SessionItemUtils::DecorationRole(), ModelView::ViewItem::setData(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [7/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_setDataForDouble   
)

ViewDataItem::setData for double values.

Checks that the setData method is correctly forwarded to underlying SessionItem.

Definition at line 142 of file standardviewitems.test.cpp.

143 {
144  // create SessionItem with data on board
145  SessionItem item;
146  QVariant expected(42.0);
147  EXPECT_TRUE(item.setData(expected));
148 
149  // initialize viewItem with sessionItem and set the data
150  ViewDataItem viewItem(&item);
151  QVariant new_data(43.0);
152  EXPECT_TRUE(viewItem.setData(new_data, Qt::EditRole));
153  EXPECT_EQ(viewItem.data(Qt::DisplayRole), new_data); // new data
154  EXPECT_EQ(viewItem.data(Qt::EditRole), new_data); // new data
155 
156  // SessionItem itself should have new data
157  EXPECT_EQ(item.data<QVariant>(), new_data); // new data
158 
159  // it is not allowed to set another type of data to ViewDataItem
160  QVariant not_allowed_value("Layer");
161  EXPECT_THROW(viewItem.setData(not_allowed_value, Qt::EditRole), std::runtime_error);
162 }

References ModelView::ViewDataItem::data(), ModelView::SessionItem::data(), ModelView::ViewItem::setData(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [8/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_setSameData   
)

ViewDataItem::setData for double values.

Checks that setting of same data returns false.

Definition at line 167 of file standardviewitems.test.cpp.

168 {
169  // create SessionItem with data on board
170  SessionItem item;
171  QVariant expected(42.0);
172  EXPECT_TRUE(item.setData(expected));
173 
174  // initialize viewItem with sessionItem and set the data
175  ViewDataItem viewItem(&item);
176  QVariant new_data(42.0);
177  EXPECT_FALSE(viewItem.setData(new_data, Qt::EditRole));
178  EXPECT_EQ(viewItem.data(Qt::EditRole), new_data); // new data
179 }

References ModelView::ViewDataItem::data(), ModelView::ViewItem::setData(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [9/14]

TEST_F ( StandardViewItemsTest  ,
ViewDataItem_toolTipRole   
)

Testing tooltip tole.

Definition at line 237 of file standardviewitems.test.cpp.

238 {
239  SessionItem item;
240 
241  ViewDataItem viewItem(&item);
242  EXPECT_FALSE(viewItem.data(Qt::ToolTipRole).isValid());
243 
244  item.setToolTip("abc");
245  EXPECT_EQ(viewItem.data(Qt::ToolTipRole).toString(), QString("abc"));
246 }
SessionItem * setToolTip(const std::string &tooltip)
Sets item tooltip (fluent interface).
QVariant ToolTipRole(const SessionItem &item, int ncol=0)
Returns tooltip for given item.

References ModelView::ViewDataItem::data(), ModelView::SessionItem::setToolTip(), and SessionItemUtils::ToolTipRole().

Here is the call graph for this function:

◆ TEST_F() [10/14]

TEST_F ( StandardViewItemsTest  ,
ViewLabelItem_data   
)

ViewLabelItem::data method Checks that the data method is correctly forwarded to underlying SessionItem.

Definition at line 46 of file standardviewitems.test.cpp.

47 {
48  // create SessionItem with data on board
49  SessionItem item;
50  const std::string expected("Layer");
51  EXPECT_TRUE(item.setData(expected, ItemDataRole::DISPLAY));
52 
53  // initialize viewItem with sessionItem and check the data
54  ViewLabelItem viewItem(&item);
55  EXPECT_EQ(Utils::toCustomVariant(viewItem.data(Qt::EditRole)), QVariant::fromValue(expected));
56  EXPECT_EQ(Utils::toCustomVariant(viewItem.data(Qt::DisplayRole)),
57  QVariant::fromValue(expected));
58 }
Represents display name of SessionItem in any cell of Qt's trees and tables.
const int DISPLAY
display name
Definition: mvvm_types.h:31
MVVM_MODEL_EXPORT Variant toCustomVariant(const Variant &standard)
Converts Qt variant to custom variant on board of SessionItem.

References ModelView::ViewLabelItem::data(), ModelView::ItemDataRole::DISPLAY, ModelView::SessionItem::setData(), and ModelView::Utils::toCustomVariant().

Here is the call graph for this function:

◆ TEST_F() [11/14]

TEST_F ( StandardViewItemsTest  ,
ViewLabelItem_flags   
)

Testing ViewLabelItem::flags.

Definition at line 88 of file standardviewitems.test.cpp.

89 {
90  SessionItem item;
91  const std::string expected("Layer");
92  EXPECT_TRUE(item.setData(expected, ItemDataRole::DISPLAY));
93 
94  ViewLabelItem viewItem(&item);
95  EXPECT_FALSE(viewItem.flags() & Qt::ItemIsEditable);
96 }

References ModelView::ItemDataRole::DISPLAY, ModelView::ViewItem::flags(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [12/14]

TEST_F ( StandardViewItemsTest  ,
ViewLabelItem_initialState   
)

Definition at line 35 of file standardviewitems.test.cpp.

36 {
37  SessionItem item;
38  ViewLabelItem viewItem(&item);
39  EXPECT_EQ(viewItem.item(), &item);
40  EXPECT_EQ(viewItem.item_role(), ItemDataRole::DISPLAY);
41 }

References ModelView::ItemDataRole::DISPLAY, ModelView::ViewItem::item(), and ModelView::ViewItem::item_role().

Here is the call graph for this function:

◆ TEST_F() [13/14]

TEST_F ( StandardViewItemsTest  ,
ViewLabelItem_setData   
)

ViewLabelItem::setData Checks that the setData method is correctly forwarded to underlying SessionItem.

Definition at line 63 of file standardviewitems.test.cpp.

64 {
65  // create SessionItem with data on board
66  SessionItem item;
67  const std::string expected("Layer");
68  EXPECT_TRUE(item.setData(expected, ItemDataRole::DISPLAY));
69 
70  // initialize viewItem with sessionItem and set the data
71  ViewLabelItem viewItem(&item);
72  QVariant new_data("MultiLayer");
73  EXPECT_TRUE(viewItem.setData(new_data, Qt::EditRole));
74  EXPECT_EQ(viewItem.data(Qt::DisplayRole), new_data); // new data
75  EXPECT_EQ(viewItem.data(Qt::EditRole), new_data); // new data
76 
77  // SessionItem itself should have new data
78  EXPECT_EQ(item.data<QVariant>(ItemDataRole::DISPLAY),
79  Utils::toCustomVariant(new_data)); // new data
80 
81  // it is not allowed to set another type of data to ViewLabelItem
82  QVariant not_allowed_value(42);
83  EXPECT_THROW(viewItem.setData(not_allowed_value, Qt::EditRole), std::runtime_error);
84 }

References ModelView::ViewLabelItem::data(), ModelView::SessionItem::data(), ModelView::ItemDataRole::DISPLAY, ModelView::ViewItem::setData(), ModelView::SessionItem::setData(), and ModelView::Utils::toCustomVariant().

Here is the call graph for this function:

◆ TEST_F() [14/14]

TEST_F ( StandardViewItemsTest  ,
ViewLabelItem_toolTipRole   
)

Testing tooltip tole.

Definition at line 100 of file standardviewitems.test.cpp.

101 {
102  SessionItem item;
103 
104  ViewLabelItem viewItem(&item);
105  EXPECT_FALSE(viewItem.data(Qt::ToolTipRole).isValid());
106 
107  item.setToolTip("abc");
108  EXPECT_EQ(viewItem.data(Qt::ToolTipRole).toString(), QString("abc"));
109 }

References ModelView::ViewLabelItem::data(), ModelView::SessionItem::setToolTip(), and SessionItemUtils::ToolTipRole().

Here is the call graph for this function: