forked from paceholder/nodeeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNodeGraphicsObject.cpp
More file actions
66 lines (50 loc) · 1.81 KB
/
TestNodeGraphicsObject.cpp
File metadata and controls
66 lines (50 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <nodes/FlowScene>
#include <nodes/FlowView>
#include <nodes/Node>
#include <nodes/NodeDataModel>
#include <catch2/catch.hpp>
#include <QtTest>
#include "ApplicationSetup.hpp"
#include "StubNodeDataModel.hpp"
using QtNodes::FlowScene;
using QtNodes::FlowView;
using QtNodes::Node;
using QtNodes::NodeDataModel;
using QtNodes::NodeGraphicsObject;
using QtNodes::PortType;
TEST_CASE("NodeDataModel::portOutConnectionPolicy(...) isn't called for input "
"connections (issue #127)",
"[gui]")
{
class MockModel : public StubNodeDataModel
{
public:
unsigned int nPorts(PortType) const override { return 1; }
NodeDataModel::ConnectionPolicy
portOutConnectionPolicy(int index) const override
{
portOutConnectionPolicyCalledCount++;
return NodeDataModel::ConnectionPolicy::One;
}
mutable int portOutConnectionPolicyCalledCount = 0;
};
auto setup = applicationSetup();
FlowScene scene;
FlowView view(&scene);
// Ensure we have enough size to contain the node
view.resize(640, 480);
view.show();
REQUIRE(QTest::qWaitForWindowExposed(&view));
auto& node = scene.createNode(std::make_unique<MockModel>());
auto& model = dynamic_cast<MockModel&>(*node.nodeDataModel());
auto& ngo = node.nodeGraphicsObject();
auto& ngeom = node.nodeGeometry();
// Move the node to somewhere in the middle of the screen
ngo.setPos(QPointF(50, 50));
// Compute the on-screen position of the input port
QPointF scInPortPos = ngeom.portScenePosition(0, PortType::In, ngo.sceneTransform());
QPoint vwInPortPos = view.mapFromScene(scInPortPos);
// Create a partial connection by clicking on the input port of the node
QTest::mousePress(view.windowHandle(), Qt::LeftButton, Qt::NoModifier, vwInPortPos);
CHECK(model.portOutConnectionPolicyCalledCount == 0);
}