From 5d985ce4e3b076af4f36069e3c6357b488eaa89a Mon Sep 17 00:00:00 2001
From: Robert Whitley <robert.whitley@stfc.ac.uk>
Date: Tue, 1 Nov 2011 09:51:38 +0000
Subject: [PATCH] Refs #3806. Added more functionality and matched up signals
 and slots to do the customisation. The plot now gets updated with a fit and
 when plotting the guess. One bug remains which is after a fitting is done for
 the second time the fit curve doesn't change.

---
 .../MantidPlot/src/ApplicationWindow.cpp      | 31 +++++++-----
 .../MantidPlot/src/Mantid/PeakPickerTool.cpp  |  6 ++-
 Code/Mantid/MantidPlot/src/PlotDialog.cpp     | 49 ++++++++++---------
 Code/Mantid/MantidPlot/src/PlotDialog.h       |  2 +-
 .../MantidQtCustomInterfaces/MuonAnalysis.h   |  5 +-
 .../CustomInterfaces/src/MuonAnalysis.cpp     | 29 ++++++++---
 .../FitPropertyBrowser.h                      |  5 ++
 .../MantidWidgets/src/FitPropertyBrowser.cpp  | 14 +++++-
 8 files changed, 96 insertions(+), 45 deletions(-)

diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
index 61df8ff3782..1d6c51e9c30 100644
--- a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
+++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
@@ -16399,13 +16399,12 @@ void ApplicationWindow::runPythonScript(const QString & code, bool quiet)
 * to change the plot style
 *
 * @params plotDetails :: This includes all details of the plot including type, 
