BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
axistitlecontroller.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/testview/axistitlecontroller.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"
19 #include "qcustomplot.h"
20 #include <QFont>
21 
22 using namespace ModelView;
23 
24 //! Testing AxisTitleControllers.
25 
26 class AxisTitleControllerTest : public ::testing::Test {
27 public:
29 };
30 
32 
33 //! Initial state.
34 
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 }
47 
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 }
73 
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 }
Defines class CLASS?
TEST_F(AxisTitleControllerTest, initialState)
Initial state.
Testing AxisTitleControllers.
Propagates title settings from TextItem to QCPAxis.
void setItem(SessionItem *item)
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.
static const std::string P_SIZE
static const std::string P_FONT
static const std::string P_TEXT
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?