Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images flickable has performance bug #187

Merged
merged 8 commits into from
Feb 5, 2024
9 changes: 6 additions & 3 deletions resources/Core/I_Scene.qml
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,22 @@ QSObject {

//! Delete all selected objects (Node + Link)
function deleteSelectedObjects() {
scene.selectionModel.notifySelectedObject = false;
// Delete objects
Object.entries(scene.selectionModel.selectedModel).forEach(([key, value]) => {
if(value.objectType === NLSpec.ObjectType.Node) {
if (value.objectType === NLSpec.ObjectType.Node) {
if (!value.guiConfig.locked)
scene.deleteNode(value._qsUuid);
}
if(value.objectType === NLSpec.ObjectType.Container) {
if (value.objectType === NLSpec.ObjectType.Container) {
scene.deleteContainer(value._qsUuid);
}
if(value.objectType === NLSpec.ObjectType.Link) {
if (value.objectType === NLSpec.ObjectType.Link) {
scene.unlinkNodes(value.inputPort._qsUuid, value.outputPort._qsUuid)
}
});

scene.selectionModel.notifySelectedObject = true;
// Clear the selection
scene.selectionModel.clear();
}
Expand Down
47 changes: 39 additions & 8 deletions resources/Core/SelectionModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ QtObject {
//! Uuids of all exist objects in scene.
property var existObjects: []

//! If notifySelectedObject is set to false, the selector object must handle this event..
//! and call the selectedModelChanged() signal.
property bool notifySelectedObject : true

onExistObjectsChanged: checkSelectedObjects();

/* Signals
Expand All @@ -26,10 +30,19 @@ QtObject {

//! Check all selected objects when necessary, i.e undo/redo
function checkSelectedObjects () {
notifySelectedObject = false;
var changed = false;
Object.keys(selectedModel).forEach(uuid => {
if (!existObjects.includes(uuid))
remove(uuid);
if (!existObjects.includes(uuid)) {
remove(uuid);
changed = true;
}
});

notifySelectedObject = true;

if (changed)
selectedModelChanged();
}

//! Clear all objects from selection model
Expand All @@ -38,11 +51,14 @@ QtObject {
Object.entries(selectedModel).forEach(([key, value]) => {
delete selectedModel[key];
});
selectedModelChanged();

if (notifySelectedObject)
selectedModelChanged();
}


//! Clear all objects (except one with qsUuid) from selection model
//! never sends signal for selection model change! as it will be followed by another event
function clearAllExcept(qsUuid : string) {
// delete all objects
Object.entries(selectedModel).forEach(([key, value]) => {
Expand All @@ -53,24 +69,30 @@ QtObject {

//! Remove an object from selection model
function remove(qsUuid : string) {
if(isSelected(qsUuid)) {
if (isSelected(qsUuid)) {
delete selectedModel[qsUuid];
selectedModelChanged();

if (notifySelectedObject)
selectedModelChanged();
}
}

//! Select object nodes (Add Node object to SelectionModel)
function selectNode(node: Node) {
//! clear selection model when selection changed.
selectedModel[node._qsUuid] = node;
selectedModelChanged();

if (notifySelectedObject)
selectedModelChanged();
}

//! Select container
function selectContainer(container: Container) {
//! clear selection model when selection changed.
selectedModel[container._qsUuid] = container;
selectedModelChanged();

if (notifySelectedObject)
selectedModelChanged();
}

//! Select Link objects (Add link object to SelectionModel)
Expand All @@ -80,7 +102,8 @@ QtObject {

// Add Link object into selected model.
selectedModel[link._qsUuid] = link;
selectedModelChanged();
if (notifySelectedObject)
selectedModelChanged();
}

//! Check an object is selected or not
Expand All @@ -104,6 +127,9 @@ QtObject {

//! Selects all nodes and links in the scene
function selectAll(nodes, links, containers) {
var notifySelectedObjectSession = notifySelectedObject;
notifySelectedObject = false;

clear();

Object.values(nodes).forEach(node => {
Expand All @@ -117,5 +143,10 @@ QtObject {
Object.values(containers).forEach(container => {
selectContainer(container);
})

notifySelectedObject = notifySelectedObjectSession;

if (notifySelectedObject)
selectedModelChanged();
}
}
19 changes: 13 additions & 6 deletions resources/View/Helpers/SelectionHelperView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ Item {
running: false

onTriggered: {
// Disable sending signals temporarily for performance improvement
scene.selectionModel.notifySelectedObject = false;

// clear selection model
scene.selectionModel.clear();

Expand All @@ -101,13 +104,17 @@ Item {
selectionRubberBandItem.height);
var selectedObj = scene.findNodesInContainerItem(selectionRubberBandRect);
selectedObj.forEach(node => {
if (node.objectType === NLSpec.ObjectType.Node) {
scene.selectionModel.selectNode(node);

} else if (node.objectType === NLSpec.ObjectType.Container) {
scene.selectionModel.selectContainer(node);
}
}); // todo: why don't we select the LINKS?

if (node.objectType === NLSpec.ObjectType.Node)
scene.selectionModel.selectNode(node)
else if (node.objectType === NLSpec.ObjectType.Container) {
scene.selectionModel.selectContainer(node)
}
});
scene.selectionModel.notifySelectedObject = true;
// todo: should we check actual change?
scene.selectionModel.selectedModelChanged();

if (!sceneSession.marqueeSelectionMode)
resetMarqueeDimensions();
Expand Down
4 changes: 4 additions & 0 deletions resources/View/ImagesFlickable.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ Rectangle {

property SelectionModel selectionModel: scene?.selectionModel ?? null

property var selectedItems : Object.values(selectionModel?.selectedModel ?? ({}))

property I_Node node

property bool selectedAlone : selectedItems.length === 1 && node === selectedItems[0]

/* Object Properties
* ****************************************************************************************/
color: "#1e1e1e"
Expand Down
20 changes: 1 addition & 19 deletions resources/View/NodesRect.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,10 @@ I_NodesRect {
width: modelData.guiConfig.width - 6
height: modelData.guiConfig.height * 0.35
x: modelData.guiConfig.position.x + 3
y: modelData.guiConfig.position.y - height - 5
y: modelData.guiConfig.position.y - height - 5 - (selectedAlone ? 45 : 0)
scene: root.scene
sceneSession: root.sceneSession
node: modelData

Connections {
property SelectionModel selectionModel: root.scene.selectionModel
target: selectionModel
function onSelectedModelChanged() {
if (!objectSelectionView.hasSelectedObject)
imageFlickable.y = Qt.binding(function() { return modelData.guiConfig.position.y - height - 5;});
Object.values(selectionModel.selectedModel).forEach(node =>{
if (imageFlickable.node === node) {
imageFlickable.y = Qt.binding(function() { return modelData.guiConfig.position.y - height - 49;});
return;
}
else
imageFlickable.y = Qt.binding(function() { return modelData.guiConfig.position.y - height - 5;});
})
}
}

}
}
}