[ui] show unsaved project warning dialog also when computing from GraphEditor

This commit is contained in:
Yann Lanthony 2019-01-30 09:47:07 +01:00
parent 6823695146
commit 28e7e64f3d
2 changed files with 68 additions and 36 deletions

View file

@ -21,7 +21,10 @@ Item {
// signals
signal workspaceMoved()
signal workspaceClicked()
signal nodeDoubleClicked(var mouse, var node)
signal computeRequest(var node)
signal submitRequest(var node)
// trigger initial fit() after initialization
// (ensure GraphEditor has its final size)
@ -279,14 +282,14 @@ Item {
MenuItem {
text: "Compute"
enabled: !uigraph.computing && !root.readOnly && nodeMenu.canComputeNode
onTriggered: uigraph.execute(nodeMenu.currentNode)
onTriggered: computeRequest(nodeMenu.currentNode)
}
MenuItem {
text: "Submit"
enabled: !uigraph.computing && !root.readOnly && nodeMenu.canComputeNode
visible: uigraph.canSubmit
height: visible ? implicitHeight : 0
onTriggered: uigraph.submit(nodeMenu.currentNode)
onTriggered: submitRequest(nodeMenu.currentNode)
}
MenuItem {
text: "Open Folder"

View file

@ -139,25 +139,67 @@ ApplicationWindow {
onRejected: closed(Platform.Dialog.Rejected)
}
Item {
id: computeManager
property bool warnIfUnsaved: true
// evaluate if global reconstruction computation can be started
property bool canStartComputation: _reconstruction.viewpoints.count >= 2 // at least 2 images
&& !_reconstruction.computing // computation is not started
&& _reconstruction.graph.canComputeLeaves // graph has no uncomputable nodes
// evaluate if graph computation can be submitted externally
property bool canSubmit: _reconstruction.canSubmit // current setup allows to compute externally
&& canStartComputation // can be computed
&& _reconstruction.graph.filepath // graph is saved on disk
function compute(node, force) {
if(!force && warnIfUnsaved && !_reconstruction.graph.filepath)
{
unsavedComputeDialog.currentNode = node;
unsavedComputeDialog.open();
}
else
_reconstruction.execute(node);
}
function submit(node) {
_reconstruction.submit(node);
}
MessageDialog {
id: unsavedComputeDialog
property var currentNode: null
canCopy: false
icon.text: MaterialIcons.warning
parent: Overlay.overlay
preset: "Warning"
title: "Unsaved Project"
text: "Data will be computed in the default cache folder if project remains unsaved."
detailedText: "Default cache folder: " + _reconstruction.graph.cacheDir
helperText: "Save project first?"
standardButtons: Dialog.Discard | Dialog.Cancel | Dialog.Save
CheckBox {
Layout.alignment: Qt.AlignRight
text: "Don't ask again for this session"
padding: 0
onToggled: computeManager.warnIfUnsaved = !checked
}
Component.onCompleted: {
// set up discard button text
standardButton(Dialog.Discard).text = "Continue without Saving"
}
onDiscarded: { close(); _reconstruction.execute(null) }
onDiscarded: { close(); computeManager.compute(currentNode, true) }
onAccepted: saveAsAction.trigger()
}
}
Platform.FileDialog {
id: openFileDialog
@ -418,16 +460,6 @@ ApplicationWindow {
Item { Layout.fillWidth: true }
Row {
// evaluate if global reconstruction computation can be started
property bool canStartComputation: _reconstruction.viewpoints.count >= 2 // at least 2 images
&& !_reconstruction.computing // computation is not started
&& _reconstruction.graph.canComputeLeaves // graph has no uncomputable nodes
// evaluate if graph computation can be submitted externally
property bool canSubmit: _reconstruction.canSubmit // current setup allows to compute externally
&& canStartComputation // can be computed
&& _reconstruction.graph.filepath // graph is saved on disk
// disable controls if graph is executed externally
enabled: !_reconstruction.computingExternally
Layout.alignment: Qt.AlignHCenter
@ -438,13 +470,8 @@ ApplicationWindow {
palette.button: enabled ? buttonColor : disabledPalette.button
palette.window: enabled ? buttonColor : disabledPalette.window
palette.buttonText: enabled ? "white" : disabledPalette.buttonText
enabled: parent.canStartComputation
onClicked: {
if(!_reconstruction.graph.filepath)
unsavedComputeDialog.open()
else
_reconstruction.execute(null)
}
enabled: computeManager.canStartComputation
onClicked: computeManager.compute(null)
}
Button {
text: "Stop"
@ -454,9 +481,9 @@ ApplicationWindow {
Item { width: 20; height: 1 }
Button {
visible: _reconstruction.canSubmit
enabled: parent.canSubmit
enabled: computeManager.canSubmit
text: "Submit"
onClicked: _reconstruction.submit(null)
onClicked: computeManager.submit(null)
}
}
Item { Layout.fillWidth: true; Layout.fillHeight: true }
@ -573,6 +600,8 @@ ApplicationWindow {
}
}
}
onComputeRequest: computeManager.compute(node)
onSubmitRequest: computeManager.submit(node)
}
}