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

Implements class CLASS? More...

Include dependency graph for graphplotcontroller.test.cpp:

Go to the source code of this file.

Classes

class  GraphPlotControllerTest
 Testing GraphPlotController. More...
 

Functions

 TEST_F (GraphPlotControllerTest, changeGraphAppearance)
 
 TEST_F (GraphPlotControllerTest, controllerDelete)
 Deletion of controller should lead to graph removal. More...
 
 TEST_F (GraphPlotControllerTest, graphDelete)
 Deletion of graphItem should lead to the dissapearance of graph. More...
 
 TEST_F (GraphPlotControllerTest, initialState)
 Initial state. More...
 
 TEST_F (GraphPlotControllerTest, setDataAfter)
 Setting data to graph after. More...
 
 TEST_F (GraphPlotControllerTest, setItem)
 Setting GraphItem with data and checking that plottable contains correct data. More...
 
 TEST_F (GraphPlotControllerTest, setPointwiseItem)
 Setting GraphItem with data and checking that plottable contains correct data. More...
 
 TEST_F (GraphPlotControllerTest, unlinkFromItem)
 Unlinking from Data1DItem or GraphItem. 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 graphplotcontroller.test.cpp.

Function Documentation

◆ TEST_F() [1/8]

TEST_F ( GraphPlotControllerTest  ,
changeGraphAppearance   
)

Definition at line 80 of file graphplotcontroller.test.cpp.

