From e7698c2974d2e0a88963eb9e6cac24913a687e6f Mon Sep 17 00:00:00 2001
From: Raquel Alvarez Banos <raquel.alvarez.banos@gmail.com>
Date: Thu, 8 Oct 2015 10:05:48 +0100
Subject: [PATCH] Re #13862 Make BaselineModelling aware of data loaded by
 DataLoading

---
 .../Muon/ALCBaselineModellingView.h           |  1 +
 .../Muon/ALCDataLoadingPresenter.h            |  4 +++
 .../Muon/ALCInterface.h                       |  8 ++++++
 .../Muon/IALCDataLoadingView.h                |  3 +++
 .../src/Muon/ALCBaselineModellingView.cpp     |  4 +++
 .../src/Muon/ALCDataLoadingPresenter.cpp      |  2 ++
 .../src/Muon/ALCInterface.cpp                 | 25 ++++++++++++++++---
 7 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingView.h
index a6b72f65f76..fe46ceea225 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingView.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingView.h
@@ -63,6 +63,7 @@ namespace CustomInterfaces
     SectionRow sectionRow(int row) const;
     SectionSelector sectionSelector(int index) const;
     int noOfSectionRows() const;
+    void emitFitRequested();
 
   public slots:
     void initialize();
diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCDataLoadingPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCDataLoadingPresenter.h
index 547a57a9718..11ea7375917 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCDataLoadingPresenter.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCDataLoadingPresenter.h
@@ -60,6 +60,10 @@ namespace CustomInterfaces
     /// Updates the list of logs and number of periods
     void updateAvailableInfo();
 
+  signals:
+    /// Signal emitted when data get changed
+    void dataChanged();
+
   private:
     /// View which the object works with
     IALCDataLoadingView* const m_view;
diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCInterface.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCInterface.h
index 9666c82a641..e94e34c6267 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCInterface.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCInterface.h
@@ -18,9 +18,11 @@ namespace CustomInterfaces
 
   class ALCDataLoadingPresenter;
 
+  class ALCBaselineModellingView;
   class ALCBaselineModellingPresenter;
   class ALCBaselineModellingModel;
 
+  class ALCPeakFittingView;
   class ALCPeakFittingPresenter;
   class ALCPeakFittingModel;
 
@@ -68,11 +70,17 @@ namespace CustomInterfaces
     void exportResults();
     void importResults();
 
+    void updateBaselineData();
+
   private:
 
     /// UI form
     Ui::ALCInterface m_ui;
 
+    // Step views
+    ALCBaselineModellingView* m_baselineModellingView;
+    ALCPeakFittingView* m_peakFittingView;
+
     // Step presenters
     ALCDataLoadingPresenter* m_dataLoading;
     ALCBaselineModellingPresenter* m_baselineModelling;
diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCDataLoadingView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCDataLoadingView.h
index c5772cdbea8..3c0ac04337d 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCDataLoadingView.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCDataLoadingView.h
@@ -135,6 +135,9 @@ namespace CustomInterfaces
     /// User has selected the first run
     void firstRunSelected();
 
+    /// New data have been loaded
+    void dataChanged();
+
   };
 
 } // namespace CustomInterfaces
diff --git a/MantidQt/CustomInterfaces/src/Muon/ALCBaselineModellingView.cpp b/MantidQt/CustomInterfaces/src/Muon/ALCBaselineModellingView.cpp
index 03be4452b12..b1ec6576a13 100644
--- a/MantidQt/CustomInterfaces/src/Muon/ALCBaselineModellingView.cpp
+++ b/MantidQt/CustomInterfaces/src/Muon/ALCBaselineModellingView.cpp
@@ -272,5 +272,9 @@ namespace CustomInterfaces
     MantidQt::API::HelpWindow::showCustomInterface(NULL, QString("Muon_ALC"));
   }
 
+  void ALCBaselineModellingView::emitFitRequested() {
+    emit fitRequested();
+  }
+
 } // namespace CustomInterfaces
 } // namespace MantidQt
diff --git a/MantidQt/CustomInterfaces/src/Muon/ALCDataLoadingPresenter.cpp b/MantidQt/CustomInterfaces/src/Muon/ALCDataLoadingPresenter.cpp
index 4492c6f9187..8f56ec1b0f6 100644
--- a/MantidQt/CustomInterfaces/src/Muon/ALCDataLoadingPresenter.cpp
+++ b/MantidQt/CustomInterfaces/src/Muon/ALCDataLoadingPresenter.cpp
@@ -108,6 +108,8 @@ namespace CustomInterfaces
       m_view->setDataCurve(*(ALCHelper::curveDataFromWs(m_loadedData, 0)),
                            ALCHelper::curveErrorsFromWs(m_loadedData, 0));
 
+      emit dataChanged();
+
     }
     catch(std::exception& e)
     {
diff --git a/MantidQt/CustomInterfaces/src/Muon/ALCInterface.cpp b/MantidQt/CustomInterfaces/src/Muon/ALCInterface.cpp
index 5e0703eea02..9a293ee0a37 100644
--- a/MantidQt/CustomInterfaces/src/Muon/ALCInterface.cpp
+++ b/MantidQt/CustomInterfaces/src/Muon/ALCInterface.cpp
@@ -49,19 +49,36 @@ namespace CustomInterfaces
     m_dataLoading = new ALCDataLoadingPresenter(dataLoadingView);
     m_dataLoading->initialize();
 
-    auto baselineModellingView = new ALCBaselineModellingView(m_ui.baselineModellingView);
-    m_baselineModelling = new ALCBaselineModellingPresenter(baselineModellingView, m_baselineModellingModel);
+    m_baselineModellingView = new ALCBaselineModellingView(m_ui.baselineModellingView);
+    m_baselineModelling = new ALCBaselineModellingPresenter(m_baselineModellingView, m_baselineModellingModel);
     m_baselineModelling->initialize();
 
-    auto peakFittingView = new ALCPeakFittingView(m_ui.peakFittingView);
-    m_peakFitting = new ALCPeakFittingPresenter(peakFittingView, m_peakFittingModel);
+    m_peakFittingView = new ALCPeakFittingView(m_ui.peakFittingView);
+    m_peakFitting = new ALCPeakFittingPresenter(m_peakFittingView, m_peakFittingModel);
     m_peakFitting->initialize();
 
+    connect(m_dataLoading, SIGNAL(dataChanged()), SLOT(updateBaselineData()));
+
     assert(m_ui.stepView->count() == STEP_NAMES.count()); // Should have names for all steps
 
     switchStep(0); // We always start from the first step
   }
 
+  void ALCInterface::updateBaselineData() {
+
+    if (m_dataLoading->loadedData()) {
+
+      m_baselineModellingModel->setData(m_dataLoading->loadedData());
+
+      if ((!m_baselineModellingView->function().isEmpty()) &&
+          (m_baselineModellingView->noOfSectionRows() > 0)) {
+
+            // Fit the data
+            m_baselineModellingView->emitFitRequested();
+      }
+    }
+  }
+
   void ALCInterface::nextStep()
   {
     int next = m_ui.stepView->currentIndex() + 1;
-- 
GitLab