| 1405 | } |
| 1406 | |
| 1407 | void CartesianPlotTest::columnRemove() { |
| 1408 | Project project; |
| 1409 | |
| 1410 | auto* worksheet = new Worksheet(QStringLiteral("Worksheet")); |
| 1411 | project.addChild(worksheet); |
| 1412 | |
| 1413 | auto* plot = new CartesianPlot(QStringLiteral("plot")); |
| 1414 | worksheet->addChild(plot); |
| 1415 | plot->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created |
| 1416 | plot->setNiceExtend(false); |
| 1417 | |
| 1418 | auto* sheet = new Spreadsheet(QStringLiteral("data"), false); |
| 1419 | project.addChild(sheet); |
| 1420 | sheet->setColumnCount(2); |
| 1421 | |
| 1422 | const auto& columns = sheet->children<Column>(); |
| 1423 | QCOMPARE(columns.count(), 2); |
| 1424 | const auto* xColumn = columns.at(0); |
| 1425 | const auto* yColumn = columns.at(1); |
| 1426 | const auto& xColumnPath = xColumn->path(); |
| 1427 | const auto& yColumnPath = yColumn->path(); |
| 1428 | |
| 1429 | auto* curve = new XYCurve(QStringLiteral("curve")); |
| 1430 | plot->addChild(curve); |
| 1431 | curve->setXColumn(xColumn); |
| 1432 | curve->setYColumn(yColumn); |
| 1433 | |
| 1434 | QSignalSpy xColumnSpy(curve, SIGNAL(xDataChanged())); |
| 1435 | QSignalSpy yColumnSpy(curve, SIGNAL(yDataChanged())); |
| 1436 | |
| 1437 | // remove the second column in the spreadsheet |
| 1438 | // the x-column in the curve is invalidated, the old path is still valid so we can restore later |
| 1439 | sheet->removeColumns(1, 1); |
| 1440 | QCOMPARE(curve->xColumn(), xColumn); |
| 1441 | QCOMPARE(curve->xColumnPath(), xColumnPath); |
| 1442 | QCOMPARE(xColumnSpy.count(), 0); |
| 1443 | |
| 1444 | QCOMPARE(curve->yColumn(), nullptr); |
| 1445 | QCOMPARE(curve->yColumnPath(), yColumnPath); |
| 1446 | QCOMPARE(yColumnSpy.count(), 1); // data changed signal has to be emitted to notify the parent plot |
| 1447 | |
| 1448 | // undo the removal and check again |
| 1449 | project.undoStack()->undo(); |
| 1450 | QCOMPARE(curve->xColumn(), xColumn); |
| 1451 | QCOMPARE(curve->xColumnPath(), xColumnPath); |
| 1452 | QCOMPARE(xColumnSpy.count(), 0); |
| 1453 | |
| 1454 | QCOMPARE(curve->yColumn(), yColumn); |
| 1455 | QCOMPARE(curve->yColumnPath(), yColumnPath); |
| 1456 | QCOMPARE(yColumnSpy.count(), 2); |
| 1457 | } |
| 1458 | |
| 1459 | /*! |
| 1460 | * check the correct restore of the data source column in the plots after the column was removed, |
nothing calls this directly
no test coverage detected