81 {
82  auto custom_plot = std::make_unique<QCustomPlot>();
83  GraphPlotController controller(custom_plot.get());
84 
85  // setup model and single data item in it
86  SessionModel model;
87  auto data_item = model.insertItem<Data1DItem>();
88  data_item->setAxis<FixedBinAxisItem>(2, 0.0, 2.0);
89  std::vector<double> expected_centers = {0.5, 1.5};
90  std::vector<double> expected_values = {42.0, 43.0};
91  data_item->setValues(expected_values);
92 
93  // setup graph item
94  auto graph_item = model.insertItem<GraphItem>();
95  graph_item->setDataItem(data_item);
96 
97  // initializing controller
98  controller.setItem(graph_item);
99 
100  // changing appearance properties
101  auto pen_item = graph_item->penItem();
102  pen_item->setProperty(PenItem::P_COLOR, QColor(Qt::red));
103 
104  auto styleCombo = pen_item->property<ComboProperty>(PenItem::P_STYLE);
105  styleCombo.setCurrentIndex(2);
106  pen_item->setProperty(PenItem::P_STYLE, styleCombo);
107  pen_item->setProperty(PenItem::P_WIDTH, 2);
108 
109  auto graph = custom_plot->graph();
110  EXPECT_EQ(graph->pen().color(), QColor(Qt::red));
111  EXPECT_EQ(graph->pen().style(), Qt::DashLine);
112  EXPECT_EQ(graph->pen().width(), 2);
113 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27
void setCurrentIndex(int index)
Represents one-dimensional data (axis and values).
Definition: data1ditem.h:30
T * setAxis(Args &&... args)
Inserts axis of given type.
Definition: data1ditem.h:56
Item to represent fixed bin axis.
Definition: axisitems.h:75
One-dimensional graph representation of Data1DItem.
Definition: graphitem.h:29
void setDataItem(const Data1DItem *item)
Sets link to the data item.
Definition: graphitem.cpp:34
Establish communication between QCPGraph and GraphItem.
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::SessionModel::insertItem(), ModelView::PenItem::P_COLOR, ModelView::PenItem::P_STYLE, ModelView::PenItem::P_WIDTH, ModelView::Data1DItem::setAxis(), ModelView::ComboProperty::setCurrentIndex(), ModelView::GraphItem::setDataItem(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [2/8]

TEST_F ( GraphPlotControllerTest  ,
controllerDelete   
)

Deletion of controller should lead to graph removal.

Definition at line 224 of file graphplotcontroller.test.cpp.

225 {
226  auto custom_plot = std::make_unique<QCustomPlot>();
227  auto controller = std::make_unique<GraphPlotController>(custom_plot.get());
228 
229  // setup model and single data item in it
230  SessionModel model;
231  auto data_item = model.insertItem<Data1DItem>();
232 
233  // setup graph item
234  auto graph_item = model.insertItem<GraphItem>();
235  graph_item->setDataItem(data_item);
236 
237  // initializing controller
238  controller->setItem(graph_item);
239  EXPECT_EQ(custom_plot->graphCount(), 1);
240 
241  // deleting controller should lead to graph removal
242  controller.reset();
243  EXPECT_EQ(custom_plot->graphCount(), 0);
244 }

References ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [3/8]

TEST_F ( GraphPlotControllerTest  ,
graphDelete   
)

Deletion of graphItem should lead to the dissapearance of graph.

Definition at line 248 of file graphplotcontroller.test.cpp.

249 {
250  auto custom_plot = std::make_unique<QCustomPlot>();
251  auto controller = std::make_unique<GraphPlotController>(custom_plot.get());
252 
253  // setup model and single data item in it
254  SessionModel model;
255  auto data_item = model.insertItem<Data1DItem>();
256 
257  // setup graph item
258  auto graph_item = model.insertItem<GraphItem>();
259  graph_item->setDataItem(data_item);
260 
261  // initializing controller
262  controller->setItem(graph_item);
263  EXPECT_EQ(custom_plot->graphCount(), 1);
264 
265  model.removeItem(graph_item->parent(), graph_item->tagRow());
266  EXPECT_EQ(custom_plot->graphCount(), 0);
267 }
SessionItem * parent() const
Returns parent item. Will return nullptr if item doesn't have a parent.
TagRow tagRow() const
Returns TagRow of this item under which it is accessible through its parent.
void removeItem(SessionItem *parent, const TagRow &tagrow)
Removes given row from parent.

References ModelView::SessionModel::insertItem(), ModelView::SessionItem::parent(), ModelView::SessionModel::removeItem(), and ModelView::SessionItem::tagRow().

Here is the call graph for this function:

◆ TEST_F() [4/8]

TEST_F ( GraphPlotControllerTest  ,
initialState   
)

Initial state.

Definition at line 40 of file graphplotcontroller.test.cpp.

41 {
42  auto custom_plot = std::make_unique<QCustomPlot>();
43  GraphPlotController controller(custom_plot.get());
44  EXPECT_EQ(controller.currentItem(), nullptr);
45  EXPECT_EQ(custom_plot->graphCount(), 0);
46 }

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

Here is the call graph for this function:

◆ TEST_F() [5/8]

TEST_F ( GraphPlotControllerTest  ,
setDataAfter   
)

Setting data to graph after.

Definition at line 151 of file graphplotcontroller.test.cpp.

152 {
153  auto custom_plot = std::make_unique<QCustomPlot>();
154  GraphPlotController controller(custom_plot.get());
155 
156  SessionModel model;
157  auto graph_item = model.insertItem<GraphItem>();
158 
159  controller.setItem(graph_item);
160 
161  // without data QCustomPlot has a graph without points
162  EXPECT_EQ(custom_plot->graphCount(), 1);
163  auto graph = custom_plot->graph();
164  EXPECT_EQ(TestUtils::binCenters(graph), std::vector<double>());
165  EXPECT_EQ(TestUtils::binValues(graph), std::vector<double>());
166 
167  // setup Data1DItem and assign to GraphItem
168  auto data_item = model.insertItem<Data1DItem>();
169  data_item->setAxis<FixedBinAxisItem>(2, 0.0, 2.0);
170  std::vector<double> expected_centers = {0.5, 1.5};
171  std::vector<double> expected_values = {42.0, 43.0};
172  data_item->setValues(expected_values);
173 
174  graph_item->setDataItem(data_item);
175 
176  // Checking resulting plottables
177  EXPECT_EQ(custom_plot->graphCount(), 1);
178  EXPECT_EQ(TestUtils::binCenters(graph), expected_centers);
179  EXPECT_EQ(TestUtils::binValues(graph), expected_values);
180 }
std::vector< double > binValues(const QCPGraph *graph)
Returns vector representing y-values on QCPgraph.
std::vector< double > binCenters(const QCPGraph *graph)
Returns vector representing bin centers on QCPgraph.

References TestUtils::binCenters(), TestUtils::binValues(), ModelView::SessionModel::insertItem(), ModelView::Data1DItem::setAxis(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [6/8]

TEST_F ( GraphPlotControllerTest  ,
setItem   
)

Setting GraphItem with data and checking that plottable contains correct data.

Definition at line 50 of file graphplotcontroller.test.cpp.

51 {
52  auto custom_plot = std::make_unique<QCustomPlot>();
53  GraphPlotController controller(custom_plot.get());
54 
55  // setup model and single data item in it
56  SessionModel model;
57  auto data_item = model.insertItem<Data1DItem>();
58  data_item->setAxis<FixedBinAxisItem>(2, 0.0, 2.0);
59  std::vector<double> expected_centers = {0.5, 1.5};
60  std::vector<double> expected_values = {42.0, 43.0};
61  data_item->setValues(expected_values);
62 
63  // setup graph item
64  auto graph_item = model.insertItem<GraphItem>();
65  graph_item->setDataItem(data_item);
66 
67  // initializing controller
68  controller.setItem(graph_item);
69 
70  // Checking resulting plottables
71  EXPECT_EQ(custom_plot->graphCount(), 1);
72  auto graph = custom_plot->graph();
73  EXPECT_EQ(TestUtils::binCenters(graph), expected_centers);
74  EXPECT_EQ(TestUtils::binValues(graph), expected_values);
75  EXPECT_EQ(graph->pen().color(), QColor(Qt::black));
76  EXPECT_EQ(graph->pen().style(), Qt::SolidLine);
77  EXPECT_EQ(graph->pen().width(), 1);
78 }

References TestUtils::binCenters(), TestUtils::binValues(), ModelView::SessionModel::insertItem(), ModelView::Data1DItem::setAxis(), ModelView::GraphItem::setDataItem(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [7/8]

TEST_F ( GraphPlotControllerTest  ,
setPointwiseItem   
)

Setting GraphItem with data and checking that plottable contains correct data.

Same as aboe, except that the data is based on PointWiseAxis.

Definition at line 118 of file graphplotcontroller.test.cpp.

119 {
120  auto custom_plot = std::make_unique<QCustomPlot>();
121  GraphPlotController controller(custom_plot.get());
122 
123  // setup model and single data item in it
124  const std::vector<double> expected_centers = {1.0, 2.0, 3.0};
125  const std::vector<double> expected_values = {42.0, 43.0, 44.0};
126 
127  SessionModel model;
128  auto data_item = model.insertItem<Data1DItem>();
129  data_item->setAxis<PointwiseAxisItem>(expected_centers);
130  data_item->setValues(expected_values);
131 
132  // setup graph item
133  auto graph_item = model.insertItem<GraphItem>();
134  auto pen_item = graph_item->penItem();
135  pen_item->setProperty(PenItem::P_COLOR, QColor(Qt::red));
136  graph_item->setDataItem(data_item);
137 
138  // initializing controller
139  controller.setItem(graph_item);
140 
141  // Checking resulting plottables
142  EXPECT_EQ(custom_plot->graphCount(), 1);
143  auto graph = custom_plot->graph();
144  EXPECT_EQ(TestUtils::binCenters(graph), expected_centers);
145  EXPECT_EQ(TestUtils::binValues(graph), expected_values);
146  EXPECT_EQ(graph->pen().color(), QColor(Qt::red));
147 }
PenItem * penItem() const
Definition: graphitem.cpp:89
Item to represent pointwise axis.
Definition: axisitems.h:94
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190

References TestUtils::binCenters(), TestUtils::binValues(), ModelView::SessionModel::insertItem(), ModelView::PenItem::P_COLOR, ModelView::GraphItem::penItem(), ModelView::Data1DItem::setAxis(), ModelView::ItemListenerBase::setItem(), and ModelView::SessionItem::setProperty().

Here is the call graph for this function:

◆ TEST_F() [8/8]

TEST_F ( GraphPlotControllerTest  ,
unlinkFromItem   
)

Unlinking from Data1DItem or GraphItem.

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

185 {
186  auto custom_plot = std::make_unique<QCustomPlot>();
187  GraphPlotController controller(custom_plot.get());
188 
189  // setup model and single data item in it
190  SessionModel model;
191  auto data_item = model.insertItem<Data1DItem>();
192  data_item->setAxis<FixedBinAxisItem>(2, 0.0, 2.0);
193  std::vector<double> expected_centers = {0.5, 1.5};
194  std::vector<double> expected_values = {42.0, 43.0};
195  data_item->setValues(expected_values);
196 
197  // setup graph item
198  auto graph_item = model.insertItem<GraphItem>();
199  auto pen_item = graph_item->penItem();
200  pen_item->setProperty(PenItem::P_COLOR, QColor(Qt::red));
201  graph_item->setDataItem(data_item);
202 
203  // initializing controller
204  controller.setItem(graph_item);
205 
206  // unlinking from data item
207  graph_item->setDataItem(nullptr);
208 
209  // Checking resulting plottables
210  // Current convention is that graph stays intact, but points disappear.
211  EXPECT_EQ(custom_plot->graphCount(), 1);
212  auto graph = custom_plot->graph();
213  EXPECT_EQ(TestUtils::binCenters(graph), std::vector<double>());
214  EXPECT_EQ(TestUtils::binValues(graph), std::vector<double>());
215  EXPECT_EQ(graph->pen().color(), QColor(Qt::red));
216 
217  // unlinking from graph item should remove Graph from CustomPlot
218  controller.setItem(nullptr);
219  EXPECT_EQ(custom_plot->graphCount(), 0);
220 }

References TestUtils::binCenters(), TestUtils::binValues(), ModelView::SessionModel::insertItem(), ModelView::PenItem::P_COLOR, ModelView::GraphItem::penItem(), ModelView::Data1DItem::setAxis(), ModelView::ItemListenerBase::setItem(), and ModelView::SessionItem::setProperty().

Here is the call graph for this function: