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

Method importDataComplexDependency

tests/backend/XYCurve/XYFunctionCurveTest.cpp:470–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468}
469
470void XYFunctionCurveTest::importDataComplexDependency() {
471 Project project;
472 auto* ws = new Worksheet(QStringLiteral("Worksheet"));
473 QVERIFY(ws != nullptr);
474 project.addChild(ws);
475
476 auto* p = new CartesianPlot(QStringLiteral("plot"));
477 p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
478 QVERIFY(p != nullptr);
479 ws->addChild(p);
480
481 // Generate data and
482 Spreadsheet* sheet = new Spreadsheet(QStringLiteral("Spreadsheet"), false);
483 project.addChild(sheet);
484 sheet->setColumnCount(2);
485 sheet->setRowCount(11);
486 sheet->column(0)->setColumnMode(AbstractColumn::ColumnMode::Double);
487 sheet->column(1)->setColumnMode(AbstractColumn::ColumnMode::Double);
488
489 for (int i = 0; i < sheet->rowCount(); i++) {
490 sheet->column(0)->setValueAt(i, i);
491 sheet->column(1)->setValueAt(i, 2 * i + 1);
492 }
493
494 QCOMPARE(sheet->column(0)->name(), QStringLiteral("1"));
495 QCOMPARE(sheet->column(1)->name(), QStringLiteral("2"));
496
497 auto* curve = new XYCurve(QStringLiteral("curve1"));
498 p->addChild(curve);
499 curve->setCoordinateSystemIndex(0);
500 curve->setXColumn(sheet->column(0));
501 curve->setYColumn(sheet->column(1));
502
503 p->addChild(new XYFunctionCurve(QLatin1String("eq2")));
504 auto functionCurves = p->children(AspectType::XYFunctionCurve);
505 QCOMPARE(functionCurves.count(), 1);
506 auto* functionCurve1 = static_cast<XYFunctionCurve*>(functionCurves.at(0));
507 // First function curve check
508 {
509 auto dock = XYFunctionCurveDock(nullptr);
510 dock.setupGeneral();
511 dock.setCurves({functionCurve1});
512
513 functionCurve1->setFunction(QStringLiteral("2*x"), {QStringLiteral("x")}, {curve});
514
515 {
516 const auto* xColumn = functionCurve1->xColumn();
517 const auto* yColumn = functionCurve1->yColumn();
518 QCOMPARE(xColumn->rowCount(), 11);
519 QCOMPARE(yColumn->rowCount(), 11);
520 for (int i = 0; i < xColumn->rowCount(); i++) {
521 VALUES_EQUAL(xColumn->valueAt(i), (double)i);
522 VALUES_EQUAL(yColumn->valueAt(i), 2 * (2 * i + 1.));
523 }
524 }
525 }
526
527 p->addChild(new XYFunctionCurve(QLatin1String("eq3")));

Callers

nothing calls this directly

Calls 15

setYColumnMethod · 0.80
setFunctionMethod · 0.80
setPropertiesMethod · 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

Tested by

no test coverage detected