-* curve number, workspace and color
+* curve type, workspace and color
 */
 void ApplicationWindow::setPlotType(const QString & plotDetails)
 {
   QStringList plotDetailsList("");
   int plotType(0);
-  int curveNum(0);
 
   if (plotDetails.contains(".") == false)
   {
@@ -16417,8 +16416,6 @@ void ApplicationWindow::setPlotType(const QString & plotDetails)
     if (plotDetailsList.size() >= 3) 
     {
       plotType = plotDetailsList[0].toInt();
-      curveNum = plotDetailsList[1].toInt();
-
 
       QList<MdiSubWindow *> windows = windowsList();
       foreach (MdiSubWindow *w, windows) 
@@ -16435,17 +16432,27 @@ void ApplicationWindow::setPlotType(const QString & plotDetails)
               Graph *g = plot->activeGraph();
               if (g)
               {
-                pd->selectCurve(g->curveIndex(curveNum));
+                int curveNum(-1);
+
+                if (plotDetailsList[1] == "Data")
+                  curveNum = g->curveIndex(plotDetailsList[2]); //workspaceName
+                else if (plotDetailsList[1] == "Fit")
+                  curveNum = g->curveIndex(plotDetailsList[2] + "-sp-1-Calc"); //workspaceName+"-"+axisLabel+QString("-Diff");
 
-                // line(0) scatter(1) line+symbol(2)
-                if (plotType >= 0 && plotType <= 2)
+                if (curveNum > -1) // If one of the curves has been changed 
                 {
-                if (plotDetailsList.size() > 3)
-                  pd->setPlotType(plotType, plotDetailsList[3]);
-                else
-                  pd->setPlotType(plotType);            
+                  pd->selectCurve(g->curveIndex(curveNum+1));
+
+                  // line(0) scatter(1) line+symbol(2)
+                  if (plotType >= 0 && plotType <= 2)
+                  {
+                    if (plotDetailsList.size() > 3)
+                      pd->setPlotType(plotType, plotDetailsList[3]);
+                    else
+                      pd->setPlotType(plotType);            
+                  }
+                  g->activateGraph();
                 }
-                g->activateGraph();
               }
             }
           }
diff --git a/Code/Mantid/MantidPlot/src/Mantid/PeakPickerTool.cpp b/Code/Mantid/MantidPlot/src/Mantid/PeakPickerTool.cpp
index 71bbc2699ff..799f21d6439 100644
--- a/Code/Mantid/MantidPlot/src/Mantid/PeakPickerTool.cpp
+++ b/Code/Mantid/MantidPlot/src/Mantid/PeakPickerTool.cpp
@@ -555,8 +555,11 @@ void PeakPickerTool::algorithmFinished(const QString& out)
   {
     new MantidCurve(m_curveDifName,out,graph(),2,false);
   }
-
+  
   graph()->replot();
+
+  //customise the plot
+  m_fitPropertyBrowser->customisation(workspaceName());  
 }
 
 /**
@@ -873,6 +876,7 @@ void PeakPickerTool::plotGuess()
   MantidQt::MantidWidgets::PropertyHandler* h = m_fitPropertyBrowser->getHandler();
   plotFitFunction(h);
   h->hasPlot() = true;
+  m_fitPropertyBrowser->customisation(m_wsName);
   d_graph->replot();
 }
 
diff --git a/Code/Mantid/MantidPlot/src/PlotDialog.cpp b/Code/Mantid/MantidPlot/src/PlotDialog.cpp
index 4b2fe95d65a..37a260da714 100644
--- a/Code/Mantid/MantidPlot/src/PlotDialog.cpp
+++ b/Code/Mantid/MantidPlot/src/PlotDialog.cpp
@@ -444,33 +444,38 @@ void PlotDialog::changePlotType(int plotType)
 */
 void PlotDialog::setPlotType(int plotType, const QString & color)
 {
-    CurveTreeItem *item = (CurveTreeItem *)listBox->currentItem();
-    if (!item)
-        return;
-    if (item->type() != CurveTreeItem::PlotCurveTreeItem)
-        return;
-    Graph *graph = item->graph();
-    if (!graph)
-        return;
-
-		QwtSymbol s = QwtSymbol(QwtSymbol::Ellipse, QBrush(), QPen(QColor(color)), QSize(5,5));
-		if (plotType == Graph::Line)
-			s.setStyle(QwtSymbol::NoSymbol);
-		else if (plotType == Graph::Scatter)
-			graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::NoCurve);
-		else if (plotType == Graph::LineSymbols)
-			graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::Lines);
+  CurveTreeItem *item = (CurveTreeItem *)listBox->currentItem();
+  if (!item)
+      return;
+  //std::cout << item->type(); //failing on 1001, should be 1002
+  if (item->type() != CurveTreeItem::PlotCurveTreeItem)
+      return;
+  Graph *graph = item->graph();
+  if (!graph)
+      return;
+
+  QwtSymbol s = QwtSymbol(QwtSymbol::Ellipse, QBrush(), QPen(), QSize(5,5));
+  if (plotType == Graph::Line)
+		s.setStyle(QwtSymbol::NoSymbol);
+	else if (plotType == Graph::Scatter)
+		graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::NoCurve);
+	else if (plotType == Graph::LineSymbols)
+		graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::Lines);
+    
+  if (color == "Default")
+    s.setPen(QPen(QColor(color)));
 
