forked from paceholder/nodeeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeConnectionInteraction.hpp
More file actions
68 lines (51 loc) · 1.8 KB
/
Copy pathNodeConnectionInteraction.hpp
File metadata and controls
68 lines (51 loc) · 1.8 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
67
68
#pragma once
#include <memory>
#include <QtCore/QPointF>
#include "Definitions.hpp"
namespace QtNodes {
class AbstractConnectionGraphicsObject;
class AbstractNodeGraphicsObject;
class AbstractQGraphicsScene;
/// Class wraps conecting and disconnecting checks.
/**
* An instance should be created on the stack and destroyed
* automatically when the operation is completed
*/
class NodeConnectionInteraction
{
public:
NodeConnectionInteraction(AbstractNodeGraphicsObject &ngo,
AbstractConnectionGraphicsObject &cgo,
AbstractQGraphicsScene &scene);
/**
* Can connect when following conditions are met:
* 1. Connection 'requires' a port.
* 2. Connection loose end is above the node port.
* 3. Source and target `nodeId`s are different.
* 4. GraphModel permits connection.
*/
bool canConnect(PortIndex *portIndex) const;
/// Creates a new connectino if possible.
/**
* 1. Check conditions from 'canConnect'.
* 2. Creates new connection with `GraphModel::addConnection`.
* 3. Adjust connection geometry.
*/
bool tryConnect() const;
/**
* 1. Delete connection with `GraphModel::deleteConnection`.
* 2. Create a "draft" connection with incomplete `ConnectionId`.
* 3. Repaint both previously connected nodes.
*/
bool disconnect(PortType portToDisconnect) const;
private:
PortType connectionRequiredPort() const;
QPointF connectionEndScenePosition(PortType) const;
QPointF nodePortScenePosition(PortType portType, PortIndex portIndex) const;
PortIndex nodePortIndexUnderScenePoint(PortType portType, QPointF const &p) const;
private:
AbstractNodeGraphicsObject &_ngo;
AbstractConnectionGraphicsObject &_cgo;
AbstractQGraphicsScene &_scene;
};
} // namespace QtNodes