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

Method columnRemove

tests/cartesianplot/CartesianPlotTest.cpp:1407–1457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1405}
1406
1407void 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,

Callers

nothing calls this directly

Calls 11

setNiceExtendMethod · 0.80
setYColumnMethod · 0.80
addChildMethod · 0.45
setTypeMethod · 0.45
setColumnCountMethod · 0.45
countMethod · 0.45
pathMethod · 0.45
setXColumnMethod · 0.45
removeColumnsMethod · 0.45
undoMethod · 0.45
undoStackMethod · 0.45

Tested by

no test coverage detected