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

Implements class CLASS? More...

Include dependency graph for colormapplotcontroller.test.cpp:

Go to the source code of this file.

Classes

class  ColorMapPlotControllerTest
 Testing ColorMapPlotController. More...
 

Functions

 TEST_F (ColorMapPlotControllerTest, controllerDelete)
 Deletion of controller should lead to graph removal. More...
 
 TEST_F (ColorMapPlotControllerTest, initialState)
 Initial state. More...
 
 TEST_F (ColorMapPlotControllerTest, setDataAfter)
 Setting data to graph after. More...
 
 TEST_F (ColorMapPlotControllerTest, setGradient)
 Deletion of controller should lead to graph removal. More...
 
 TEST_F (ColorMapPlotControllerTest, setItem)
 Setting ColorMapItem with data and checking that QCPColorMap appeared among plottables. More...
 
 TEST_F (ColorMapPlotControllerTest, unlinkFromItem)
 Unlinking from Data2DItem or ColorMapItem. 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 colormapplotcontroller.test.cpp.

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( ColorMapPlotControllerTest  ,
controllerDelete   
)

Deletion of controller should lead to graph removal.

Definition at line 167 of file colormapplotcontroller.test.cpp.

168 {
169  auto custom_plot = std::make_unique<QCustomPlot>();
170  auto controller = std::make_unique<ColorMapPlotController>(custom_plot.get());
171 
172  // setup model and single data item in it
173  SessionModel model;
174  auto data_item = model.insertItem<Data2DItem>();
175 
176  // setup graph item
177  auto colormap_item = model.insertItem<ColorMapItem>();
178  colormap_item->setDataItem(data_item);
179 
180  // initializing controller
181  controller->setItem(colormap_item);
182  EXPECT_EQ(custom_plot->plottableCount(), 1);
183 
184  // deleting controller should lead to QCPColorMap removal
185  controller.reset();
186  EXPECT_EQ(custom_plot->plottableCount(), 0);
187 }
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
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().

Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( ColorMapPlotControllerTest  ,
initialState   
)

Initial state.

Definition at line 39 of file colormapplotcontroller.test.cpp.

40 {
41  auto custom_plot = std::make_unique<QCustomPlot>();
42  ColorMapPlotController controller(custom_plot.get());
43  EXPECT_EQ(controller.currentItem(), nullptr);
44 
45  // creation of controller leads to the creation of QCPColorMap
46  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
47  ASSERT_TRUE(color_map != nullptr);
48 }
Establish communication between QCPColorMap and ColorMapItem.

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

Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( ColorMapPlotControllerTest  ,
setDataAfter   
)

Setting data to graph after.

Definition at line 88 of file colormapplotcontroller.test.cpp.

89 {
90  auto custom_plot = std::make_unique<QCustomPlot>();
91  ColorMapPlotController controller(custom_plot.get());
92 
93  SessionModel model;
94  auto colormap_item = model.insertItem<ColorMapItem>();
95 
96  controller.setItem(colormap_item);
97 
98  // without data QCustomPlot has QCPColorMap without default settings
99  EXPECT_EQ(custom_plot->plottableCount(), 1);
100  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
101  ASSERT_TRUE(color_map != nullptr);
102  const int qcpmap_internal_default(10);
103  EXPECT_EQ(color_map->data()->keySize(), qcpmap_internal_default);
104  EXPECT_EQ(color_map->data()->valueSize(), qcpmap_internal_default);
105 
106  // setup Data2DItem and assign to ColorMapItem
107  auto data_item = model.insertItem<Data2DItem>();
108  const int nx = 3, ny = 2;
109  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
110  FixedBinAxisItem::create(ny, 0.0, 2.0));
111  std::vector<double> expected = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
112  data_item->setContent(expected);
113 
114  colormap_item->setDataItem(data_item);
115 
116  // colormap should get the shape of Data2DItem
117  EXPECT_EQ(color_map->data()->keySize(), nx);
118  EXPECT_EQ(color_map->data()->valueSize(), ny);
119  EXPECT_EQ(color_map->data()->cell(0, 0), 1.0);
120  EXPECT_EQ(color_map->data()->cell(nx - 1, ny - 1), 6.0);
121 }
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/6]

TEST_F ( ColorMapPlotControllerTest  ,
setGradient   
)

Deletion of controller should lead to graph removal.

Definition at line 191 of file colormapplotcontroller.test.cpp.

