|
| 1 | +#include <nodes/Connection> |
| 2 | +#include <nodes/FlowScene> |
| 3 | +#include <nodes/FlowView> |
| 4 | +#include <nodes/Node> |
| 5 | + |
| 6 | +#include <catch.hpp> |
| 7 | + |
| 8 | +#include <QtTest> |
| 9 | +#include <QtWidgets/QApplication> |
| 10 | + |
| 11 | +#include <iostream> |
| 12 | + |
| 13 | +#include "ApplicationSetup.hpp" |
| 14 | +#include "Stringify.hpp" |
| 15 | +#include "StubNodeDataModel.hpp" |
| 16 | + |
| 17 | +using QtNodes::Connection; |
| 18 | +using QtNodes::DataModelRegistry; |
| 19 | +using QtNodes::FlowScene; |
| 20 | +using QtNodes::FlowView; |
| 21 | +using QtNodes::Node; |
| 22 | +using QtNodes::NodeData; |
| 23 | +using QtNodes::NodeDataModel; |
| 24 | +using QtNodes::NodeDataType; |
| 25 | +using QtNodes::PortIndex; |
| 26 | +using QtNodes::PortType; |
| 27 | + |
| 28 | +TEST_CASE("Dragging node changes position", "[gui]") |
| 29 | +{ |
| 30 | + auto app = applicationSetup(); |
| 31 | + |
| 32 | + FlowScene scene; |
| 33 | + FlowView view(&scene); |
| 34 | + |
| 35 | + view.show(); |
| 36 | + REQUIRE(QTest::qWaitForWindowExposed(&view)); |
| 37 | + |
| 38 | + SECTION("just one node") |
| 39 | + { |
| 40 | + auto& node = scene.createNode(std::make_unique<StubNodeDataModel>()); |
| 41 | + |
| 42 | + auto& ngo = node.nodeGraphicsObject(); |
| 43 | + |
| 44 | + QPointF scPosBefore = ngo.pos(); |
| 45 | + |
| 46 | + QPointF scClickPos = ngo.boundingRect().center(); |
| 47 | + scClickPos = QPointF(ngo.sceneTransform().map(scClickPos).toPoint()); |
| 48 | + |
| 49 | + QPoint vwClickPos = view.mapFromScene(scClickPos); |
| 50 | + QPoint vwDestPos = vwClickPos + QPoint(10, 20); |
| 51 | + |
| 52 | + QPointF scExpectedDelta = view.mapToScene(vwDestPos) - scClickPos; |
| 53 | + |
| 54 | + CAPTURE(scClickPos); |
| 55 | + CAPTURE(vwClickPos); |
| 56 | + CAPTURE(vwDestPos); |
| 57 | + CAPTURE(scExpectedDelta); |
| 58 | + |
| 59 | + QTest::mouseMove(view.windowHandle(), vwClickPos); |
| 60 | + QTest::mousePress(view.windowHandle(), Qt::LeftButton, Qt::NoModifier, vwClickPos); |
| 61 | + QTest::mouseMove(view.windowHandle(), vwDestPos); |
| 62 | + |
| 63 | + QPointF scDelta = ngo.pos() - scPosBefore; |
| 64 | + QPoint roundDelta = scDelta.toPoint(); |
| 65 | + QPoint roundExpectedDelta = scExpectedDelta.toPoint(); |
| 66 | + |
| 67 | + CHECK(roundDelta == roundExpectedDelta); |
| 68 | + } |
| 69 | +} |
0 commit comments