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

Method curvePointMoveUndoRedo

tests/backend/Datapicker/DatapickerTest.cpp:911–972  ·  view source on GitHub ↗

! * check the correctness of the data point after the point was moved on the scene with undo and redo after this. */

Source from the content-addressed store, hash-verified

909 * check the correctness of the data point after the point was moved on the scene with undo and redo after this.
910 */
911void DatapickerTest::curvePointMoveUndoRedo() {
912 Project project;
913 auto* datapicker = new Datapicker(QStringLiteral("Test"));
914 project.addChild(datapicker);
915 auto* image = datapicker->image();
916
917 // add reference points
918 datapicker->addNewPoint(QPointF(0, 1), image);
919 datapicker->addNewPoint(QPointF(0, 0), image);
920 datapicker->addNewPoint(QPointF(1, 0), image);
921
922 auto ap = image->axisPoints();
923 ap.type = DatapickerImage::GraphType::Linear;
924 image->setAxisPoints(ap);
925
926 // set logical coordinates for the reference points
927 DatapickerImageWidget w(nullptr);
928 w.setImages({image});
929 w.ui.sbPositionX1->setValue(0);
930 w.ui.sbPositionY1->setValue(10);
931 w.ui.sbPositionZ1->setValue(0);
932 w.ui.sbPositionX2->setValue(0);
933 w.ui.sbPositionY2->setValue(0);
934 w.ui.sbPositionZ2->setValue(0);
935 w.ui.sbPositionX3->setValue(10);
936 w.ui.sbPositionY3->setValue(0);
937 w.ui.sbPositionZ3->setValue(0);
938 w.logicalPositionChanged();
939
940 auto* curve = new DatapickerCurve(i18n("Curve"));
941 curve->addDatasheet(image->axisPoints().type);
942 datapicker->addChild(curve);
943
944 // add new curve point and check its logical coordinates
945 datapicker->addNewPoint(QPointF(0.5, 0.6), curve);
946 VALUES_EQUAL(curve->posXColumn()->valueAt(0), 5.);
947 VALUES_EQUAL(curve->posYColumn()->valueAt(0), 6.);
948
949 // move the last added point to a new position and check its logical coordinates again
950 auto points = curve->children<DatapickerPoint>(AbstractAspect::ChildIndexFlag::IncludeHidden);
951 QCOMPARE(points.count(), 1);
952 points[0]->setPosition(QPointF(0.2, 0.9)); // Changing the position of the point
953 VALUES_EQUAL(curve->posXColumn()->valueAt(0), 2.);
954 VALUES_EQUAL(curve->posYColumn()->valueAt(0), 9.);
955
956 // undo the move step and check the position again
957 auto* undoStack = project.undoStack();
958 undoStack->undo();
959 points = curve->children<DatapickerPoint>(AbstractAspect::ChildIndexFlag::IncludeHidden);
960 QCOMPARE(points.count(), 1);
961 QCOMPARE(points[0]->position(), QPointF(0.5, 0.6));
962 VALUES_EQUAL(curve->posXColumn()->valueAt(0), 5.);
963 VALUES_EQUAL(curve->posYColumn()->valueAt(0), 6.);
964
965 // redo the last step and check the position again
966 undoStack->redo();
967 points = curve->children<DatapickerPoint>(AbstractAspect::ChildIndexFlag::IncludeHidden);
968 QCOMPARE(points.count(), 1);

Callers

nothing calls this directly

Calls 15

imageMethod · 0.80
addNewPointMethod · 0.80
setAxisPointsMethod · 0.80
addDatasheetMethod · 0.80
positionMethod · 0.80
QPointFClass · 0.50
addChildMethod · 0.45
setImagesMethod · 0.45
setValueMethod · 0.45
valueAtMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected