-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample.qml
77 lines (65 loc) · 1.67 KB
/
Sample.qml
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
69
70
71
72
73
74
75
76
77
import QtQuick 2.15
import NodeGraph 1.0
Item {
id: root
width: 1200
height: 800
layer.enabled: true
layer.samples: 4
Background {
anchors.fill: parent
color: Qt.vector4d(0.35, 0.35, 0.35, 1)
color2: Qt.vector4d(0.3, 0.3, 0.3, 1)
}
NodeGraph {
id: graph
width: Math.max(8000, root.width)
height: Math.max(4000, root.height)
}
focus: true
Keys.onPressed: {
if (event.key == Qt.Key_Delete)
graph.removeSelectedNodes()
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: {
addNode("Node", mouseX, mouseY, 5)
}
}
function addNode(name, x, y, attributes) {
const node = graph.addNode({
name: name,
x: x,
y: y,
})
for (let i = 0; i < attributes; i++)
node.addAttribute({
name: "Attribute " + (i + 1),
hasInput: i < attributes / 2,
hasOutput: i > attributes / 4,
})
return node
}
Component.onCompleted: {
let nodes = []
for (let i = 0; i < 10; ++i)
nodes.push(addNode("Node " + i,
100 + (i % 5) * 200,
50 + Math.floor(i / 5) * 300,
(i * 13) % 8 + 3))
function rand(max) {
return Math.floor(Math.random() * max)
}
for (let i = 0; i < nodes.length - 1; ++i) {
let node0 = nodes[i]
let node1 = nodes[i == 4 ? 9 : i + 1]
for (let j = 0; j < 8; j++) {
let attribute0 = node0.attributes.itemAt(rand(node0.attributes.count))
let attribute1 = node1.attributes.itemAt(rand(node1.attributes.count))
graph.addLink(attribute0, attribute1)
}
}
}
}