BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
pencontroller.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/pencontroller.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 "customplot_test_utils.h"
16 #include "google_test.h"
20 #include "qcustomplot.h"
21 
22 #include <stdexcept>
23 
24 using namespace ModelView;
25 
26 //! Testing PenController.
27 
28 class PenControllerTest : public ::testing::Test {
29 public:
31 };
32 
34 
35 //! Initial state.
36 
37 TEST_F(PenControllerTest, initialState)
38 {
39  // Constructor accept valid QCPGraph
40  EXPECT_THROW(PenController(nullptr), std::runtime_error);
41 
42  auto custom_plot = std::make_unique<QCustomPlot>();
43  auto graph = custom_plot->addGraph();
44 
45  PenController controller(graph);
46  EXPECT_EQ(controller.currentItem(), nullptr);
47 }
48 
49 TEST_F(PenControllerTest, graphItemInInitialState)
50 {
51  auto custom_plot = std::make_unique<QCustomPlot>();
52  auto graph = custom_plot->addGraph();
53 
54  PenController controller(graph);
55 
56  SessionModel model;
57  auto pen_item = model.insertItem<PenItem>();
58  controller.setItem(pen_item);
59 
60  EXPECT_EQ(controller.currentItem(), pen_item);
61 
62  // parameters of graph in QCustomPlot
63  EXPECT_EQ(graph->pen().color(), QColor(Qt::black));
64  EXPECT_EQ(graph->pen().style(), Qt::SolidLine);
65  EXPECT_EQ(graph->pen().width(), 1);
66 }
67 
68 TEST_F(PenControllerTest, setPenSelected)
69 {
70  auto custom_plot = std::make_unique<QCustomPlot>();
71  auto graph = custom_plot->addGraph();
72 
73  PenController controller(graph);
74 
75  SessionModel model;
76  auto pen_item = model.insertItem<PenItem>();
77  controller.setItem(pen_item);
78 
79  pen_item->setSelected(true);
80 
81  // parameters of graph in QCustomPlot
82  EXPECT_EQ(graph->pen().color(), QColor(Qt::black));
83  EXPECT_EQ(graph->pen().style(), Qt::DashLine);
84  EXPECT_EQ(graph->pen().width(), 1);
85 }
86 
87 TEST_F(PenControllerTest, setColorAndWidth)
88 {
89  auto custom_plot = std::make_unique<QCustomPlot>();
90  auto graph = custom_plot->addGraph();
91 
92  PenController controller(graph);
93 
94  SessionModel model;
95  auto pen_item = model.insertItem<PenItem>();
96  controller.setItem(pen_item);
97 
98  pen_item->setProperty(PenItem::P_WIDTH, 2);
99  pen_item->setProperty(PenItem::P_COLOR, QColor(Qt::red));
100 
101  // parameters of graph in QCustomPlot
102  EXPECT_EQ(graph->pen().color(), QColor(Qt::red));
103  EXPECT_EQ(graph->pen().style(), Qt::SolidLine);
104  EXPECT_EQ(graph->pen().width(), 2);
105 
106  // set color via named color machinery
107  pen_item->setNamedColor("azure");
108  EXPECT_EQ(graph->pen().color().name(), QString("#f0ffff"));
109 }
void setItem(SessionItem *item)
Establishes communication between QCPGraph and PenItem.
Definition: pencontroller.h:31
Represents basics settings of QPen.
static const std::string P_COLOR
static const std::string P_WIDTH
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
Testing PenController.
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(PenControllerTest, initialState)
Initial state.
Defines class CLASS?
Defines class CLASS?