-    graph->setCurveSymbol(item->plotItemIndex(), s);
+  graph->setCurveSymbol(item->plotItemIndex(), s);
+  //acceptParams();
 }
 
 
 void PlotDialog::initFontsPage()
 {
-    QGroupBox *boxFonts = new QGroupBox();
-    QGridLayout *fl = new QGridLayout(boxFonts);
+  QGroupBox *boxFonts = new QGroupBox();
+  QGridLayout *fl = new QGridLayout(boxFonts);
 
-    btnTitle = new QPushButton(tr("Titles"));
+  btnTitle = new QPushButton(tr("Titles"));
 	btnAxesLabels = new QPushButton(tr("Axes Labels"));
 	btnAxesNumbers = new QPushButton(tr("Axes Numbers"));
 	btnLegend = new QPushButton(tr("Legends"));
@@ -484,10 +489,10 @@ void PlotDialog::initFontsPage()
 
 	fontsPage = new QWidget();
 	QHBoxLayout *hl = new QHBoxLayout(fontsPage);
-    hl->addWidget(boxFonts);
+  hl->addWidget(boxFonts);
 	privateTabWidget->addTab(fontsPage, tr( "Fonts" ) );
 
-    connect( btnTitle, SIGNAL( clicked() ), this, SLOT( setTitlesFont() ) );
+  connect( btnTitle, SIGNAL( clicked() ), this, SLOT( setTitlesFont() ) );
 	connect( btnAxesLabels, SIGNAL( clicked() ), this, SLOT( setAxesLabelsFont() ) );
 	connect( btnAxesNumbers, SIGNAL( clicked() ), this, SLOT( setAxesNumbersFont() ) );
 	connect( btnLegend, SIGNAL( clicked() ), this, SLOT( setLegendsFont() ) );
diff --git a/Code/Mantid/MantidPlot/src/PlotDialog.h b/Code/Mantid/MantidPlot/src/PlotDialog.h
index 122855edc62..9a63c021394 100644
--- a/Code/Mantid/MantidPlot/src/PlotDialog.h
+++ b/Code/Mantid/MantidPlot/src/PlotDialog.h
@@ -75,7 +75,7 @@ public:
   void insertColumnsList(const QStringList& names){columnNames = names;};
   void setMultiLayer(MultiLayer *ml);
 
-  void setPlotType(int plotType, const QString & color = "Black");
+  void setPlotType(int plotType, const QString & color = "Default");
 
 public slots:
   void showAll(bool all);
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysis.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysis.h
index 79df5e78525..647092ce5ff 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysis.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysis.h
@@ -155,9 +155,12 @@ private slots:
   /// Assigns a peak picker tool to the workspace (@param::workspace name)
   void assignPeakPickerTool(const QString &);
 
-  /// Change the plot style and color
+  /// Change the fit style and color
   void changeFitPlotType(const QString &);
 
+  /// Change the data style and color
+  void changeDataPlotType(const QString &);
+
 private:
   /// Initialize the layout
   virtual void initLayout();
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp
index 24f28f08697..6d3366b7f15 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp
@@ -177,6 +177,10 @@ void MuonAnalysis::initLayout()
 
   // Detect when fitting has started, change the plot style to the one specified in plot details tab.
   connect(m_uiForm.fitBrowser,SIGNAL(changeFitPlotStyle(const QString &)), this, SLOT(changeFitPlotType(const QString &)));
+
+  // Detect if the graph should be customised and call the two functions that change the different curves on the graph.
+  connect(m_uiForm.fitBrowser,SIGNAL(customiseGraph(const QString &)), this, SLOT(changeDataPlotType(const QString &)));
+  connect(m_uiForm.fitBrowser,SIGNAL(customiseGraph(const QString &)), this, SLOT(changeFitPlotType(const QString &)));
 }
 
 
