22 #include "qcustomplot.h"
34 std::unique_ptr<QSignalSpy>
createSpy(QCPAxis* axis)
36 return std::make_unique<QSignalSpy>(
37 axis,
static_cast<void (QCPAxis::*)(
const QCPRange&)
>(&QCPAxis::rangeChanged));
42 return std::make_unique<QSignalSpy>(
43 axis,
static_cast<void (QCPAxis::*)(
const QCPRange&,
const QCPRange&)
>(
44 &QCPAxis::rangeChanged));
54 auto custom_plot = std::make_unique<QCustomPlot>();
56 auto axis = custom_plot->xAxis;
59 const double customplot_default_lower(0.0), customplot_default_upper(5.0);
60 EXPECT_EQ(axis->range().lower, customplot_default_lower);
61 EXPECT_EQ(axis->range().upper, customplot_default_upper);
65 EXPECT_EQ(axis->range().lower, customplot_default_lower);
66 EXPECT_EQ(axis->range().upper, customplot_default_upper);
69 auto xChanged = createSpy(custom_plot->xAxis);
70 auto yChanged = createSpy(custom_plot->yAxis);
73 custom_plot->xAxis->setRangeLower(1.0);
76 EXPECT_EQ(xChanged->count(), 1);
77 EXPECT_EQ(yChanged->count(), 0);
85 auto custom_plot = std::make_unique<QCustomPlot>();
86 const double expected_min = 1.0;
87 const double expected_max = 2.0;
96 ASSERT_TRUE(custom_plot->xAxis !=
nullptr);
99 auto prev_y_range = custom_plot->yAxis->range();
100 auto xChanged = createSpy(custom_plot->xAxis);
101 auto yChanged = createSpy(custom_plot->yAxis);
106 EXPECT_EQ(custom_plot->xAxis->range().lower, expected_min);
107 EXPECT_EQ(custom_plot->xAxis->range().upper, expected_max);
108 EXPECT_EQ(xChanged->count(), 1);
109 EXPECT_EQ(yChanged->count(), 0);
112 EXPECT_EQ(custom_plot->yAxis->range(), prev_y_range);
120 auto custom_plot = std::make_unique<QCustomPlot>();
129 const double expected_min = 1.0;
130 const double expected_max = 2.0;
131 auto xChanged = createSpy(custom_plot->xAxis);
132 auto yChanged = createSpy(custom_plot->yAxis);
138 EXPECT_EQ(xChanged->count(), 1);
139 EXPECT_EQ(yChanged->count(), 0);
142 custom_plot->xAxis->setRange(expected_min, expected_max);
143 EXPECT_EQ(xChanged->count(), 2);
144 EXPECT_EQ(yChanged->count(), 0);
156 auto custom_plot = std::make_unique<QCustomPlot>();
167 auto xChanged = createSpy(custom_plot->xAxis);
168 auto yChanged = createSpy(custom_plot->yAxis);
171 const double expected_min = 1.0;
172 const double expected_max = 2.0;
177 EXPECT_EQ(xChanged->count(), 2);
178 EXPECT_EQ(yChanged->count(), 0);
179 EXPECT_EQ(custom_plot->xAxis->range().lower, expected_min);
180 EXPECT_EQ(custom_plot->xAxis->range().upper, expected_max);
189 auto custom_plot = std::make_unique<QCustomPlot>();
202 EXPECT_EQ(custom_plot->xAxis->range().lower, 1.0);
203 EXPECT_EQ(custom_plot->xAxis->range().upper, 2.0);
205 auto rangeChanged = createSpy(custom_plot->xAxis);
206 auto rangeChanged2 = createSpy2(custom_plot->xAxis);
209 const double expected_max = 20.0;
213 EXPECT_EQ(rangeChanged->count(), 1);
214 EXPECT_EQ(rangeChanged2->count(), 1);
215 EXPECT_EQ(custom_plot->xAxis->range().lower, 1.0);
216 EXPECT_EQ(custom_plot->xAxis->range().upper, expected_max);
218 QList<QVariant> arguments = rangeChanged->takeFirst();
219 EXPECT_EQ(arguments.size(), 1);
220 auto reportedRange = arguments.at(0).value<QCPRange>();
221 EXPECT_EQ(reportedRange.lower, 1.0);
222 EXPECT_EQ(reportedRange.upper, 20.0);
224 arguments = rangeChanged2->takeFirst();
225 EXPECT_EQ(arguments.size(), 2);
226 auto newRange = arguments.at(0).value<QCPRange>();
227 auto oldRange = arguments.at(1).value<QCPRange>();
228 EXPECT_EQ(newRange.lower, 1.0);
229 EXPECT_EQ(newRange.upper, 20.0);
230 EXPECT_EQ(oldRange.lower, 1.0);
231 EXPECT_EQ(oldRange.upper, 2.0);
240 auto custom_plot = std::make_unique<QCustomPlot>();
253 EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
255 EXPECT_CALL(widget, onChildPropertyChange(_, _)).Times(0);
256 EXPECT_CALL(widget, onItemInserted(_, _)).Times(0);
257 EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
260 const double expected_max = 20.0;
263 EXPECT_EQ(custom_plot->xAxis->range().lower, 1.0);
264 EXPECT_EQ(custom_plot->xAxis->range().upper, expected_max);
271 auto custom_plot = std::make_unique<QCustomPlot>();
279 auto qcp_axis = custom_plot->xAxis;
284 EXPECT_EQ(qcp_axis->scaleType(), QCPAxis::stLogarithmic);
292 auto custom_plot = std::make_unique<QCustomPlot>();
299 auto qcp_axis = custom_plot->xAxis;
304 EXPECT_EQ(qcp_axis->scaleType(), QCPAxis::stLinear);
310 EXPECT_EQ(qcp_axis->scaleType(), QCPAxis::stLogarithmic);
319 auto custom_plot = std::make_unique<QCustomPlot>();
330 auto xChanged = createSpy(custom_plot->xAxis);
331 auto yChanged = createSpy(custom_plot->yAxis);
334 const double expected_min = 1.0;
335 const double expected_max = 2.0;
340 EXPECT_EQ(xChanged->count(), 0);
341 EXPECT_EQ(yChanged->count(), 2);
342 EXPECT_EQ(custom_plot->yAxis->range().lower, expected_min);
343 EXPECT_EQ(custom_plot->yAxis->range().upper, expected_max);
350 auto custom_plot = std::make_unique<QCustomPlot>();
363 auto controller = std::make_unique<ViewportAxisPlotController>(custom_plot->xAxis);
364 controller->setItem(axis_item0);
365 auto xChanged = createSpy(custom_plot->xAxis);
366 auto yChanged = createSpy(custom_plot->yAxis);
370 custom_plot->xAxis->range().lower);
372 custom_plot->xAxis->range().upper);
375 controller->setItem(axis_item1);
377 EXPECT_EQ(xChanged->count(), 1);
378 EXPECT_EQ(yChanged->count(), 0);
381 custom_plot->xAxis->range().lower);
383 custom_plot->xAxis->range().upper);
386 const double expected_min = 100.0;
387 const double expected_max = 200.0;
388 custom_plot->xAxis->setRange(expected_min, expected_max);
404 custom_plot->xAxis->setRange(1.0, 2.0);
408 custom_plot->xAxis->setRange(2.0, 3.0);
416 auto custom_plot = std::make_unique<QCustomPlot>();
423 auto qcp_axis = custom_plot->xAxis;
434 EXPECT_EQ(qcp_axis->label(), QString(
"abc"));
static const std::string P_MAX
static const std::string P_MIN
void setItem(SessionItem *item)
int childrenCount() const
Returns total number of children in all tags.
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Main class to hold hierarchy of SessionItem objects.
SessionItem * rootItem() const
Returns root item of the model.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
void removeItem(SessionItem *parent, const TagRow &tagrow)
Removes given row from parent.
Represent text item on plot.
static const std::string P_TEXT
Item to represent viewport axis.
static const std::string P_IS_LOG
static const std::string P_TITLE
Establishes communication between QCPAxis and ViewportAxisItem.
Testing AxisPlotControllers.
~ViewportAxisPlotControllerTest()
std::unique_ptr< QSignalSpy > createSpy2(QCPAxis *axis)
std::unique_ptr< QSignalSpy > createSpy(QCPAxis *axis)
materialitems.h Collection of materials to populate MaterialModel.
TEST_F(ViewportAxisPlotControllerTest, initialState)
Initial state.