From e3f72a9f0e8a67d84d4411e0798baa038de08e65 Mon Sep 17 00:00:00 2001
From: Elliot Oram <Elliot.Oram@stfc.ac.uk>
Date: Mon, 12 Oct 2015 11:25:02 +0100
Subject: [PATCH] Changed .cpp UI code to run new python alg

Refs #13826
---
 .../algorithms/WorkflowAlgorithms/QLRun.py    |  4 +-
 .../MantidQtCustomInterfaces/Indirect/Quasi.h | 86 +++++++++----------
 .../CustomInterfaces/src/Indirect/Quasi.cpp   | 34 ++++++--
 3 files changed, 73 insertions(+), 51 deletions(-)

diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py
index a1c2e79cc9e..fe344b965f8 100644
--- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py
+++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py
@@ -11,8 +11,8 @@ class QLRun(PythonAlgorithm):
         return "PythonAlgorithms"
 
     def summary(self):
-        return "This algorithm runs the Fortran QLines programs which fits a Delta function of"
-               " amplitude 0 and Lorentzians of amplitude A(j) and HWHM W(j) where j=1,2,3. The"
+        return "This algorithm runs the Fortran QLines programs which fits a Delta function of"+\
+               " amplitude 0 and Lorentzians of amplitude A(j) and HWHM W(j) where j=1,2,3. The"+\
                " whole function is then convoled with the resolution function."
 
     def PyInit(self):
diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Quasi.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Quasi.h
index 08ae4d6a644..51f240b0f68 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Quasi.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Quasi.h
@@ -4,50 +4,48 @@
 #include "ui_Quasi.h"
 #include "IndirectBayesTab.h"
 
-namespace MantidQt
-{
-	namespace CustomInterfaces
-	{
-		class DLLExport Quasi : public IndirectBayesTab
-		{
-			Q_OBJECT
-
-		public:
-			Quasi(QWidget * parent = 0);
-
-			// Inherited methods from IndirectBayesTab
-      void setup();
-			bool validate();
-			void run();
-			/// Load default settings into the interface
-			void loadSettings(const QSettings& settings);
-
-		private slots:
-			/// Slot for when the min range on the range selector changes
-			void minValueChanged(double min);
-			/// Slot for when the min range on the range selector changes
-			void maxValueChanged(double max);
-			/// Slot to update the guides when the range properties change
-			void updateProperties(QtProperty* prop, double val);
-			/// Slot to handle when a new sample file is available
-			void handleSampleInputReady(const QString& filename);
-			/// Slot to handle when a new resolution file is available
-			void handleResolutionInputReady(const QString& wsName);
-			/// slot to handle when the user changes the program to be used
-			void handleProgramChange(int index);
-      /// Slot to handle setting a new preview spectrum
-      void previewSpecChanged(int value);
-      /// Handles updating spectra in mini plot
-      void updateMiniPlot();
-
-		private:
-			/// Current preview spectrum
-      int m_previewSpec;
-			/// The ui form
-			Ui::Quasi m_uiForm;
-
-		};
-	} // namespace CustomInterfaces
+namespace MantidQt {
+namespace CustomInterfaces {
+class DLLExport Quasi : public IndirectBayesTab {
+  Q_OBJECT
+
+public:
+  Quasi(QWidget *parent = 0);
+
+  // Inherited methods from IndirectBayesTab
+  void setup();
+  bool validate();
+  void run();
+  /// Load default settings into the interface
+  void loadSettings(const QSettings &settings);
+
+private slots:
+  /// Slot for when the min range on the range selector changes
+  void minValueChanged(double min);
+  /// Slot for when the min range on the range selector changes
+  void maxValueChanged(double max);
+  /// Slot to update the guides when the range properties change
+  void updateProperties(QtProperty *prop, double val);
+  /// Slot to handle when a new sample file is available
+  void handleSampleInputReady(const QString &filename);
+  /// Slot to handle when a new resolution file is available
+  void handleResolutionInputReady(const QString &wsName);
+  /// slot to handle when the user changes the program to be used
+  void handleProgramChange(int index);
+  /// Slot to handle setting a new preview spectrum
+  void previewSpecChanged(int value);
+  /// Handles updating spectra in mini plot
+  void updateMiniPlot();
+  /// Handles what happen after the algorithm is run
+  void algorithmComplete(bool error);
+
+private:
+  /// Current preview spectrum
+  int m_previewSpec;
+  /// The ui form
+  Ui::Quasi m_uiForm;
+};
+} // namespace CustomInterfaces
 } // namespace MantidQt
 
 #endif
diff --git a/MantidQt/CustomInterfaces/src/Indirect/Quasi.cpp b/MantidQt/CustomInterfaces/src/Indirect/Quasi.cpp
index 5ecec24dba7..a07ec3dbb22 100644
--- a/MantidQt/CustomInterfaces/src/Indirect/Quasi.cpp
+++ b/MantidQt/CustomInterfaces/src/Indirect/Quasi.cpp
@@ -185,7 +185,21 @@ void Quasi::run() {
   }
   QString plot = m_uiForm.cbPlot->currentText();
 
-  pyInput += "QLRun('" + program + "','" + sampleName + "','" + resName +
+  IAlgorithm_sptr runAlg = AlgorithmManager::Instance().create("QLRun");
+  runAlg->initialize();
+  runAlg->setProperty("program", program.toStdString());
+  runAlg->setProperty("samWs", sampleName.toStdString());
+  runAlg->setProperty("resWs", resName.toStdString());
+  runAlg->setProperty("resNormWs", resNormFile.toStdString());
+  runAlg->setProperty("erange", eRange.toStdString());
+  runAlg->setProperty("nbins", nBins.toStdString());
+  runAlg->setProperty("Fit", fitOps.toStdString());
+  runAlg->setProperty("wfile", fixedWidthFile.toStdString());
+  runAlg->setProperty("Loop", sequence.toStdString());
+  runAlg->setProperty("Save", save.toStdString());
+  runAlg->setProperty("Plot", plot.toStdString());
+
+  /*pyInput += "QLRun('" + program + "','" + sampleName + "','" + resName +
              "','" + resNormFile + "'," + eRange + ","
                                                    " " +
              nBins + "," + fitOps + ",'" + fixedWidthFile + "'," + sequence +
@@ -193,15 +207,25 @@ void Quasi::run() {
              " Save=" +
              save + ", Plot='" + plot + "')\n";
 
-  runPythonScript(pyInput);
-
-  updateMiniPlot();
+  runPythonScript(pyInput);*/
+  m_batchAlgoRunner->addAlgorithm(runAlg);
+  connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this,
+          SLOT(algorithmComplete(bool)));
+  m_batchAlgoRunner->executeBatchAsync();
 }
 
 /**
  * Updates the data and fit curves on the mini plot.
  */
-void Quasi::updateMiniPlot() {
+void Quasi::algorithmComplete(bool error) {
+
+  if (error)
+    return;
+  else
+    updateMiniPlot();
+}
+
+void Quasi::updateMiniPlot(){
   // Update sample plot
   if (!m_uiForm.dsSample->isValid())
     return;
-- 
GitLab