@@ -1393,7 +1397,6 @@ void MuonAnalysis::createPlotWS(const std::string& groupName, const std::string&
   // rebin data if option set in Plot Options
   if ( m_uiForm.rebinComboBox->currentText() == "Fixed" )
   {
-    // @Rob.Whitley Need to implement.
     // Record the bunch data so that a fit can be done against it
     m_previousBunchWsName = wsname;
     m_previousRebinSteps = m_uiForm.optionStepSizeText->text();
@@ -1422,7 +1425,6 @@ void MuonAnalysis::createPlotWS(const std::string& groupName, const std::string&
 }
 
 
-// @Rob.Whitley Need to implement
 /**
 * Check the bunch details then fit using the rebinned data but plot against 
 * the data that is currently plotted, this may be the same.
@@ -1445,7 +1447,7 @@ void MuonAnalysis::reBunch(const std::string & wsName)
 
   else if (m_previousBunchWsName == wsName)
   {
-    //Put back to original, then bunch to specification (make raw currently creates a new plot @Rob.Whitley Need to implement)
+    //Put back to original, then bunch to specification
     makeRaw(wsName);
     m_previousBunchWsName = wsName;
     m_previousRebinSteps = m_uiForm.optionStepSizeText->text();
@@ -1739,7 +1741,7 @@ void MuonAnalysis::plotPair(const std::string& plotType)
     QString plotType("");
     plotType.setNum(m_uiForm.connectPlotType->currentIndex());
 
-    changePlotType(plotType + ".1." + titleLabel);
+    changePlotType(plotType + ".Data." + titleLabel);
     
     m_currentDataName = titleLabel;
     m_uiForm.fitBrowser->manualAddWorkspace(m_currentDataName);
@@ -2809,7 +2811,7 @@ void MuonAnalysis::assignPeakPickerTool(const QString & workspaceName)
 
 
 /**
-* Set up the string that will contain all the data needed for making a plot.
+* Set up the string that will contain all the data needed for changing a fit.
 * [fitType, curveNum, wsName, color]
 *
 * @params wsName :: The workspace name of the plot to be created. 
@@ -2819,7 +2821,22 @@ void MuonAnalysis::changeFitPlotType(const QString & wsName)
   // First part indicates 
   QString fitType("");
   fitType.setNum(m_uiForm.connectFitType->currentIndex());
-  changePlotType(fitType + ".3." + wsName + "." + "Lime");
+  changePlotType(fitType + ".Fit." + wsName + "." + "Orange");
+}
+
+
+/**
+* Set up the string that will contain all the data needed for changing the data.
+* [fitType, curveNum, wsName, color]
+*
+* @params wsName :: The workspace name of the plot to be created. 
+*/
+void MuonAnalysis::changeDataPlotType(const QString & wsName)
+{
+  // First part indicates 
+  QString fitType("");
+  fitType.setNum(m_uiForm.connectPlotType->currentIndex());
+  changePlotType(fitType + ".Data." + wsName + "." + "Black");
 }
 
 }//namespace MantidQT
diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h
index 14bb3b6698e..c220285453f 100644
--- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h
+++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h
@@ -203,6 +203,9 @@ public:
   /// Update the PeakPickerTool with the current workspace to be displayed and which to associate itself with
   void updatePPTool(const QString& name);
 
+  /// Emits a signal to customise the plot it is associated with
+  void customisation(const QString& wsName);
+
 public slots:
   void fit();
   void sequentialFit();
@@ -244,6 +247,8 @@ signals:
   void removePlotSignal(MantidQt::MantidWidgets::PropertyHandler*);
   void removeFitCurves();
 
+  void customiseGraph(const QString&);
+
   void executeFit(QString,QMap<QString,QString>,Mantid::API::AlgorithmObserver*);
   void multifitFinished();
 
diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
index c4469766c79..24a0df4b77f 100644
--- a/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
+++ b/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
@@ -1453,7 +1453,7 @@ void FitPropertyBrowser::finishHandle(const Mantid::API::IAlgorithm* alg)
     double quality = alg->getProperty("OutputChi2overDoF");
     std::string costFunction = alg->getProperty("CostFunction");
     Mantid::API::ICostFunction* costfun 
-     = Mantid::API::CostFunctionFactory::Instance().createUnwrapped(costFunction);
+     = Mantid::API::CostFunctionFactory::Instance().createUnwrapped(costFunction); 
     emit changeWindowTitle(QString("Fit Function (") 
       + costfun->shortName().c_str() + " = " + QString::number(quality) + ")");
   }
@@ -1463,7 +1463,6 @@ void FitPropertyBrowser::finishHandle(const Mantid::API::IAlgorithm* alg)
   {
     emit multifitFinished();
   }
-  changeFitPlotStyle(QString::fromStdString(alg->getProperty("InputWorkspace")));
 }
 
 
@@ -2120,6 +2119,17 @@ void FitPropertyBrowser::clearAllPlots()
   emit removeFitCurves();
 }
 
+/**
+* Customise the plot if it is a custom fitting. (i.e part of muon analysis)
+*
+* @param wsName :: The name of the workspace plot to be customised
+*/
+void FitPropertyBrowser::customisation(const QString& wsName)
+{
+  if (m_customFittings)
+    emit customiseGraph(wsName);
+}
+
 /** Create a double property and set some settings
  * @param name :: The name of the new property
  * @return Pointer to the created property
-- 
GitLab