MCPcopy Create free account
hub / github.com/KDE/labplot / importData

Method importData

tests/backend/XYCurve/XYFunctionCurveTest.cpp:392–468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392void XYFunctionCurveTest::importData() {
393 Project project;
394 auto* ws = new Worksheet(QStringLiteral("Worksheet"));
395 QVERIFY(ws != nullptr);
396 project.addChild(ws);
397
398 auto* p = new CartesianPlot(QStringLiteral("plot"));
399 p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
400 QVERIFY(p != nullptr);
401 ws->addChild(p);
402
403 // Generate data and
404 Spreadsheet* sheet = new Spreadsheet(QStringLiteral("Spreadsheet"), false);
405 project.addChild(sheet);
406 sheet->setColumnCount(2);
407 sheet->setRowCount(11);
408 sheet->column(0)->setColumnMode(AbstractColumn::ColumnMode::Double);
409 sheet->column(1)->setColumnMode(AbstractColumn::ColumnMode::Double);
410
411 for (int i = 0; i < sheet->rowCount(); i++) {
412 sheet->column(0)->setValueAt(i, i);
413 sheet->column(1)->setValueAt(i, 2 * i + 1);
414 }
415
416 QCOMPARE(sheet->column(0)->name(), QStringLiteral("1"));
417 QCOMPARE(sheet->column(1)->name(), QStringLiteral("2"));
418
419 auto* curve = new XYCurve(QStringLiteral("curve1"));
420 p->addChild(curve);
421 curve->setCoordinateSystemIndex(0);
422 curve->setXColumn(sheet->column(0));
423 curve->setYColumn(sheet->column(1));
424
425 p->addChild(new XYFunctionCurve(QLatin1String("eq2")));
426 auto functionCurves = p->children(AspectType::XYFunctionCurve);
427 QCOMPARE(functionCurves.count(), 1);
428 auto* functionCurve = static_cast<XYFunctionCurve*>(functionCurves.at(0));
429
430 auto dock = XYFunctionCurveDock(nullptr);
431 dock.setupGeneral();
432 dock.setCurves({functionCurve});
433
434 functionCurve->setFunction(QStringLiteral("2*x"), {QStringLiteral("x")}, {curve});
435
436 {
437 const auto* xColumn = functionCurve->xColumn();
438 const auto* yColumn = functionCurve->yColumn();
439 QCOMPARE(xColumn->rowCount(), 11);
440 QCOMPARE(yColumn->rowCount(), 11);
441 for (int i = 0; i < xColumn->rowCount(); i++) {
442 VALUES_EQUAL(xColumn->valueAt(i), (double)i);
443 VALUES_EQUAL(yColumn->valueAt(i), 2 * (2 * i + 1.));
444 }
445 }
446
447 QStringList fileContent = {
448 QStringLiteral("1,2"),
449 QStringLiteral("7,99"),

Callers

nothing calls this directly

Calls 15

setYColumnMethod · 0.80
setFunctionMethod · 0.80
XYFunctionCurveDockClass · 0.50
addChildMethod · 0.45
setTypeMethod · 0.45
setColumnCountMethod · 0.45
setRowCountMethod · 0.45
setColumnModeMethod · 0.45
columnMethod · 0.45
rowCountMethod · 0.45
setValueAtMethod · 0.45

Tested by

no test coverage detected