[ui] minor code cleanup

This commit is contained in:
Loïc Vital 2022-09-23 17:48:37 +02:00 committed by Fabien Castan
parent f90942bd2d
commit 9de858efe4
2 changed files with 23 additions and 6 deletions

View file

@ -155,6 +155,11 @@ FocusScope {
} }
function tryLoadNode(node) { function tryLoadNode(node) {
// safety check
if (!node) {
return;
}
// node must be computed or at least running // node must be computed or at least running
if (!node.isFinishedOrRunning()) { if (!node.isFinishedOrRunning()) {
return; return;
@ -179,7 +184,7 @@ FocusScope {
function getImageFile() { function getImageFile() {
// entry point for getting the image file URL that corresponds to // entry point for getting the image file URL that corresponds to
// the displayed node, selected output attribute and selected viewId // the displayed node, selected output attribute and selected viewId
if (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);
@ -222,6 +227,11 @@ FocusScope {
} }
onDisplayedNodeChanged: { onDisplayedNodeChanged: {
// safety check
if (!displayedNode) {
return;
}
var names = []; var names = [];
// store attr name for output attributes that represent images // store attr name for output attributes that represent images
for (var i = 0; i < displayedNode.attributes.count; i++) { for (var i = 0; i < displayedNode.attributes.count; i++) {
@ -230,10 +240,12 @@ FocusScope {
names.push(attr.name); names.push(attr.name);
} }
} }
// ensure that we can always visualize the gallery // ensure that we can always visualize the gallery
if (names.length > 0) { if (names.length > 0) {
names.push("gallery"); names.push("gallery");
} }
outputAttribute.names = names; outputAttribute.names = names;
} }
@ -1078,7 +1090,7 @@ FocusScope {
flat: true flat: true
property var names: [] property var names: []
property string name: (names.length > 0) ? (enabled ? names[currentIndex] : names[0]) : "" property string name: ""
model: names model: names
enabled: activeNode enabled: activeNode
@ -1088,12 +1100,18 @@ FocusScope {
} }
onNamesChanged: { onNamesChanged: {
// set size to max name length // update name (requires some safety check)
if (names.length > 0 && names[0]) {
name = names[0];
} else {
name = "";
}
// update width (set size to max name length + add margin for the dropdown icon)
var maxWidth = 0; var maxWidth = 0;
for (var i = 0; i < names.length; i++) { for (var i = 0; i < names.length; i++) {
maxWidth = Math.max(maxWidth, fontMetrics.boundingRect(names[i]).width); maxWidth = Math.max(maxWidth, fontMetrics.boundingRect(names[i]).width);
} }
// add margin for the dropdown icon
Layout.preferredWidth = maxWidth + 3.0 * Qt.application.font.pixelSize; Layout.preferredWidth = maxWidth + 3.0 * Qt.application.font.pixelSize;
} }
} }

View file

@ -856,8 +856,7 @@ ApplicationWindow {
viewer2D.tryLoadNode(node); viewer2D.tryLoadNode(node);
// 3D viewer // 3D viewer
for(var i=0; i < node.attributes.count; ++i) for (var i = 0; i < node.attributes.count; i++) {
{
var attr = node.attributes.at(i) var attr = node.attributes.at(i)
if(attr.isOutput && workspaceView.viewIn3D(attr, mouse)) if(attr.isOutput && workspaceView.viewIn3D(attr, mouse))
break; break;