[ui] fix drag and drop external images on Viewer2D

This commit is contained in:
Loïc Vital 2022-09-29 11:40:28 +02:00 committed by Fabien Castan
parent b91d0b372e
commit 88e822a9de
2 changed files with 29 additions and 6 deletions

View file

@ -10,6 +10,10 @@ FocusScope {
clip: true clip: true
property var displayedNode: _reconstruction.cameraInit property var displayedNode: _reconstruction.cameraInit
property bool useExternal: false
property url sourceExternal
property url source property url source
property var metadata property var metadata
property var viewIn3D property var viewIn3D
@ -155,6 +159,8 @@ FocusScope {
} }
function tryLoadNode(node) { function tryLoadNode(node) {
useExternal = false;
// safety check // safety check
if (!node) { if (!node) {
return false; return false;
@ -182,15 +188,33 @@ FocusScope {
return true; return true;
} }
function loadExternal(path) {
useExternal = true;
sourceExternal = path;
displayedNode = null;
metadata = {};
}
function getImageFile() { function getImageFile() {
// entry point for getting the image file URL that corresponds to // entry point for getting the image file URL
// the displayed node, selected output attribute and selected viewId if (useExternal) {
return sourceExternal;
}
if (!displayedNode || outputAttribute.name == "" || outputAttribute.name == "gallery") { if (!displayedNode || outputAttribute.name == "" || outputAttribute.name == "gallery") {
return getViewpointPath(_reconstruction.selectedViewId); return getViewpointPath(_reconstruction.selectedViewId);
} }
return getFileAttributePath(displayedNode, outputAttribute.name, _reconstruction.selectedViewId); return getFileAttributePath(displayedNode, outputAttribute.name, _reconstruction.selectedViewId);
} }
function getMetadata() {
// entry point for getting the image metadata
if (useExternal) {
return {};
} else {
return getViewpointMetadata(_reconstruction.selectedViewId);
}
}
function getFileAttributePath(node, attrName, viewId) { function getFileAttributePath(node, attrName, viewId) {
// get output attribute with matching name // get output attribute with matching name
// and parse its value to get the image filepath // and parse its value to get the image filepath
@ -226,7 +250,7 @@ FocusScope {
return vp.childAttribute("metadata").value; return vp.childAttribute("metadata").value;
} }
} }
return ""; return {};
} }
onDisplayedNodeChanged: { onDisplayedNodeChanged: {
@ -252,7 +276,7 @@ FocusScope {
target: _reconstruction target: _reconstruction
onSelectedViewIdChanged: { onSelectedViewIdChanged: {
root.source = getImageFile(); root.source = getImageFile();
root.metadata = getViewpointMetadata(_reconstruction.selectedViewId); root.metadata = getMetadata();
} }
} }

View file

@ -152,8 +152,7 @@ Item {
anchors.fill: parent anchors.fill: parent
keys: ["text/uri-list"] keys: ["text/uri-list"]
onDropped: { onDropped: {
viewer2D.source = drop.urls[0] viewer2D.loadExternal(drop.urls[0]);
viewer2D.metadata = {}
} }
} }
Rectangle { Rectangle {