| 390 | } |
| 391 | |
| 392 | void 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"), |
nothing calls this directly
no test coverage detected