192 {
193  auto custom_plot = std::make_unique<QCustomPlot>();
194  auto controller = std::make_unique<ColorMapPlotController>(custom_plot.get());
195 
196  // setup model and single data item in it
197  SessionModel model;
198  auto data_item = model.insertItem<Data2DItem>();
199 
200  // creating colormap item
201  auto colormap_item = model.insertItem<ColorMapItem>();
202  colormap_item->setDataItem(data_item);
203 
204  controller->setItem(colormap_item);
205 
206  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
207 
208  EXPECT_EQ(color_map->gradient(), QCPColorGradient::gpPolar);
209 
210  auto combo = colormap_item->property<ComboProperty>(ColorMapItem::P_GRADIENT);
211  combo.setValue("Hot");
212  colormap_item->setProperty(ColorMapItem::P_GRADIENT, combo);
213  EXPECT_EQ(color_map->gradient(), QCPColorGradient::gpHot);
214 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27
void setValue(const std::string &name)
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190

References ModelView::SessionModel::insertItem(), ModelView::ColorMapItem::P_GRADIENT, ModelView::SessionItem::property(), ModelView::SessionItem::setProperty(), and ModelView::ComboProperty::setValue().

Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( ColorMapPlotControllerTest  ,
setItem   
)

Setting ColorMapItem with data and checking that QCPColorMap appeared among plottables.

Definition at line 52 of file colormapplotcontroller.test.cpp.

53 {
54  auto custom_plot = std::make_unique<QCustomPlot>();
55  ColorMapPlotController controller(custom_plot.get());
56 
57  // creating data item
58  SessionModel model;
59  auto data_item = model.insertItem<Data2DItem>();
60  const int nx = 3, ny = 2;
61  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
62  FixedBinAxisItem::create(ny, 0.0, 2.0));
63  std::vector<double> expected = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
64  data_item->setContent(expected);
65 
66  // creating colormap item
67  auto colormap_item = model.insertItem<ColorMapItem>();
68  colormap_item->setDataItem(data_item);
69 
70  // initializing controller
71  controller.setItem(colormap_item);
72 
73  // checking that QCPColorMap has been created
74  EXPECT_EQ(custom_plot->plottableCount(), 1);
75  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
76  ASSERT_TRUE(color_map != nullptr);
77  EXPECT_EQ(color_map->data()->keySize(), nx);
78  EXPECT_EQ(color_map->data()->valueSize(), ny);
79  EXPECT_EQ(color_map->data()->cell(0, 0), 1.0);
80  EXPECT_EQ(color_map->data()->cell(nx - 1, ny - 1), 6.0);
81 
82  // checking interpolation flag
83  EXPECT_TRUE(color_map->interpolate());
84 }
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:

◆ TEST_F() [6/6]

TEST_F ( ColorMapPlotControllerTest  ,
unlinkFromItem   
)

Unlinking from Data2DItem or ColorMapItem.

Definition at line 125 of file colormapplotcontroller.test.cpp.

126 {
127  auto custom_plot = std::make_unique<QCustomPlot>();
128  ColorMapPlotController controller(custom_plot.get());
129 
130  // setup model and single data item in it
131  SessionModel model;
132  auto data_item = model.insertItem<Data2DItem>();
133  const int nx = 3, ny = 2;
134  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
135  FixedBinAxisItem::create(ny, 0.0, 2.0));
136  std::vector<double> expected = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
137  data_item->setContent(expected);
138 
139  // creating colormap item
140  auto colormap_item = model.insertItem<ColorMapItem>();
141  colormap_item->setDataItem(data_item);
142 
143  controller.setItem(colormap_item);
144 
145  auto color_map = TestUtils::GetPlottable<QCPColorMap>(custom_plot.get());
146  EXPECT_EQ(color_map->data()->keySize(), nx);
147  EXPECT_EQ(color_map->data()->valueSize(), ny);
148 
149  // unlinking from data item
150  colormap_item->setDataItem(nullptr);
151 
152  EXPECT_EQ(custom_plot->plottableCount(), 1);
153 
154  // QCPColorMap should be there, but its shapre should be (0,0)
155  EXPECT_EQ(color_map->data()->keySize(), 0);
156  EXPECT_EQ(color_map->data()->valueSize(), 0);
157 
158  // unlinking from ColorMapItem leave QCPColorMap intact
159  controller.setItem(nullptr);
160  EXPECT_EQ(custom_plot->plottableCount(), 1);
161  EXPECT_EQ(color_map->data()->keySize(), 0);
162  EXPECT_EQ(color_map->data()->valueSize(), 0);
163 }

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: