File indexing completed on 2024-04-28 03:48:19

0001 /*
0002     File                 : MultiRangeTest_macros.h
0003     Project              : LabPlot
0004     Description          : 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 "MultiRangeTest.h"
0013 
0014 #include "backend/core/Project.h"
0015 #include "backend/core/Workbook.h"
0016 #include "backend/lib/macros.h"
0017 #include "backend/matrix/Matrix.h"
0018 #include "backend/spreadsheet/Spreadsheet.h"
0019 #include "backend/worksheet/Worksheet.h"
0020 #include "backend/worksheet/plots/cartesian/Axis.h"
0021 #include "backend/worksheet/plots/cartesian/CartesianCoordinateSystem.h"
0022 #include "backend/worksheet/plots/cartesian/CartesianPlot.h"
0023 #include "backend/worksheet/plots/cartesian/CartesianPlotPrivate.h"
0024 #include "backend/worksheet/plots/cartesian/XYCurve.h"
0025 #include "backend/worksheet/plots/cartesian/XYEquationCurve.h"
0026 #include "commonfrontend/worksheet/WorksheetView.h"
0027 #include "kdefrontend/dockwidgets/BaseDock.h"
0028 #include "kdefrontend/dockwidgets/XYCurveDock.h"
0029 
0030 #include <QAction>
0031 #include <QComboBox>
0032 #include <QGraphicsSceneWheelEvent>
0033 #include <QUndoStack>
0034 
0035 // ##############################################################################
0036 // #####################  import of LabPlot projects ############################
0037 // ##############################################################################
0038 
0039 #define LOAD_PROJECT                                                                                                                                           \
0040     Project project;                                                                                                                                           \
0041     project.load(QFINDTESTDATA(QLatin1String("data/TestMultiRange.lml")));                                                                                     \
0042     /* check the project tree for the imported project */                                                                                                      \
0043     /* first child of the root folder */                                                                                                                       \
0044     auto* aspect = project.child<AbstractAspect>(0);                                                                                                           \
0045     QVERIFY(aspect != nullptr);                                                                                                                                \
0046     if (aspect)                                                                                                                                                \
0047         QCOMPARE(aspect->name(), QLatin1String("Arbeitsblatt"));                                                                                               \
0048     QVERIFY(aspect->type() == AspectType::Worksheet);                                                                                                          \
0049     auto w = dynamic_cast<Worksheet*>(aspect);                                                                                                                 \
0050     if (!w)                                                                                                                                                    \
0051         return;                                                                                                                                                \
0052                                                                                                                                                                \
0053     auto p1 = dynamic_cast<CartesianPlot*>(aspect->child<CartesianPlot>(0));                                                                                   \
0054     QVERIFY(p1 != nullptr);                                                                                                                                    \
0055     auto p2 = dynamic_cast<CartesianPlot*>(aspect->child<CartesianPlot>(1));                                                                                   \
0056     QVERIFY(p2 != nullptr);                                                                                                                                    \
0057     if (!p1 || !p2)                                                                                                                                            \
0058         return;                                                                                                                                                \
0059                                                                                                                                                                \
0060     auto* view = dynamic_cast<WorksheetView*>(w->view());                                                                                                      \
0061     QVERIFY(view != nullptr);                                                                                                                                  \
0062     view->initActions(); /* needed by SET_CARTESIAN_MOUSE_MODE() */                                                                                            \
0063                                                                                                                                                                \
0064     /* axis selected */                                                                                                                                        \
0065     auto sinCurve = dynamic_cast<XYCurve*>(p1->child<XYCurve>(0));                                                                                             \
0066     QVERIFY(sinCurve != nullptr);                                                                                                                              \
0067     if (!sinCurve)                                                                                                                                             \
0068         return;                                                                                                                                                \
0069     QCOMPARE(sinCurve->name(), QStringLiteral("sinCurve"));                                                                                                    \
0070     auto tanCurve = dynamic_cast<XYCurve*>(p1->child<XYCurve>(1));                                                                                             \
0071     QVERIFY(tanCurve != nullptr);                                                                                                                              \
0072     if (!tanCurve)                                                                                                                                             \
0073         return;                                                                                                                                                \
0074     QCOMPARE(tanCurve->name(), QStringLiteral("tanCurve"));                                                                                                    \
0075     auto logCurve = dynamic_cast<XYCurve*>(p1->child<XYCurve>(2));                                                                                             \
0076     QVERIFY(logCurve != nullptr);                                                                                                                              \
0077     if (!logCurve)                                                                                                                                             \
0078         return;                                                                                                                                                \
0079     QCOMPARE(logCurve->name(), QStringLiteral("logx"));                                                                                                        \
0080                                                                                                                                                                \
0081     auto cosCurve = dynamic_cast<XYCurve*>(p2->child<XYCurve>(0));                                                                                             \
0082     QVERIFY(cosCurve != nullptr);                                                                                                                              \
0083     if (!cosCurve)                                                                                                                                             \
0084         return;                                                                                                                                                \
0085     QCOMPARE(cosCurve->name(), QStringLiteral("cosCurve"));                                                                                                    \
0086                                                                                                                                                                \
0087     auto horAxisP1 = static_cast<Axis*>(p1->child<Axis>(0));                                                                                                   \
0088     QVERIFY(horAxisP1 != nullptr);                                                                                                                             \
0089     QCOMPARE(horAxisP1->orientation() == Axis::Orientation::Horizontal, true);                                                                                 \
0090                                                                                                                                                                \
0091     auto vertAxisP1 = static_cast<Axis*>(p1->child<Axis>(1));                                                                                                  \
0092     QVERIFY(vertAxisP1 != nullptr);                                                                                                                            \
0093     QCOMPARE(vertAxisP1->orientation() == Axis::Orientation::Vertical, true);                                                                                  \
0094                                                                                                                                                                \
0095     auto vertAxis2P1 = static_cast<Axis*>(p1->child<Axis>(2));                                                                                                 \
0096     QVERIFY(vertAxis2P1 != nullptr);                                                                                                                           \
0097     QCOMPARE(vertAxis2P1->orientation() == Axis::Orientation::Vertical, true);                                                                                 \
0098                                                                                                                                                                \
0099     auto vertAxis3P1 = static_cast<Axis*>(p1->child<Axis>(3));                                                                                                 \
0100     QVERIFY(vertAxis3P1 != nullptr);                                                                                                                           \
0101     QCOMPARE(vertAxis3P1->orientation() == Axis::Orientation::Vertical, true);                                                                                 \
0102     QCOMPARE(vertAxis3P1->name(), QStringLiteral("y-axis 1"));                                                                                                 \
0103                                                                                                                                                                \
0104     auto horAxisP2 = static_cast<Axis*>(p2->child<Axis>(0));                                                                                                   \
0105     QVERIFY(horAxisP2 != nullptr);                                                                                                                             \
0106     QCOMPARE(horAxisP2->orientation() == Axis::Orientation::Horizontal, true);
0107 
0108 #define SET_CARTESIAN_MOUSE_MODE(mode)                                                                                                                         \
0109     QAction a(nullptr);                                                                                                                                        \
0110     a.setData(static_cast<int>(mode));                                                                                                                         \
0111     view->cartesianPlotMouseModeChanged(&a);