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

Implements class CLASS? More...

Include dependency graph for pencontroller.test.cpp:

Go to the source code of this file.

Classes

class  PenControllerTest
 Testing PenController. More...
 

Functions

 TEST_F (PenControllerTest, graphItemInInitialState)
 
 TEST_F (PenControllerTest, initialState)
 Initial state. More...
 
 TEST_F (PenControllerTest, setColorAndWidth)
 
 TEST_F (PenControllerTest, setPenSelected)
 

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

Function Documentation

◆ TEST_F() [1/4]

TEST_F ( PenControllerTest  ,
graphItemInInitialState   
)

Definition at line 49 of file pencontroller.test.cpp.

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 }
Establishes communication between QCPGraph and PenItem.
Definition: pencontroller.h:31
Represents basics settings of QPen.
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

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

Here is the call graph for this function:

◆ TEST_F() [2/4]

TEST_F ( PenControllerTest  ,
initialState   
)

Initial state.

Definition at line 37 of file pencontroller.test.cpp.

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 }

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

Here is the call graph for this function:

◆ TEST_F() [3/4]

TEST_F ( PenControllerTest  ,
setColorAndWidth   
)

Definition at line 87 of file pencontroller.test.cpp.

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 setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190

References ModelView::SessionModel::insertItem(), ModelView::PenItem::P_COLOR, ModelView::PenItem::P_WIDTH, and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [4/4]

TEST_F ( PenControllerTest  ,
setPenSelected   
)

Definition at line 68 of file pencontroller.test.cpp.

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 }
void setSelected(bool is_selected)
Sets style of the pen to represent selected object (dash line).

References ModelView::SessionModel::insertItem(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function: