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

Implements class CLASS? More...

Include dependency graph for colormapviewportplotcontroller.test.cpp:

Go to the source code of this file.

Classes

class  ColorMapViewportPlotControllerTest
 Testing ColorMapViewportPlotController. More...
 

Functions

 TEST_F (ColorMapViewportPlotControllerTest, initialState)
 Initial state. More...
 
 TEST_F (ColorMapViewportPlotControllerTest, setEmptyViewport)
 Check ::setItem() method when no colormaps exist. More...
 
 TEST_F (ColorMapViewportPlotControllerTest, setItem)
 Check ::setItem() method when data 2d is fully set up. More...
 
 TEST_F (ColorMapViewportPlotControllerTest, setupConsequitive)
 Consequitive setup. 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 colormapviewportplotcontroller.test.cpp.

Function Documentation

◆ TEST_F() [1/4]

TEST_F ( ColorMapViewportPlotControllerTest  ,
initialState   
)

Initial state.

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

41 {
42  auto custom_plot = std::make_unique<QCustomPlot>();
43  ColorMapViewportPlotController controller(custom_plot.get());
44  EXPECT_EQ(controller.currentItem(), nullptr);
45  EXPECT_TRUE(TestUtils::GetPlottable<QCPColorMap>(custom_plot.get()) != nullptr);
46 
47  const double customplot_default_lower(0.0), customplot_default_upper(5.0);
48  EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().lower, customplot_default_lower);
49  EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().upper, customplot_default_upper);
50  EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().lower, customplot_default_lower);
51  EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().upper, customplot_default_upper);
52 }
Establishes communications and mutual updates for ColorMapViewportItem and QCutomPlot.

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

Here is the call graph for this function:

◆ TEST_F() [2/4]

TEST_F ( ColorMapViewportPlotControllerTest  ,
setEmptyViewport   
)

Check ::setItem() method when no colormaps exist.

Definition at line 56 of file colormapviewportplotcontroller.test.cpp.

57 {
58  auto custom_plot = std::make_unique<QCustomPlot>();
59  ColorMapViewportPlotController controller(custom_plot.get());
60 
61  SessionModel model;
62  auto viewport_item = model.insertItem<ColorMapViewportItem>();
63 
64  controller.setItem(viewport_item);
65 
66  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
67  EXPECT_TRUE(color_map != nullptr);
68 
69  const double default_lower(0.0), default_upper(1.0);
70  EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().lower, default_lower);
71  EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().upper, default_upper);
72  EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().lower, default_lower);
73  EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().upper, default_upper);
74 
75  const int qcpmap_internal_default(10);
76  EXPECT_EQ(color_map->data()->keySize(), qcpmap_internal_default);
77  EXPECT_EQ(color_map->data()->valueSize(), qcpmap_internal_default);
78 }
Container with viewport and collection of ColorMapItem's to plot.
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(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [3/4]

TEST_F ( ColorMapViewportPlotControllerTest  ,
setItem   
)

Check ::setItem() method when data 2d is fully set up.

Definition at line 82 of file colormapviewportplotcontroller.test.cpp.

83 {
84  auto custom_plot = std::make_unique<QCustomPlot>();
85  ColorMapViewportPlotController controller(custom_plot.get());
86 
87  SessionModel model;
88  auto data_item = model.insertItem<Data2DItem>();
89  const int nx = 3, ny = 2;
90  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
91  FixedBinAxisItem::create(ny, 0.0, 2.0));
92  std::vector<double> expected = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
93  data_item->setContent(expected);
94 
95  // creating colormap item
96  auto viewport_item = model.insertItem<ColorMapViewportItem>();
97  auto colormap_item = model.insertItem<ColorMapItem>(viewport_item);
98  colormap_item->setDataItem(data_item);
99 
100  // setting up the controller
101  controller.setItem(viewport_item);
102 
103  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
104  EXPECT_EQ(color_map->data()->keySize(), nx);
105  EXPECT_EQ(color_map->data()->valueSize(), ny);
106  EXPECT_EQ(color_map->data()->cell(0, 0), 1.0);
107  EXPECT_EQ(color_map->data()->cell(nx - 1, ny - 1), 6.0);
108 }
Two-dimensional color map representation of Data2DItem.
Definition: colormapitem.h:28
Represents two-dimensional data (axes definition and 2d array of values).
Definition: data2ditem.h:29
void setAxes(std::unique_ptr< BinnedAxisItem > x_axis, std::unique_ptr< BinnedAxisItem > y_axis)
Sets axes and put data points to zero.
Definition: data2ditem.cpp:41

References ModelView::FixedBinAxisItem::create(), ModelView::SessionModel::insertItem(), ModelView::Data2DItem::setAxes(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [4/4]

TEST_F ( ColorMapViewportPlotControllerTest  ,
setupConsequitive   
)

Consequitive setup.

Definition at line 112 of file colormapviewportplotcontroller.test.cpp.

113 {
114  auto custom_plot = std::make_unique<QCustomPlot>();
115  ColorMapViewportPlotController controller(custom_plot.get());
116 
117  SessionModel model;
118  auto viewport_item = model.insertItem<ColorMapViewportItem>();
119 
120  controller.setItem(viewport_item);
121 
122  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
123  EXPECT_TRUE(color_map != nullptr);
124 
125  // setting up data
126  auto data_item = model.insertItem<Data2DItem>();
127  const int nx = 3, ny = 2;
128  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
129  FixedBinAxisItem::create(ny, 0.0, 2.0));
130  std::vector<double> expected = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
131  data_item->setContent(expected);
132 
133  // creating colormap item
134  auto colormap_item = model.insertItem<ColorMapItem>(viewport_item);
135  colormap_item->setDataItem(data_item);
136 
137  // checking that QCPColorMap has good shape
138  EXPECT_EQ(color_map->data()->keySize(), nx);
139  EXPECT_EQ(color_map->data()->valueSize(), ny);
140  EXPECT_EQ(color_map->data()->cell(0, 0), 1.0);
141  EXPECT_EQ(color_map->data()->cell(nx - 1, ny - 1), 6.0);
142 }
void setDataItem(const Data2DItem *item)
Sets link to the data item.

References ModelView::FixedBinAxisItem::create(), ModelView::SessionModel::insertItem(), ModelView::Data2DItem::setAxes(), ModelView::ColorMapItem::setDataItem(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function: