From ddeeb2d910c779ed01fe548123ab32ef7caa0dea Mon Sep 17 00:00:00 2001 From: Anton Piccardo-Selg <anton.piccardo-selg@tessella.com> Date: Tue, 9 Jun 2015 16:00:32 +0100 Subject: [PATCH] Refs #6457 Handle save results mechanism --- .../MantidQtCustomInterfaces/SANSRunWindow.h | 1 + .../CustomInterfaces/src/SANSRunWindow.cpp | 25 +++++++++++++++++++ .../MantidQtMantidWidgets/SaveWorkspaces.h | 2 ++ .../MantidWidgets/src/SaveWorkspaces.cpp | 12 +++++++++ 4 files changed, 40 insertions(+) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h index b27a11398a9..e9db170ed8e 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h @@ -211,6 +211,7 @@ private: /// Destroy a zero error free cloned workspace void deleteZeroErrorFreeClone(QString& clonedWorkspaceName); + private slots: /// phi masking has changed void phiMaskingChanged(); diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp index 461b9d7f44e..d736e88a105 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp @@ -435,6 +435,11 @@ void SANSRunWindow::saveWorkspacesDialog() // Connect the request for deleting a zero-error-free workspace connect(m_saveWorkspaces, SIGNAL(deleteZeroErrorFreeWorkspace(QString&)), this, SLOT(deleteZeroErrorFreeClone(QString&) )); + // Connect to change in the zero-error removal checkbox + connect(m_uiForm.zeroErrorCheckBox, SIGNAL(stateChanged(int)), + m_saveWorkspaces, SLOT(onSaveAsZeroErrorFreeChanged(int))); + + m_uiForm.saveSel_btn->setEnabled(false); m_saveWorkspaces->show(); } @@ -2800,6 +2805,17 @@ void SANSRunWindow::handleDefSaveClick() QMessageBox::warning(this, "Filename required", "A filename must be entered into the text box above to save this file"); } + // If we save with a zero-error-free correction we need to swap the + QString workspaceNameBuffer = m_outputWS; + if (m_uiForm.zeroErrorCheckBox->isChecked()) { + QString clonedWorkspaceName = m_outputWS + "_cloned_temp"; + createZeroErrorFreeClone(m_outputWS, clonedWorkspaceName); + if (AnalysisDataService::Instance().doesExist(clonedWorkspaceName.toStdString())) { + m_outputWS = clonedWorkspaceName; + } + } + + const QStringList algs(getSaveAlgs()); QString saveCommand; for(QStringList::const_iterator alg = algs.begin(); alg != algs.end(); ++alg) @@ -2847,6 +2863,14 @@ void SANSRunWindow::handleDefSaveClick() saveCommand += "print 'success'\n"; QString result = runPythonCode(saveCommand).trimmed(); + + // Revert changes and delete the zero-free workspace + if (this->m_uiForm.zeroErrorCheckBox->isChecked()) { + deleteZeroErrorFreeClone(m_outputWS); + } + m_outputWS = workspaceNameBuffer; + + if ( result != "success" ) { QMessageBox::critical(this, "Error saving workspace", "Problem encountered saving workspace, does it still exist. There may be more information in the results console?"); @@ -3866,6 +3890,7 @@ void SANSRunWindow::deleteZeroErrorFreeClone(QString& clonedWorkspaceName) { } } + } //namespace CustomInterfaces } //namespace MantidQt diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h index 6217561df5d..24224bdb6bc 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h +++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h @@ -52,6 +52,8 @@ namespace MantidQt void initLayout(); ///Returns the save extension expected the name algorithm static QString getSaveAlgExt(const QString & algName); + public slots: + void onSaveAsZeroErrorFreeChanged(int state); signals: void closing(); diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp index 058a4755df9..346ab744f29 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp @@ -424,3 +424,15 @@ void SaveWorkspaces::removeZeroFreeWorkspaces(QHash<QString, QString> workspaces emit deleteZeroErrorFreeWorkspace((*it)); } } + +/** + * Reacts to a user change wether the workspace is to be saved as zero-error-free or not + * @param state :: 0 if we don't save with the zero-error correction, otherwise anything else + */ +void SaveWorkspaces::onSaveAsZeroErrorFreeChanged(int state) { + if (state == 0) { + m_saveAsZeroErrorFree = false; + } else { + m_saveAsZeroErrorFree = true; + } +} -- GitLab