BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
colormapviewportplotcontroller.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/colormapviewportplotcontroller.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"
24 #include "qcustomplot.h"
25 #include <qcustomplot.h>
26 
27 using namespace ModelView;
28 
29 //! Testing ColorMapViewportPlotController.
30 
31 class ColorMapViewportPlotControllerTest : public ::testing::Test {
32 public:
34 };
35 
37 
38 //! Initial state.
39 
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 }
53 
54 //! Check ::setItem() method when no colormaps exist.
55 
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 }
79 
80 //! Check ::setItem() method when data 2d is fully set up.
81 
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 }
109 
110 //! Consequitive setup.
111 
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 }
Defines class CLASS?
Testing ColorMapViewportPlotController.
Two-dimensional color map representation of Data2DItem.
Definition: colormapitem.h:28
void setDataItem(const Data2DItem *item)
Sets link to the data item.
Container with viewport and collection of ColorMapItem's to plot.
Establishes communications and mutual updates for ColorMapViewportItem and QCutomPlot.
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
static std::unique_ptr< FixedBinAxisItem > create(int nbins, double xmin, double xmax)
Definition: axisitems.cpp:81
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
Defines class CLASS?
Defines class CLASS?
TEST_F(ColorMapViewportPlotControllerTest, initialState)
Initial state.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?