| 1166 | } |
| 1167 | |
| 1168 | void CartesianPlotTest::wheelEventOutsideTopLeft() { |
| 1169 | Project project; |
| 1170 | |
| 1171 | auto* worksheet = new Worksheet(QStringLiteral("Worksheet")); |
| 1172 | project.addChild(worksheet); |
| 1173 | auto* view = dynamic_cast<WorksheetView*>(worksheet->view()); |
| 1174 | QVERIFY(view != nullptr); |
| 1175 | view->initMenus(); // needed by SET_CARTESIAN_MOUSE_MODE() |
| 1176 | |
| 1177 | auto* plot = new CartesianPlot(QStringLiteral("plot")); |
| 1178 | worksheet->addChild(plot); |
| 1179 | plot->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created |
| 1180 | plot->setNiceExtend(false); |
| 1181 | plot->setHorizontalPadding(Worksheet::convertToSceneUnits(1.5, Worksheet::Unit::Centimeter)); |
| 1182 | plot->setVerticalPadding(Worksheet::convertToSceneUnits(1.5, Worksheet::Unit::Centimeter)); |
| 1183 | plot->setRightPadding(Worksheet::convertToSceneUnits(1.5, Worksheet::Unit::Centimeter)); |
| 1184 | plot->setBottomPadding(Worksheet::convertToSceneUnits(1.5, Worksheet::Unit::Centimeter)); |
| 1185 | |
| 1186 | auto* equationCurve{new XYEquationCurve(QStringLiteral("f(x)"))}; |
| 1187 | equationCurve->setCoordinateSystemIndex(plot->defaultCoordinateSystemIndex()); |
| 1188 | plot->addChild(equationCurve); |
| 1189 | |
| 1190 | XYEquationCurve::EquationData data; |
| 1191 | data.min = QStringLiteral("0"); |
| 1192 | data.max = QStringLiteral("10"); |
| 1193 | data.count = 10; |
| 1194 | data.expression1 = QStringLiteral("x"); |
| 1195 | equationCurve->setEquationData(data); |
| 1196 | equationCurve->recalculate(); |
| 1197 | |
| 1198 | CHECK_RANGE(plot, equationCurve, Dimension::X, 0., 10.); |
| 1199 | CHECK_RANGE(plot, equationCurve, Dimension::Y, 0., 10.); |
| 1200 | |
| 1201 | plot->m_zoomFactor = 2; |
| 1202 | plot->setNiceExtend(false); |
| 1203 | const auto& rect = plot->dataRect(); |
| 1204 | |
| 1205 | int signalEmittedCounter = 0; |
| 1206 | connect(plot, |
| 1207 | &CartesianPlot::wheelEventSignal, |
| 1208 | [&signalEmittedCounter](const QPointF& sceneRelPos, int delta, int xIndex, int yIndex, bool considerDimension, Dimension dim) { |
| 1209 | signalEmittedCounter++; |
| 1210 | QCOMPARE(sceneRelPos.x(), -0.2); |
| 1211 | QCOMPARE(sceneRelPos.y(), 1.3); |
| 1212 | QVERIFY(delta > 0); |
| 1213 | Q_UNUSED(xIndex); |
| 1214 | Q_UNUSED(yIndex); |
| 1215 | QCOMPARE(considerDimension, false); |
| 1216 | Q_UNUSED(dim); |
| 1217 | }); |
| 1218 | |
| 1219 | QGraphicsSceneWheelEvent event; |
| 1220 | event.setPos(QPointF(rect.left() - 140, rect.top() - 210)); |
| 1221 | event.setDelta(10); // value not important, only sign |
| 1222 | plot->d_func()->wheelEvent(&event); |
| 1223 | CHECK_RANGE(plot, equationCurve, Dimension::X, -1., 4.); |
| 1224 | CHECK_RANGE(plot, equationCurve, Dimension::Y, 6.5, 11.5); |
| 1225 | QCOMPARE(signalEmittedCounter, 1); |
nothing calls this directly
no test coverage detected