-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathGraphEditor.qml
More file actions
executable file
·1584 lines (1386 loc) · 67.6 KB
/
GraphEditor.qml
File metadata and controls
executable file
·1584 lines (1386 loc) · 67.6 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Controls 1.0
import MaterialIcons 2.2
import Utils 1.0
/**
* A component displaying a Graph (nodes, attributes and edges).
*/
Item {
id: root
property variant uigraph: null /// Meshroom UI graph (UIGraph)
readonly property variant graph: uigraph ? uigraph.graph : null /// Core graph contained in the UI graph
property variant nodeTypesModel: null /// The list of node types that can be instantiated
property real maxZoom: 2.0
property real minZoom: 0.1
property var edgeAboutToBeRemoved: undefined
property var _attributeToDelegate: ({})
// Signals
signal workspaceMoved()
signal workspaceClicked()
signal nodeDoubleClicked(var mouse, var node)
signal computeRequest(var nodes)
signal submitRequest(var nodes)
property int nbMeshroomScenes: 0
property int nbDraggedFiles: 0
signal filesDropped(var drop, var mousePosition) // Files have been dropped
// Trigger initial fit() after initialization
// (ensure GraphEditor has its final size)
Component.onCompleted: firstFitTimer.start()
Timer {
id: firstFitTimer
running: false
interval: 10
onTriggered: fit()
}
clip: true
SystemPalette { id: activePalette }
/// Get node delegate for the given node object
function nodeDelegate(node) {
for(var i = 0; i < nodeRepeater.count; ++i) {
if (nodeRepeater.getItemAt(i).node === node)
return nodeRepeater.getItemAt(i)
}
return undefined
}
/// Duplicate a node and optionally all the following ones
function duplicateNode(duplicateFollowingNodes) {
var nodes
if (duplicateFollowingNodes) {
nodes = uigraph.duplicateNodesFrom(uigraph.getSelectedNodes())
} else {
nodes = uigraph.duplicateNodes(uigraph.getSelectedNodes())
}
uigraph.selectedNode = nodes[0]
uigraph.selectNodes(nodes)
}
/// Copy node content to clipboard
function copyNodes() {
var nodeContent = uigraph.getSelectedNodesContent()
if (nodeContent !== '') {
Clipboard.clear()
Clipboard.setText(nodeContent)
}
}
/// Paste content of clipboard to graph editor and create new node if valid
function pasteNodes() {
let finalPosition = undefined
if (mouseArea.containsMouse) {
finalPosition = mapToItem(draggable, mouseArea.mouseX, mouseArea.mouseY)
} else {
finalPosition = getCenterPosition()
}
const copiedContent = Clipboard.getText()
const nodes = uigraph.pasteNodes(copiedContent, finalPosition)
if (nodes.length > 0) {
uigraph.selectedNode = nodes[0]
uigraph.selectNodes(nodes)
}
}
/// Get the coordinates of the point at the center of the GraphEditor
function getCenterPosition() {
return mapToItem(draggable, mouseArea.width / 2, mouseArea.height / 2)
}
Keys.onPressed: function(event) {
if (event.key === Qt.Key_F) {
fit()
} else if (event.key === Qt.Key_Delete) {
if (event.modifiers === Qt.AltModifier) {
uigraph.removeNodesFrom(uigraph.getSelectedNodes())
} else {
uigraph.removeSelectedNodes()
}
} else if (event.key === Qt.Key_D) {
duplicateNode(event.modifiers === Qt.AltModifier)
} else if (event.key === Qt.Key_X) {
if (event.modifiers === Qt.ControlModifier) {
copyNodes()
uigraph.removeSelectedNodes()
}
else {
uigraph.disconnectSelectedNodes()
}
} else if (event.key === Qt.Key_C) {
if (event.modifiers === Qt.ControlModifier) {
copyNodes()
}
else {
colorSelector.toggle()
}
} else if (event.key === Qt.Key_V && event.modifiers === Qt.ControlModifier) {
pasteNodes()
} else if (event.key === Qt.Key_V && event.modifiers === Qt.ShiftModifier) {
uigraph.alignVertically()
} else if (event.key === Qt.Key_H && event.modifiers === Qt.ShiftModifier) {
uigraph.alignHorizontally()
} else if (event.key === Qt.Key_Tab) {
event.accepted = true
if (mouseArea.containsMouse) {
newNodeMenu.spawnPosition = mouseArea.mapToItem(draggable, mouseArea.mouseX, mouseArea.mouseY)
newNodeMenu.popup()
}
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
property double factor: 1.15
property bool removingEdges: false
// Activate multisampling for edges antialiasing
layer.enabled: true
layer.samples: 8
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
drag.threshold: 0
drag.smoothed: false
cursorShape: drag.target == draggable ? Qt.ClosedHandCursor : removingEdges ? Qt.CrossCursor : Qt.ArrowCursor
onWheel: function(wheel) {
var zoomFactor = wheel.angleDelta.y > 0 ? factor : 1 / factor
var scale = draggable.scale * zoomFactor
scale = Math.min(Math.max(minZoom, scale), maxZoom)
if (draggable.scale == scale)
return
var point = mapToItem(draggable, wheel.x, wheel.y)
draggable.x += (1 - zoomFactor) * point.x * draggable.scale
draggable.y += (1 - zoomFactor) * point.y * draggable.scale
draggable.scale = scale
workspaceMoved()
}
onPressed: function(mouse) {
if (mouse.button != Qt.MiddleButton && mouse.modifiers == Qt.NoModifier) {
uigraph.clearNodeSelection()
}
if (mouse.button == Qt.LeftButton && (mouse.modifiers == Qt.NoModifier || mouse.modifiers & (Qt.ControlModifier | Qt.ShiftModifier))) {
nodeSelectionBox.startSelection(mouse)
}
if (mouse.button == Qt.MiddleButton || (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.AltModifier)) {
drag.target = draggable // start drag
}
if (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier) && (mouse.modifiers & Qt.AltModifier)) {
edgeSelectionLine.startSelection(mouse)
removingEdges = true
}
}
onReleased: {
removingEdges = false
edgeSelectionLine.endSelection()
nodeSelectionBox.endSelection()
drag.target = null
root.forceActiveFocus()
workspaceClicked()
}
onPositionChanged: {
if (drag.active)
workspaceMoved()
}
onClicked: function(mouse) {
if (mouse.button == Qt.RightButton) {
// Store mouse click position in 'draggable' coordinates as new node spawn position
newNodeMenu.spawnPosition = mouseArea.mapToItem(draggable, mouse.x, mouse.y)
newNodeMenu.popup()
}
}
// Contextual Menu for creating new nodes
// TODO: add filtering + validate on 'Enter'
Menu {
id: newNodeMenu
property point spawnPosition
property variant menuKeys: Object.keys(root.nodeTypesModel).concat(Object.values(MeshroomApp.pipelineTemplateNames))
height: searchBar.height + nodeMenuRepeater.height + instantiator.height
function createNode(nodeType) {
// "nodeType" might be a pipeline (artificially added in the "Pipelines" category) instead of a node
// If it is not a pipeline to import, then it must be a node
if (!importPipeline(nodeType)) {
// Add node via the proper command in uigraph
var node = uigraph.addNewNode(nodeType, spawnPosition)
uigraph.selectedNode = node
uigraph.selectNodes([node])
}
close()
}
function importPipeline(pipeline) {
if (MeshroomApp.pipelineTemplateNames.includes(pipeline)) {
var url = MeshroomApp.pipelineTemplateFiles[MeshroomApp.pipelineTemplateNames.indexOf(pipeline)]["path"]
var nodes = uigraph.importProject(Filepath.stringToUrl(url), spawnPosition)
uigraph.selectedNode = nodes[0]
uigraph.selectNodes(nodes)
return true
}
return false
}
function parseCategories() {
// Organize nodes based on their category
// {"category1": ["node1", "node2"], "category2": ["node3", "node4"]}
let categories = {}
for (const [name, data] of Object.entries(root.nodeTypesModel)) {
let category = data["category"]
if (categories[category] === undefined) {
categories[category] = []
}
categories[category].push(name)
}
// Add a "Pipelines" category, filled with the list of templates to create pipelines from the menu
if (MeshroomApp.pipelineTemplateNames.length > 0) {
categories["Pipelines"] = MeshroomApp.pipelineTemplateNames
}
return categories
}
onVisibleChanged: {
searchBar.clear()
if (visible) {
// When menu is shown, give focus to the TextField filter
searchBar.forceActiveFocus()
}
}
SearchBar {
id: searchBar
width: parent.width
}
// menuItemDelegate is wrapped in a component so it can be used in both the search bar and sub-menus
Component {
id: menuItemDelegateComponent
MenuItem {
id: menuItemDelegate
font.pointSize: 8
padding: 3
// Hide items that does not match the filter text
visible: modelData.toLowerCase().indexOf(searchBar.text.toLowerCase()) > -1
text: modelData
// Forward key events to the search bar to continue typing seamlessly
// even if this delegate took the activeFocus due to mouse hovering
Keys.forwardTo: [searchBar.textField]
Keys.onPressed: function(event) {
event.accepted = false
switch (event.key) {
case Qt.Key_Return:
case Qt.Key_Enter:
// Create node on validation (Enter/Return keys)
newNodeMenu.createNode(modelData)
event.accepted = true
break
case Qt.Key_Up:
case Qt.Key_Down:
case Qt.Key_Left:
case Qt.Key_Right:
break // Ignore if arrow key was pressed to let the menu be controlled
default:
searchBar.forceActiveFocus()
}
}
// Set the priority ordering of the keys to be Item's own Key Handling > ForwardTo
Keys.priority: Keys.AfterItem
// Create node on mouse click
onClicked: newNodeMenu.createNode(modelData)
states: [
State {
// Additional property setting when the MenuItem is not visible
when: !visible
name: "invisible"
PropertyChanges {
target: menuItemDelegate
height: 0 // Make sure the item is no visible by setting height to 0
focusPolicy: Qt.NoFocus // Don't grab focus when not visible
}
}
]
}
}
Repeater {
id: nodeMenuRepeater
model: searchBar.text !== "" ? Object.values(newNodeMenu.menuKeys) : undefined
// Create Menu items from available items
delegate: menuItemDelegateComponent
}
// Dynamically add the menu categories
Instantiator {
id: instantiator
model: (searchBar.text === "") ? Object.keys(newNodeMenu.parseCategories()).sort() : undefined
onObjectAdded: function(index, object) {
// Add sub-menu under the search bar
newNodeMenu.insertMenu(index + 1, object)
}
onObjectRemoved: function(index, object) {
newNodeMenu.removeMenu(object)
}
delegate: Menu {
title: modelData
id: newNodeSubMenu
Instantiator {
model: newNodeMenu.visible ? newNodeMenu.parseCategories()[modelData] : undefined
onObjectAdded: function(index, object) {
newNodeSubMenu.insertItem(index, object)
}
onObjectRemoved: function(index, object) {
newNodeSubMenu.removeItem(object)
}
delegate: menuItemDelegateComponent
}
}
}
}
// Informative contextual menu when graph is read-only
Menu {
id: lockedMenu
MenuItem {
id: item
font.pointSize: 8
enabled: false
text: "Computing - Graph is Locked!"
}
}
Item {
id: draggable
transformOrigin: Item.TopLeft
width: 1000
height: 1000
Popup {
id: edgeMenu
property var currentEdge: null
property bool forLoop: false
onOpened: {
expandButton.canExpand = uigraph.canExpandForLoop(edgeMenu.currentEdge)
}
contentItem: Row {
IntSelector {
id: loopIterationSelector
tooltipText: "Iterations"
visible: edgeMenu.currentEdge && edgeMenu.forLoop
enabled: expandButton.canExpand
property var listAttr: edgeMenu.currentEdge ? edgeMenu.currentEdge.src.root : null
Connections {
target: edgeMenu
function onCurrentEdgeChanged() {
if (edgeMenu.currentEdge) {
loopIterationSelector.listAttr = edgeMenu.currentEdge.src.root
loopIterationSelector.value = loopIterationSelector.listAttr ? loopIterationSelector.listAttr.value.indexOf(edgeMenu.currentEdge.src) + 1 : 0
}
}
}
// We add 1 to the index because of human readable index (starting at 1)
value: listAttr ? listAttr.value.indexOf(edgeMenu.currentEdge.src) + 1 : 0
range: { "min": 1, "max": listAttr ? listAttr.value.count : 0 }
onValueChanged: {
if (listAttr === null) {
return
}
const newSrcAttr = listAttr.value.at(value - 1)
const dst = edgeMenu.currentEdge.dst
// If the edge exists, do not replace it
if (newSrcAttr === edgeMenu.currentEdge.src && dst === edgeMenu.currentEdge.dst) {
return
}
edgeMenu.currentEdge = uigraph.replaceEdge(edgeMenu.currentEdge, newSrcAttr, dst)
}
}
MaterialToolButton {
font.pointSize: 13
ToolTip.text: "Remove Edge"
enabled: edgeMenu.currentEdge && !edgeMenu.currentEdge.dst.node.locked && !edgeMenu.currentEdge.dst.isReadOnly
text: MaterialIcons.delete_
onClicked: {
uigraph.removeEdge(edgeMenu.currentEdge)
edgeMenu.close()
}
}
MaterialToolButton {
id: expandButton
property bool canExpand: edgeMenu.currentEdge && edgeMenu.forLoop
visible: edgeMenu.currentEdge && edgeMenu.forLoop && canExpand
enabled: edgeMenu.currentEdge && !edgeMenu.currentEdge.dst.node.locked && !edgeMenu.currentEdge.dst.isReadOnly
font.pointSize: 13
ToolTip.text: "Expand"
text: MaterialIcons.open_in_full
onClicked: {
edgeMenu.currentEdge = uigraph.expandForLoop(edgeMenu.currentEdge)
canExpand = false
edgeMenu.close()
}
}
MaterialToolButton {
id: collapseButton
visible: edgeMenu.currentEdge && edgeMenu.forLoop && !expandButton.canExpand
enabled: edgeMenu.currentEdge && !edgeMenu.currentEdge.dst.node.locked && !edgeMenu.currentEdge.dst.isReadOnly
font.pointSize: 13
ToolTip.text: "Collapse"
text: MaterialIcons.close_fullscreen
onClicked: {
uigraph.collapseForLoop(edgeMenu.currentEdge)
expandButton.canExpand = true
edgeMenu.close()
}
}
}
}
// Edges
Repeater {
id: edgesRepeater
// Delay edges loading after nodes (edges needs attribute pins to be created)
model: nodeRepeater.loaded && root.graph ? root.graph.edges : undefined
delegate: Edge {
function getAttributePin(attribute) {
// Get the first visible parent of "attribute"
let dstAttributeDelegate = root._attributeToDelegate[attribute]
if (dstAttributeDelegate && dstAttributeDelegate.visible) {
return dstAttributeDelegate
}
if (!attribute || !attribute.root) {
return null
}
let index = Array.from(attribute.root.value).indexOf(attribute)
let groupAttributeDelegate = null
let groupAttribute = attribute
while (groupAttribute && (!groupAttributeDelegate ||
(groupAttributeDelegate && !groupAttributeDelegate.visible && groupAttribute && groupAttribute.root))) {
groupAttribute = groupAttribute ? groupAttribute.root : null
if (groupAttribute) {
groupAttributeDelegate = root._attributeToDelegate[groupAttribute]
}
}
if (groupAttributeDelegate) {
return groupAttributeDelegate
}
return dstAttributeDelegate
}
property var src: getAttributePin(edge.src)
property var dst: getAttributePin(edge.dst)
property bool isValidEdge: src !== null && dst !== null
visible: isValidEdge && src.visible && dst.visible
property bool forLoop: {
if (src !== null && dst !== null) {
return src.attribute.type === "ListAttribute" && dst.attribute.type != "ListAttribute"
}
return false
}
property bool inFocus: containsMouse || (edgeMenu.opened && edgeMenu.currentEdge === edge)
edge: object
isForLoop: forLoop
loopSize: forLoop ? edge.src.root.value.count : 0
iteration: forLoop ? edge.src.root.value.indexOf(edge.src) : 0
color: edge.dst === root.edgeAboutToBeRemoved ? "red" : inFocus ? activePalette.highlight : activePalette.text
thickness: {
if (forLoop) {
return (inFocus) ? 4 : 3
}
return (inFocus) ? 2 : 1
}
point1x: isValidEdge ? src.globalX + src.outputAnchorPos.x : 0
point1y: isValidEdge ? src.globalY + src.outputAnchorPos.y : 0
point2x: isValidEdge ? dst.globalX + dst.inputAnchorPos.x : 0
point2y: isValidEdge ? dst.globalY + dst.inputAnchorPos.y : 0
onPressed: function(event) {
const canEdit = !edge.dst.node.locked
if (event.button) {
if (canEdit && (event.modifiers & Qt.AltModifier)) {
uigraph.removeEdge(edge)
} else if (event.button == Qt.RightButton) {
edgeMenu.currentEdge = edge
edgeMenu.forLoop = forLoop
var spawnPosition = mouseArea.mapToItem(draggable, mouseArea.mouseX, mouseArea.mouseY)
edgeMenu.x = spawnPosition.x
edgeMenu.y = spawnPosition.y
edgeMenu.open()
}
}
}
}
}
Loader {
id: nodeMenuLoader
property var currentNode: null
active: currentNode != null
sourceComponent: nodeMenuComponent
function load(node) {
currentNode = node
}
function unload() {
currentNode = null
}
function showDataDeletionDialog(deleteFollowing: bool, callback) {
uigraph.forceNodesStatusUpdate()
const dialog = deleteDataDialog.createObject(
root,
{
"node": currentNode,
"deleteFollowing": deleteFollowing
}
)
dialog.open()
if(callback)
dialog.dataDeleted.connect(callback)
}
}
Component {
id: nodeMenuComponent
Menu {
id: nodeMenu
property var currentNode: nodeMenuLoader.currentNode
// Cache computatibility/submitability status of each selected node.
readonly property var nodeSubmitOrComputeStatus: {
var collectedStatus = ({})
uigraph.nodeSelection.selectedIndexes.forEach(function(idx) {
const node = uigraph.graph.nodes.at(idx.row)
collectedStatus[node] = uigraph.graph.canSubmitOrCompute(node)
})
return collectedStatus
}
readonly property bool isSelectionFullyComputed: {
return uigraph.nodeSelection.selectedIndexes.every(function(idx) {
const node = uigraph.graph.nodes.at(idx.row)
return node.isComputed
})
}
// Selection contains only compatibility nodes
readonly property bool isSelectionFullyCompatibility: {
return uigraph.nodeSelection.selectedIndexes.every(function(idx) {
const node = uigraph.graph.nodes.at(idx.row)
return node.isCompatibilityNode
})
}
// Selection contains at least one computable node type
readonly property bool selectionContainsComputableNodeType: {
return uigraph.nodeSelection.selectedIndexes.some(function(idx) {
const node = uigraph.graph.nodes.at(idx.row)
return node.isComputableType
})
}
readonly property bool canSelectionBeComputed: {
if(!selectionContainsComputableNodeType)
return false
if(isSelectionFullyCompatibility)
return false
if(isSelectionFullyComputed)
return true
var b = uigraph.nodeSelection.selectedIndexes.every(function(idx) {
const node = uigraph.graph.nodes.at(idx.row)
return (
node.isComputed ||
(uigraph.graph.canComputeTopologically(node) &&
// canCompute if canSubmitOrCompute == 1(can compute) or 3(can compute & submit)
nodeSubmitOrComputeStatus[node] % 2 == 1)
)
})
return b
}
readonly property bool isSelectionSubmitable: uigraph.canSubmit && selectionContainsComputableNodeType
readonly property bool canSelectionBeSubmitted: {
if(!selectionContainsComputableNodeType)
return false
if(isSelectionFullyCompatibility)
return false
if(isSelectionFullyComputed)
return true
return uigraph.nodeSelection.selectedIndexes.every(function(idx) {
const node = uigraph.graph.nodes.at(idx.row)
return (
node.isComputed ||
(uigraph.graph.canComputeTopologically(node) &&
// canSubmit if canSubmitOrCompute == 2(can submit) or 3(can compute & submit)
nodeSubmitOrComputeStatus[node] > 1)
)
})
}
width: 220
Component.onCompleted: popup()
onClosed: nodeMenuLoader.unload()
MenuItem {
id: computeMenuItem
text: nodeMenu.isSelectionFullyComputed ? "Re-Compute" : "Compute"
visible: nodeMenu.selectionContainsComputableNodeType
height: visible ? implicitHeight : 0
enabled: nodeMenu.canSelectionBeComputed
onTriggered: {
if (nodeMenu.isSelectionFullyComputed) {
nodeMenuLoader.showDataDeletionDialog(
false,
function(request, uigraph) {
request(uigraph.getSelectedNodes())
}.bind(null, computeRequest, uigraph)
)
} else {
computeRequest(uigraph.getSelectedNodes())
}
}
}
MenuItem {
id: submitMenuItem
text: nodeMenu.isSelectionFullyComputed ? "Re-Submit" : "Submit"
visible: nodeMenu.isSelectionSubmitable
height: visible ? implicitHeight : 0
enabled: nodeMenu.canSelectionBeSubmitted
onTriggered: {
if (nodeMenu.isSelectionFullyComputed) {
nodeMenuLoader.showDataDeletionDialog(
false,
function(request, uigraph) {
request(uigraph.getSelectedNodes())
}.bind(null, submitRequest, uigraph)
)
} else {
submitRequest(uigraph.getSelectedNodes())
}
}
}
MenuItem {
text: "Stop Computation"
enabled: nodeMenu.currentNode.canBeStopped() && nodeMenu.currentNode.globalExecMode == "LOCAL"
visible: enabled
height: visible ? implicitHeight : 0
onTriggered: uigraph.stopNodeComputation(nodeMenu.currentNode)
}
MenuItem {
text: "Cancel Computation"
enabled: nodeMenu.currentNode.canBeCanceled() && nodeMenu.currentNode.globalExecMode == "LOCAL"
visible: enabled
height: visible ? implicitHeight : 0
onTriggered: uigraph.cancelNodeComputation(nodeMenu.currentNode)
}
MenuItem {
text: "Interrupt Job"
enabled: nodeMenu.currentNode.canBeStopped() && nodeMenu.currentNode.globalExecMode == "EXTERN"
visible: enabled
height: visible ? implicitHeight : 0
onTriggered: uigraph.stopNode(nodeMenu.currentNode)
}
MenuItem {
text: "Cancel Job"
enabled: nodeMenu.currentNode.canBeCanceled() && nodeMenu.currentNode.globalExecMode == "EXTERN"
visible: enabled
height: visible ? implicitHeight : 0
onTriggered: uigraph.stopNode(nodeMenu.currentNode)
}
MenuItem {
text: "Retry Error Tasks"
enabled: nodeMenu.currentNode.globalExecMode == "EXTERN" && ["ERROR", "STOPPED", "KILLED"].includes(nodeMenu.currentNode.globalStatus)
visible: enabled
height: visible ? implicitHeight : 0
onTriggered: uigraph.restartJobErrorTasks(nodeMenu.currentNode)
}
MenuItem {
text: "Open Folder"
visible: nodeMenu.currentNode.isComputableType
height: visible ? implicitHeight : 0
onTriggered: Qt.openUrlExternally(Filepath.stringToUrl(nodeMenu.currentNode.internalFolder))
}
MenuSeparator {
visible: nodeMenu.currentNode.isComputableType
}
MenuItem {
text: "Cut Node(s)"
enabled: true
ToolTip.text: "Copy selection to the clipboard and remove it"
ToolTip.visible: hovered
onTriggered: {
copyNodes()
uigraph.removeSelectedNodes()
}
}
MenuItem {
text: "Copy Node(s)"
enabled: true
ToolTip.text: "Copy selection to the clipboard"
ToolTip.visible: hovered
onTriggered: copyNodes()
}
MenuItem {
text: "Paste Node(s)"
enabled: true
ToolTip.text: "Copy selection to the clipboard and immediately paste it"
ToolTip.visible: hovered
onTriggered: {
copyNodes()
pasteNodes()
}
}
MenuItem {
text: "Disconnect Node(s)"
enabled: true
ToolTip.text: "Disconnect all edges from the selected Node(s)"
ToolTip.visible: hovered
onTriggered: uigraph.disconnectSelectedNodes()
}
MenuItem {
text: "Duplicate Node(s)" + (duplicateFollowingButton.hovered ? " From Here" : "")
enabled: true
onTriggered: duplicateNode(false)
MaterialToolButton {
id: duplicateFollowingButton
height: parent.height
anchors {
right: parent.right
rightMargin: parent.padding
}
text: MaterialIcons.fast_forward
onClicked: {
duplicateNode(true)
nodeMenu.close()
}
}
}
MenuItem {
text: "Remove Node(s)" + (removeFollowingButton.hovered ? " From Here" : "")
enabled: !nodeMenu.currentNode.locked
onTriggered: uigraph.removeSelectedNodes()
MaterialToolButton {
id: removeFollowingButton
height: parent.height
anchors {
right: parent.right
rightMargin: parent.padding
}
text: MaterialIcons.fast_forward
onClicked: {
uigraph.removeNodesFrom(uigraph.getSelectedNodes())
nodeMenu.close()
}
}
}
MenuSeparator {
visible: nodeMenu.currentNode.isComputableType
}
MenuItem {
id: deleteDataMenuItem
text: "Delete Data" + (deleteFollowingButton.hovered ? " From Here" : "" ) + "..."
visible: nodeMenu.currentNode.isComputableType
height: visible ? implicitHeight : 0
enabled: {
if (!nodeMenu.currentNode)
return false
// Check if the current node is locked (needed because it does not belong to its own duplicates list)
if (nodeMenu.currentNode.locked)
return false
// Check if at least one of the duplicate nodes is locked
for (let i = 0; i < nodeMenu.currentNode.duplicates.count; ++i) {
if (nodeMenu.currentNode.duplicates.at(i).locked)
return false
}
return true
}
onTriggered: nodeMenuLoader.showDataDeletionDialog(false)
MaterialToolButton {
id: deleteFollowingButton
anchors {
right: parent.right
rightMargin: parent.padding
}
height: parent.height
text: MaterialIcons.fast_forward
onClicked: {
nodeMenuLoader.showDataDeletionDialog(true)
nodeMenu.close()
}
}
}
}
}
// Confirmation dialog for node cache deletion
Component {
id: deleteDataDialog
MessageDialog {
property var node
property bool deleteFollowing: false
signal dataDeleted()
focus: true
modal: false
header.visible: false
text: "Delete Data of '" + node.label + "'" + (uigraph.nodeSelection.selectedIndexes.length > 1 ? " and other selected Nodes" : "") + (deleteFollowing ? " and following Nodes?" : "?")
helperText: "Warning: This operation cannot be undone."
standardButtons: Dialog.Yes | Dialog.Cancel
onAccepted: {
if (deleteFollowing)
uigraph.clearDataFrom(uigraph.getSelectedNodes())
else
uigraph.clearSelectedNodesData()
dataDeleted()
}
onClosed: destroy()
}
}
// Nodes
Repeater {
id: nodeRepeater
model: root.graph ? root.graph.nodes : undefined
property bool loaded: model ? count === model.count : false
property bool ongoingDrag: false
property bool updateSelectionOnClick: false
property var temporaryEdgeAboutToBeRemoved: undefined
function getItemAt(index) {
const loader = itemAt(index)
if (loader && loader.item)
return loader.item
return null
}
delegate: Loader {
id: nodeLoader
Component {
id: nodeComponent
Node {
id: nodeDelegate
node: object
width: uigraph.layout.nodeWidth
mainSelected: uigraph.selectedNode === node
hovered: uigraph.hoveredNode === node
// ItemSelectionModel.hasSelection triggers updates anytime the selectionChanged() signal is emitted.
selected: uigraph.nodeSelection.hasSelection ? uigraph.nodeSelection.isRowSelected(index) : false
onAttributePinCreated: function(attribute, pin) { registerAttributePin(attribute, pin) }
onAttributePinDeleted: function(attribute, pin) { unregisterAttributePin(attribute, pin) }
onShaked: {
uigraph.disconnectSelectedNodes()
}
onPressed: function(mouse) {
nodeRepeater.updateSelectionOnClick = true
nodeRepeater.ongoingDrag = true
let selectionMode = ItemSelectionModel.NoUpdate
if (!selected) {
selectionMode = ItemSelectionModel.ClearAndSelect
}
if (mouse.button === Qt.LeftButton) {
if (mouse.modifiers & Qt.ShiftModifier) {
selectionMode = ItemSelectionModel.Select
}
if (mouse.modifiers & Qt.ControlModifier) {
selectionMode = ItemSelectionModel.Toggle
}
if (mouse.modifiers & Qt.AltModifier) {
let selectFollowingMode = ItemSelectionModel.ClearAndSelect
if (mouse.modifiers & Qt.ShiftModifier) {
selectFollowingMode = ItemSelectionModel.Select
}
uigraph.selectFollowing(node, selectFollowingMode)
// Indicate selection has been dealt with by setting conservative Select mode.
selectionMode = ItemSelectionModel.Select
}
}
else if (mouse.button === Qt.RightButton) {
if (selected) {
// Keep the full selection when right-clicking on an already selected node.
nodeRepeater.updateSelectionOnClick = false
}
}
if (selectionMode != ItemSelectionModel.NoUpdate) {
nodeRepeater.updateSelectionOnClick = false
uigraph.selectNodeByIndex(index, selectionMode)
}
// If the node is selected after this, make it the active selected node.
if (selected) {
uigraph.selectedNode = node
}
// Open the node context menu once selection has been updated.
if (mouse.button == Qt.RightButton) {
nodeMenuLoader.load(node)
}
}
onReleased: function(mouse, wasDragged) {
nodeRepeater.ongoingDrag = false
}
// Only called when the node has not been dragged.
onClicked: function(mouse) {
if (!nodeRepeater.updateSelectionOnClick) {
return