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

Implements class CLASS? More...

Include dependency graph for axistitlecontroller.test.cpp:

Go to the source code of this file.

Classes

class  AxisTitleControllerTest
 Testing AxisTitleControllers. More...
 

Functions

 TEST_F (AxisTitleControllerTest, initialState)
 Initial state. More...
 
 TEST_F (AxisTitleControllerTest, setFont)
 
 TEST_F (AxisTitleControllerTest, setTextItem)
 

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 axistitlecontroller.test.cpp.

Function Documentation

◆ TEST_F() [1/3]

TEST_F ( AxisTitleControllerTest  ,
initialState   
)

Initial state.

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

36 {
37  auto custom_plot = std::make_unique<QCustomPlot>();
38 
39  auto axis = custom_plot->xAxis;
40 
41  // controller shouldn''t change axis range
42  AxisTitleController controller(axis);
43  EXPECT_EQ(controller.currentItem(), nullptr);
44 
45  EXPECT_EQ(axis->label(), QString());
46 }
Propagates title settings from TextItem to QCPAxis.

References ModelView::ItemListener< T >::currentItem().

Here is the call graph for this function:

◆ TEST_F() [2/3]

TEST_F ( AxisTitleControllerTest  ,
setFont   
)

Definition at line 74 of file axistitlecontroller.test.cpp.

75 {
76  auto custom_plot = std::make_unique<QCustomPlot>();
77 
78  SessionModel model;
79  auto textItem = model.insertItem<TextItem>();
80 
81  auto axis = custom_plot->xAxis;
82 
83  // controller shouldn''t change axis range
84  AxisTitleController controller(axis);
85  controller.setItem(textItem);
86  EXPECT_EQ(controller.currentItem(), textItem);
87 
88  // setting new label
89  const QString expected_text("abc");
90  const QString expected_family("Helvetica");
91  const int expected_size = 42;
92  textItem->setProperty(TextItem::P_TEXT, expected_text.toStdString());
93  textItem->setProperty(TextItem::P_SIZE, expected_size);
94  textItem->setProperty(TextItem::P_FONT, expected_family.toStdString());
95 
96  // checking that label has updated
97  EXPECT_EQ(axis->label(), expected_text);
98  EXPECT_EQ(axis->labelFont().family(), expected_family);
99  EXPECT_EQ(axis->labelFont().pointSize(), expected_size);
100 }
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
Represent text item on plot.

References ModelView::ItemListener< T >::currentItem(), ModelView::SessionModel::insertItem(), ModelView::TextItem::P_FONT, ModelView::TextItem::P_SIZE, ModelView::TextItem::P_TEXT, and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [3/3]

TEST_F ( AxisTitleControllerTest  ,
setTextItem   
)

Definition at line 48 of file axistitlecontroller.test.cpp.

49 {
50  auto custom_plot = std::make_unique<QCustomPlot>();
51 
52  SessionModel model;
53  auto textItem = model.insertItem<TextItem>();
54 
55  auto axis = custom_plot->xAxis;
56  // auto expected_pointSize = axis->labelFont().pointSize();
57  // auto expected_family = axis->labelFont().family();
58 
59  // this a values hardcoded in plottableitems.cpp. Shell we provide some customized way to create
60  // TextItem with font/size suitable for QCPAxis ?
61  const int expected_pointSize = 10;
62  const std::string expected_family = "Noto Sans";
63 
64  // controller shouldn''t change axis range
65  AxisTitleController controller(axis);
66  controller.setItem(textItem);
67  EXPECT_EQ(controller.currentItem(), textItem);
68 
69  EXPECT_EQ(axis->label(), QString());
70  EXPECT_EQ(axis->labelFont().family().toStdString(), expected_family);
71  EXPECT_EQ(axis->labelFont().pointSize(), expected_pointSize);
72 }

References ModelView::ItemListener< T >::currentItem(), ModelView::SessionModel::insertItem(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function: