| 295 | } |
| 296 | |
| 297 | void XYFunctionCurveTest::saveLoad() { |
| 298 | QString savePath; |
| 299 | { |
| 300 | Project project; |
| 301 | auto* ws = new Worksheet(QStringLiteral("Worksheet")); |
| 302 | QVERIFY(ws != nullptr); |
| 303 | project.addChild(ws); |
| 304 | |
| 305 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 306 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created |
| 307 | QVERIFY(p != nullptr); |
| 308 | ws->addChild(p); |
| 309 | |
| 310 | p->addChild(new XYEquationCurve(QLatin1String("eq"))); |
| 311 | |
| 312 | auto equationCurves = p->children(AspectType::XYEquationCurve); |
| 313 | QCOMPARE(equationCurves.count(), 1); |
| 314 | auto* equationCurve = static_cast<XYEquationCurve*>(equationCurves.at(0)); |
| 315 | XYEquationCurve::EquationData data; |
| 316 | data.count = 100; |
| 317 | data.expression1 = QStringLiteral("x"); |
| 318 | data.expression2 = QString(); |
| 319 | data.min = QStringLiteral("1"); |
| 320 | data.max = QStringLiteral("100"); |
| 321 | data.type = XYEquationCurve::EquationType::Cartesian; |
| 322 | equationCurve->setEquationData(data); |
| 323 | |
| 324 | QCOMPARE(equationCurve->xColumn()->rowCount(), data.count); |
| 325 | |
| 326 | p->addChild(new XYFunctionCurve(QLatin1String("eq2"))); |
| 327 | auto functionCurves = p->children(AspectType::XYFunctionCurve); |
| 328 | QCOMPARE(functionCurves.count(), 1); |
| 329 | auto* functionCurve = static_cast<XYFunctionCurve*>(functionCurves.at(0)); |
| 330 | |
| 331 | auto dock = XYFunctionCurveDock(nullptr); |
| 332 | dock.setupGeneral(); |
| 333 | dock.setCurves({functionCurve}); |
| 334 | |
| 335 | functionCurve->setFunction(QStringLiteral("2*z"), {QStringLiteral("z")}, {equationCurve}); |
| 336 | |
| 337 | { |
| 338 | const auto* xColumn = functionCurve->xColumn(); |
| 339 | const auto* yColumn = functionCurve->yColumn(); |
| 340 | QCOMPARE(xColumn->rowCount(), data.count); |
| 341 | QCOMPARE(yColumn->rowCount(), data.count); |
| 342 | for (int i = 0; i < xColumn->rowCount(); i++) { |
| 343 | VALUES_EQUAL(xColumn->valueAt(i), i + 1.); |
| 344 | VALUES_EQUAL(yColumn->valueAt(i), (i + 1.) * 2.); |
| 345 | } |
| 346 | } |
| 347 | SAVE_PROJECT("TestXYFunctionCurveSaveLoad"); |
| 348 | } |
| 349 | |
| 350 | { |
| 351 | Project project; |
| 352 | QCOMPARE(project.load(savePath), true); |
| 353 | |
| 354 | const auto* ws = project.child<Worksheet>(0); |
nothing calls this directly
no test coverage detected