| 24 | #include <QUndoStack> |
| 25 | |
| 26 | void XYFunctionCurveTest::setCurves() { |
| 27 | Project project; |
| 28 | auto* ws = new Worksheet(QStringLiteral("Worksheet")); |
| 29 | QVERIFY(ws != nullptr); |
| 30 | project.addChild(ws); |
| 31 | |
| 32 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 33 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created |
| 34 | QVERIFY(p != nullptr); |
| 35 | ws->addChild(p); |
| 36 | |
| 37 | p->addChild(new XYEquationCurve(QLatin1String("eq"))); |
| 38 | |
| 39 | auto equationCurves = p->children(AspectType::XYEquationCurve); |
| 40 | QCOMPARE(equationCurves.count(), 1); |
| 41 | auto* equationCurve = static_cast<XYEquationCurve*>(equationCurves.at(0)); |
| 42 | XYEquationCurve::EquationData data; |
| 43 | data.count = 100; |
| 44 | data.expression1 = QStringLiteral("x"); |
| 45 | data.expression2 = QString(); |
| 46 | data.min = QStringLiteral("1"); |
| 47 | data.max = QStringLiteral("100"); |
| 48 | data.type = XYEquationCurve::EquationType::Cartesian; |
| 49 | equationCurve->setEquationData(data); |
| 50 | |
| 51 | QCOMPARE(equationCurve->xColumn()->rowCount(), data.count); |
| 52 | |
| 53 | p->addChild(new XYFunctionCurve(QLatin1String("eq2"))); |
| 54 | auto functionCurves = p->children(AspectType::XYFunctionCurve); |
| 55 | QCOMPARE(functionCurves.count(), 1); |
| 56 | auto* functionCurve = static_cast<XYFunctionCurve*>(functionCurves.at(0)); |
| 57 | |
| 58 | auto dock = XYFunctionCurveDock(nullptr); |
| 59 | dock.setupGeneral(); |
| 60 | dock.setCurves({functionCurve}); |
| 61 | |
| 62 | functionCurve->setFunction(QStringLiteral("2*x"), {QStringLiteral("x")}, {equationCurve}); |
| 63 | |
| 64 | { |
| 65 | const auto* xColumn = functionCurve->xColumn(); |
| 66 | const auto* yColumn = functionCurve->yColumn(); |
| 67 | QCOMPARE(xColumn->rowCount(), data.count); |
| 68 | QCOMPARE(yColumn->rowCount(), data.count); |
| 69 | for (int i = 0; i < xColumn->rowCount(); i++) { |
| 70 | VALUES_EQUAL(xColumn->valueAt(i), i + 1.); |
| 71 | VALUES_EQUAL(yColumn->valueAt(i), (i + 1.) * 2.); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | functionCurve->undoStack()->undo(); |
| 76 | |
| 77 | QCOMPARE(functionCurve->xColumn()->rowCount(), 0); |
| 78 | |
| 79 | functionCurve->undoStack()->redo(); |
| 80 | |
| 81 | { |
| 82 | const auto* xColumn = functionCurve->xColumn(); |
| 83 | const auto* yColumn = functionCurve->yColumn(); |
no test coverage detected