24 #include "qcustomplot.h"
41 auto custom_plot = std::make_unique<QCustomPlot>();
43 EXPECT_EQ(custom_plot->graphCount(), 0);
50 auto custom_plot = std::make_unique<QCustomPlot>();
59 EXPECT_EQ(custom_plot->graphCount(), 0);
62 EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().lower, 0.0);
63 EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().upper, 1.0);
64 EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().lower, 0.0);
65 EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().upper, 1.0);
72 auto custom_plot = std::make_unique<QCustomPlot>();
80 const std::vector<double> expected_values = {1.0, 2.0, 3.0};
81 const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
83 data_item->setValues(expected_values);
87 controller.
setItem(viewport_item);
90 EXPECT_EQ(custom_plot->graphCount(), 1);
93 EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().lower, expected_centers[0]);
94 EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().upper, expected_centers[2]);
95 EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().lower, expected_values[0]);
96 EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().upper, expected_values[2]);
103 auto custom_plot = std::make_unique<QCustomPlot>();
109 controller.
setItem(viewport_item);
112 EXPECT_EQ(custom_plot->graphCount(), 0);
116 const std::vector<double> expected_values1 = {1.0, 2.0, 3.0};
117 const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
119 data1->setValues(expected_values1);
122 const std::vector<double> expected_values2 = {4.0, 5.0, 6.0};
124 data2->setValues(expected_values2);
130 EXPECT_EQ(custom_plot->graphCount(), 1);
132 graph_item1->setDataItem(data1);
135 EXPECT_EQ(custom_plot->graphCount(), 1);
142 EXPECT_EQ(custom_plot->graphCount(), 2);
145 viewport_item->setViewportToContent();
146 EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().lower, expected_centers[0]);
147 EXPECT_DOUBLE_EQ(custom_plot->xAxis->range().upper, expected_centers[2]);
148 EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().lower, expected_values1[0]);
149 EXPECT_DOUBLE_EQ(custom_plot->yAxis->range().upper, expected_values2[2]);
155 EXPECT_EQ(custom_plot->graphCount(), 1);
162 auto custom_plot = std::make_unique<QCustomPlot>();
168 controller.
setItem(viewport_item);
171 EXPECT_EQ(custom_plot->graphCount(), 0);
175 EXPECT_EQ(custom_plot->graphCount(), 1);
178 EXPECT_EQ(custom_plot->graphCount(), 2);
181 EXPECT_EQ(custom_plot->graphCount(), 3);
190 static std::vector<QCPAbstractPlottable*> findVisible(
const QCustomPlot* custom_plot)
192 std::vector<QCPAbstractPlottable*> output;
193 for (
int i = 0; i < custom_plot->graphCount(); ++i) {
194 if (custom_plot->graph(i)->visible())
195 output.push_back(custom_plot->graph(i));
202 auto custom_plot = std::make_unique<QCustomPlot>();
208 controller.
setItem(viewport_item);
214 EXPECT_EQ(custom_plot->graphCount(), 3);
216 viewport_item->setVisible(std::vector<GraphItem*>{first_plot});
217 EXPECT_EQ(FindVisible::findVisible(custom_plot.get()).size(), 1);
219 viewport_item->setVisible(std::vector<GraphItem*>{second_plot, third_plot});
220 EXPECT_EQ(FindVisible::findVisible(custom_plot.get()).size(), 2);
222 viewport_item->setAllVisible();
223 EXPECT_EQ(FindVisible::findVisible(custom_plot.get()).size(), 3);
230 auto custom_plot = std::make_unique<QCustomPlot>();
239 const std::vector<double> expected_values = {1.0, 2.0, 3.0};
240 const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
242 data_item->setValues(expected_values);
246 controller.
setItem(viewport_item0);
249 EXPECT_EQ(custom_plot->graphCount(), 1);
252 controller.
setItem(viewport_item1);
253 EXPECT_EQ(custom_plot->graphCount(), 0);
260 auto custom_plot = std::make_unique<QCustomPlot>();
267 controller.
setItem(viewport_item);
270 EXPECT_EQ(custom_plot->graphCount(), 0);
274 const std::vector<double> expected_values = {1.0, 2.0, 3.0};
275 const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
277 data1->setValues(expected_values);
290 graph_item->setDataItem(data1);
295 EXPECT_EQ(custom_plot->graphCount(), 1);
305 EXPECT_EQ(custom_plot->graphCount(), 1);
308 EXPECT_EQ(graph_item->dataItem(),
nullptr);
316 EXPECT_EQ(graph_item->dataItem(), data1);
317 EXPECT_EQ(custom_plot->graphCount(), 1);
326 auto custom_plot = std::make_unique<QCustomPlot>();
333 controller.
setItem(viewport_item);
336 EXPECT_EQ(custom_plot->graphCount(), 0);
347 const std::vector<double> expected_values = {1.0, 2.0, 3.0};
348 const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
350 data1->setValues(expected_values);
364 EXPECT_EQ(custom_plot->graphCount(), 1);
374 EXPECT_EQ(viewport_item->graphItems().size(), 0);
376 EXPECT_EQ(custom_plot->graphCount(), 0);
380 EXPECT_EQ(custom_plot->graphCount(), 1);
381 EXPECT_EQ(viewport_item->graphItems().size(), 1);
Testing GraphViewportPlotController.
~GraphViewportPlotControllerTest()
Represents one-dimensional data (axis and values).
T * setAxis(Args &&... args)
Inserts axis of given type.
Item to represent fixed bin axis.
One-dimensional graph representation of Data1DItem.
Data1DItem * dataItem() const
Returns data item linked to the given GraphItem.
void setDataItem(const Data1DItem *item)
Sets link to the data item.
2D viewport specialized for showing multiple GraphItem's.
Establishes communications and mutual updates for GraphViewportItem and QCutomPlot.
void setItem(SessionItem *item)
std::string identifier() const
Returns unique identifier.
Main class to hold hierarchy of SessionItem objects.
T * topItem() const
Returns top item of the given type.
void setUndoRedoEnabled(bool value)
Sets undo/redo either enabled or disabled. By default undo/redo is disabled.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
UndoStackInterface * undoStack() const
Returns command stack to perform undo/redo.
void removeItem(SessionItem *parent, const TagRow &tagrow)
Removes given row from parent.
virtual int index() const =0
virtual void beginMacro(const std::string &name)=0
virtual int count() const =0
virtual void endMacro()=0
static const std::string T_ITEMS
TEST_F(GraphViewportPlotControllerTest, initialState)
Initial state.
materialitems.h Collection of materials to populate MaterialModel.
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.