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
65 lines (49 loc) · 1.89 KB
/
TestNodeGraphicsObject.cpp
File metadata and controls
65 lines (49 loc) · 1.89 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
#include "ApplicationSetup.hpp"
#include "StubNodeDataModel.hpp"
#include <QtNodes/FlowScene>
#include <QtNodes/FlowView>
#include <QtNodes/Node>
#include <QtNodes/NodeDataModel>
#include <catch2/catch.hpp>
#include <QtTest>
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);
}