File indexing completed on 2024-09-29 03:31:30

0001 /*
0002     File                 : MultiRangeTest3.cpp
0003     Project              : LabPlot
0004     Description          : Third tests for multi ranges
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2021 Martin Marmsoler <martin.marmsoler@gmail.com>
0007     SPDX-FileCopyrightText: 2021 Stefan Gerlach <stefan.gerlach@uni.kn>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #include "MultiRangeTest3.h"
0013 #include "MultiRangeTest_macros.h"
0014 
0015 void MultiRangeTest3::baseDockSetAspects_NoPlotRangeChange() {
0016     LOAD_PROJECT
0017 
0018     const int sinCurveCSystemIndex = sinCurve->coordinateSystemIndex();
0019     const int tanCurveCSystemIndex = tanCurve->coordinateSystemIndex();
0020     QVERIFY(sinCurveCSystemIndex != tanCurveCSystemIndex);
0021     // checks directly the plot. In the basedock the element is used and not the plot, so do it here too
0022     QVERIFY(sinCurve->coordinateSystemCount() == 3);
0023 
0024     XYCurveDock dock(nullptr);
0025     dock.setupGeneral();
0026     dock.setCurves(QList<XYCurve*>({sinCurve, tanCurve}));
0027 
0028     dock.updatePlotRangeList();
0029 
0030     // The coordinatesystem indices shall not change
0031     QCOMPARE(sinCurveCSystemIndex, sinCurve->coordinateSystemIndex());
0032     QCOMPARE(tanCurveCSystemIndex, tanCurve->coordinateSystemIndex());
0033 }
0034 
0035 /*!
0036  * \brief MultiRangeTest3::curveRangeChange
0037  * When changing the coordinatesystem of an object like a curve, the
0038  * curve shall be updated accordingly also for undo/redo
0039  */
0040 void MultiRangeTest3::curveRangeChange() {
0041     Project project;
0042     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0043     QVERIFY(ws != nullptr);
0044     project.addChild(ws);
0045 
0046     auto* plot = new CartesianPlot(QStringLiteral("plot"));
0047     QVERIFY(plot != nullptr);
0048     ws->addChild(plot);
0049 
0050     auto* curve{new XYEquationCurve(QStringLiteral("f(x)"))};
0051     curve->setCoordinateSystemIndex(plot->defaultCoordinateSystemIndex());
0052     plot->addChild(curve);
0053 
0054     XYEquationCurve::EquationData data;
0055     data.min = QStringLiteral("0");
0056     data.max = QStringLiteral("10");
0057     data.count = 100;
0058     data.expression1 = QStringLiteral("sin(x*2*pi*3)");
0059     curve->setEquationData(data);
0060     curve->recalculate();
0061 
0062     CHECK_RANGE(plot, curve, Dimension::X, 0., 10.);
0063     CHECK_RANGE(plot, curve, Dimension::Y, -1., 1.);
0064 
0065     // Create new cSystem
0066     Range<double> yRange;
0067     yRange.setFormat(RangeT::Format::Numeric);
0068     yRange.setAutoScale(false);
0069     yRange.setRange(0, 10);
0070     plot->addYRange(yRange);
0071     CartesianCoordinateSystem* cSystem = new CartesianCoordinateSystem(plot);
0072     cSystem->setIndex(Dimension::X, 0);
0073     cSystem->setIndex(Dimension::Y, 1);
0074     plot->addCoordinateSystem(cSystem);
0075 
0076     QCOMPARE(plot->coordinateSystemCount(), 2);
0077     QCOMPARE(plot->coordinateSystem(1), cSystem);
0078 
0079     CHECK_RANGE(plot, curve, Dimension::X, 0., 10.);
0080     CHECK_RANGE(plot, curve, Dimension::Y, -1., 1.);
0081 
0082     curve->setCoordinateSystemIndex(1);
0083 
0084     CHECK_RANGE(plot, curve, Dimension::X, 0., 10.);
0085     CHECK_RANGE(plot, curve, Dimension::Y, 0., 10.);
0086 
0087     curve->undoStack()->undo();
0088 
0089     QCOMPARE(curve->coordinateSystemIndex(), 0);
0090     CHECK_RANGE(plot, curve, Dimension::X, 0., 10.);
0091     CHECK_RANGE(plot, curve, Dimension::Y, -1., 1.);
0092 
0093     curve->undoStack()->redo();
0094 
0095     QCOMPARE(curve->coordinateSystemIndex(), 1);
0096     CHECK_RANGE(plot, curve, Dimension::X, 0., 10.);
0097     CHECK_RANGE(plot, curve, Dimension::Y, 0., 10.);
0098 }
0099 
0100 QTEST_MAIN(MultiRangeTest3)