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

0001 /*
0002     File                 : MultiRangeTest2.cpp
0003     Project              : LabPlot
0004     Description          : Second 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 "MultiRangeTest2.h"
0013 #include "MultiRangeTest_macros.h"
0014 
0015 void MultiRangeTest2::autoScaleYAfterZoomInX() {
0016     /* 1) Zoom in X
0017      * 2) Autoscale X
0018      * 3) Check that y also changed! */
0019     LOAD_PROJECT
0020     auto refValues = horAxisP1->tickLabelValues();
0021     horAxisP1->setSelected(true);
0022     SET_CARTESIAN_MOUSE_MODE(CartesianPlot::MouseMode::ZoomXSelection)
0023 
0024     p1->mousePressZoomSelectionMode(QPointF(0.2, -150), 0);
0025     p1->mouseMoveZoomSelectionMode(QPointF(0.6, 100), 0);
0026     p1->mouseReleaseZoomSelectionMode(0);
0027 
0028     CHECK_RANGE(p1, tanCurve, Dimension::X, 0.2, 0.6); // zoom
0029     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.);
0030 
0031     p1->navigate(tanCurve->coordinateSystemIndex(), CartesianPlot::NavigationOperation::ScaleAutoX);
0032 
0033     CHECK_RANGE(p1, tanCurve, Dimension::X, 0., 1.);
0034     CHECK_RANGE(p1, horAxisP1, Dimension::X, 0., 1.); // range is changed in retransform scale
0035 
0036     // retransform of horAxisP1 is done, so the tickLabelValues change back
0037     // to be in the range of 0, 1
0038     COMPARE_DOUBLE_VECTORS(horAxisP1->tickLabelValues(), refValues);
0039 }
0040 
0041 void MultiRangeTest2::autoScaleXAfterZoomInY() {
0042     LOAD_PROJECT
0043     auto refValues = vertAxisP1->tickLabelValues();
0044     vertAxisP1->setSelected(true);
0045     SET_CARTESIAN_MOUSE_MODE(CartesianPlot::MouseMode::ZoomYSelection)
0046 
0047     p1->mousePressZoomSelectionMode(QPointF(0.2, -150), 0);
0048     p1->mouseMoveZoomSelectionMode(QPointF(0.6, 100), 0);
0049     p1->mouseReleaseZoomSelectionMode(0);
0050 
0051     CHECK_RANGE(p1, sinCurve, Dimension::X, 0., 1.);
0052     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0053     CHECK_RANGE(p1, tanCurve, Dimension::X, 0., 1.);
0054     CHECK_RANGE(p1, tanCurve, Dimension::Y, -150., 100.); // zoom
0055     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.);
0056     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0057 
0058     p1->navigate(tanCurve->coordinateSystemIndex(), CartesianPlot::NavigationOperation::ScaleAutoY);
0059 
0060     // retransform of vertAxisP1 is done, so the tickLabelValues change back
0061     COMPARE_DOUBLE_VECTORS(vertAxisP1->tickLabelValues(), refValues);
0062 }
0063 
0064 /*!
0065  * \brief MultiRangeTest2::mouseWheelXAxisApplyToAllX
0066  * If applied to all x is activated, using the mousewheel on a
0067  * selected axis should also execute the mousewheel on other plots
0068  */
0069 void MultiRangeTest2::mouseWheelXAxisApplyToAllX() {
0070     LOAD_PROJECT
0071 
0072     QCOMPARE(w->cartesianPlotActionMode(), Worksheet::CartesianPlotActionMode::ApplyActionToAllX);
0073 
0074     CHECK_RANGE(p1, sinCurve, Dimension::X, 0., 1.);
0075     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0076     CHECK_RANGE(p1, tanCurve, Dimension::X, 0., 1.);
0077     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.); // zoom
0078     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.);
0079     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0080     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0., 1.);
0081     CHECK_RANGE(p2, cosCurve, Dimension::X, 0., 1.);
0082     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0083 
0084     horAxisP1->setSelected(true); // seems not to work
0085     view->m_selectedElement = horAxisP1;
0086 
0087     int counter = 0;
0088     connect(p1,
0089             &CartesianPlot::wheelEventSignal,
0090             [&counter](const QPointF& relScenePos, int delta, int xIndex, int /*yIndex*/, bool considerDimension, Dimension dim) {
0091                 QCOMPARE(delta, 10);
0092                 QCOMPARE(xIndex, 0); // x Range of horAxisP1
0093                 QCOMPARE(relScenePos.x(), 0.5);
0094                 QCOMPARE(relScenePos.y(), 0.5);
0095                 QCOMPARE(considerDimension, true);
0096                 QCOMPARE(dim, Dimension::X);
0097                 counter++;
0098             });
0099 
0100     QGraphicsSceneWheelEvent event;
0101     event.setDelta(10);
0102     event.setPos(QPointF(p1->dataRect().center().x(), p1->dataRect().center().y()));
0103     p1->d_func()->wheelEvent(&event);
0104 
0105     QCOMPARE(counter, 1);
0106 
0107     // All x ranges are zoomed, for plot 1 and plot 2
0108     CHECK_RANGE(p1, sinCurve, Dimension::X, 0.1, 0.9); // zoom
0109     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0110     CHECK_RANGE(p1, tanCurve, Dimension::X, 0.1, 0.9); // zoom
0111     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.);
0112     CHECK_RANGE(p1, logCurve, Dimension::X, 10., 90.); // zoom
0113     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0114     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0.1, 0.9);
0115     CHECK_RANGE(p2, cosCurve, Dimension::X, 0.1, 0.9);
0116     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0117 }
0118 
0119 /*!
0120  * \brief MultiRangeTest2::mouseWheelXAxisApplyToAllX
0121  * If applied to all x is activated, using the mousewheel on a
0122  * selected axis should also execute the mousewheel on other plots
0123  * This time the second x axis is used. In the second plot no second x axis is used
0124  * so check that application does not crash
0125  */
0126 void MultiRangeTest2::mouseWheelTanCurveApplyToAllX() {
0127     LOAD_PROJECT
0128 
0129     QCOMPARE(w->cartesianPlotActionMode(), Worksheet::CartesianPlotActionMode::ApplyActionToAllX);
0130 
0131     CHECK_RANGE(p1, sinCurve, Dimension::X, 0., 1.);
0132     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0133     CHECK_RANGE(p1, tanCurve, Dimension::X, 0., 1.);
0134     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.); // zoom
0135     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.);
0136     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0137     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0., 1.);
0138     CHECK_RANGE(p2, cosCurve, Dimension::X, 0., 1.);
0139     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0140 
0141     tanCurve->setSelected(true); // seems not to work
0142     view->m_selectedElement = tanCurve;
0143 
0144     int counter = 0;
0145     connect(p1,
0146             &CartesianPlot::wheelEventSignal,
0147             [&counter](const QPointF& relScenePos, int delta, int xIndex, int yIndex, bool considerDimension, Dimension dim) {
0148                 Q_UNUSED(yIndex);
0149                 Q_UNUSED(dim);
0150                 QCOMPARE(relScenePos.x(), 0.5);
0151                 QCOMPARE(relScenePos.y(), 0.5);
0152                 QCOMPARE(delta, 10);
0153                 QCOMPARE(xIndex, 0); // tan curve has xIndex 0
0154                 QCOMPARE(considerDimension, false);
0155                 counter++;
0156             });
0157 
0158     QGraphicsSceneWheelEvent event;
0159     event.setDelta(10);
0160     event.setPos(QPointF(p1->dataRect().center().x(), p1->dataRect().center().y()));
0161     p1->d_func()->wheelEvent(&event);
0162 
0163     QCOMPARE(counter, 1);
0164 
0165     // All x ranges are zoomed, for plot 1 and plot 2
0166     CHECK_RANGE(p1, sinCurve, Dimension::X, 0.1, 0.9); // zoom
0167     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0168     CHECK_RANGE(p1, tanCurve, Dimension::X, 0.1, 0.9); // zoom
0169     // zoomed in, because with scrolling both axes are scrolled
0170     CHECK_RANGE(p1, tanCurve, Dimension::Y, -200., 200.);
0171     CHECK_RANGE(p1, logCurve, Dimension::X, 10., 90.); // zoom
0172     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0173     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0.1, 0.9);
0174     CHECK_RANGE(p2, cosCurve, Dimension::X, 0.1, 0.9);
0175     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0176 }
0177 
0178 void MultiRangeTest2::mouseWheelXAxisApplyToSelected() {
0179     LOAD_PROJECT
0180 
0181     w->setCartesianPlotActionMode(Worksheet::CartesianPlotActionMode::ApplyActionToSelection);
0182     QCOMPARE(w->cartesianPlotActionMode(), Worksheet::CartesianPlotActionMode::ApplyActionToSelection);
0183 
0184     CHECK_RANGE(p1, sinCurve, Dimension::X, 0., 1.);
0185     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0186     CHECK_RANGE(p1, tanCurve, Dimension::X, 0., 1.);
0187     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.); // zoom
0188     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.);
0189     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0190     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0., 1.);
0191     CHECK_RANGE(p2, cosCurve, Dimension::X, 0., 1.);
0192     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0193 
0194     horAxisP1->setSelected(true); // seems not to work
0195     view->m_selectedElement = horAxisP1;
0196 
0197     int counter = 0;
0198     connect(p1,
0199             &CartesianPlot::wheelEventSignal,
0200             [&counter](const QPointF& sceneRelPos, int delta, int xIndex, int /*yIndex*/, bool considerDimension, Dimension dim) {
0201                 Q_UNUSED(sceneRelPos);
0202                 QCOMPARE(delta, 10);
0203                 QCOMPARE(xIndex, 0); // x Range of horAxisP1
0204                 QCOMPARE(considerDimension, true);
0205                 QCOMPARE(dim, Dimension::X);
0206                 counter++;
0207             });
0208 
0209     QGraphicsSceneWheelEvent event;
0210     event.setDelta(10);
0211     event.setPos(QPointF(p1->dataRect().center().x(), p1->dataRect().center().y()));
0212     p1->d_func()->wheelEvent(&event);
0213 
0214     QCOMPARE(counter, 1);
0215 
0216     CHECK_RANGE(p1, sinCurve, Dimension::X, 0.1, 0.9); // zoom
0217     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0218     CHECK_RANGE(p1, tanCurve, Dimension::X, 0.1, 0.9); // zoom
0219     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.);
0220     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.); // Not zoomed
0221     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0222     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0., 1.); // Not zoomed
0223     CHECK_RANGE(p2, cosCurve, Dimension::X, 0., 1.); // Not zoomed
0224     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0225 }
0226 
0227 void MultiRangeTest2::axisMouseMoveApplyToAllX() {
0228     LOAD_PROJECT
0229 
0230     w->setCartesianPlotActionMode(Worksheet::CartesianPlotActionMode::ApplyActionToAllX);
0231     QCOMPARE(w->cartesianPlotActionMode(), Worksheet::CartesianPlotActionMode::ApplyActionToAllX);
0232 
0233     CHECK_RANGE(p1, sinCurve, Dimension::X, 0., 1.);
0234     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0235     CHECK_RANGE(p1, tanCurve, Dimension::X, 0., 1.);
0236     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.);
0237     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.);
0238     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0239     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0., 1.);
0240     CHECK_RANGE(p2, cosCurve, Dimension::X, 0., 1.);
0241     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0242 
0243     const int delta = -10; // delta > 0 --> right or up
0244     horAxisP1->shiftSignal(delta, Dimension::X, p1->coordinateSystem(horAxisP1->coordinateSystemIndex())->index(Dimension::X));
0245 
0246     CHECK_RANGE(p1, sinCurve, Dimension::X, 0.1, 1.1); // shift
0247     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0248     CHECK_RANGE(p1, tanCurve, Dimension::X, 0.1, 1.1); // shift
0249     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.);
0250     CHECK_RANGE(p1, logCurve, Dimension::X, 10., 110.); // shift
0251     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0252     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0.1, 1.1); // shift
0253     CHECK_RANGE(p2, cosCurve, Dimension::X, 0.1, 1.1); // shift
0254     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0255 }
0256 
0257 void MultiRangeTest2::axisMouseMoveApplyToSelection() {
0258     LOAD_PROJECT
0259 
0260     w->setCartesianPlotActionMode(Worksheet::CartesianPlotActionMode::ApplyActionToSelection);
0261     QCOMPARE(w->cartesianPlotActionMode(), Worksheet::CartesianPlotActionMode::ApplyActionToSelection);
0262 
0263     CHECK_RANGE(p1, sinCurve, Dimension::X, 0., 1.);
0264     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0265     CHECK_RANGE(p1, tanCurve, Dimension::X, 0., 1.);
0266     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.);
0267     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.);
0268     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0269     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0., 1.);
0270     CHECK_RANGE(p2, cosCurve, Dimension::X, 0., 1.);
0271     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0272 
0273     const int delta = -10; // delta > 0 --> right or up
0274     horAxisP1->shiftSignal(delta, Dimension::X, p1->coordinateSystem(horAxisP1->coordinateSystemIndex())->index(Dimension::X));
0275 
0276     CHECK_RANGE(p1, sinCurve, Dimension::X, 0.1, 1.1); // shift
0277     CHECK_RANGE(p1, sinCurve, Dimension::Y, -1., 1.);
0278     CHECK_RANGE(p1, tanCurve, Dimension::X, 0.1, 1.1); // shift
0279     CHECK_RANGE(p1, tanCurve, Dimension::Y, -250., 250.);
0280     CHECK_RANGE(p1, logCurve, Dimension::X, 0., 100.);
0281     CHECK_RANGE(p1, logCurve, Dimension::Y, -10., 6.);
0282     CHECK_RANGE(p2, horAxisP1, Dimension::X, 0., 1.);
0283     CHECK_RANGE(p2, cosCurve, Dimension::X, 0., 1.);
0284     CHECK_RANGE(p2, cosCurve, Dimension::Y, -1., 1.);
0285 }
0286 
0287 QTEST_MAIN(MultiRangeTest2)