From 5666920720f6d85c36f56a0fb84ce033e2bff6c5 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Tue, 21 Jun 2016 17:28:00 +0200
Subject: [PATCH] FitComparisonWidget now is able to show real data and
 simulated data during real time tuning.

---
 GUI/coregui/Models/DomainFittingBuilder.cpp   |  2 +-
 GUI/coregui/Models/JobItem.cpp                |  6 +++++
 GUI/coregui/Models/JobItem.h                  |  2 ++
 .../Views/FitWidgets/FitComparisonWidget.cpp  | 27 ++++++++++++++++---
 .../Views/FitWidgets/FitComparisonWidget.h    |  7 +++++
 5 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/GUI/coregui/Models/DomainFittingBuilder.cpp b/GUI/coregui/Models/DomainFittingBuilder.cpp
index 156ea737576..342da290682 100644
--- a/GUI/coregui/Models/DomainFittingBuilder.cpp
+++ b/GUI/coregui/Models/DomainFittingBuilder.cpp
@@ -62,7 +62,7 @@ std::shared_ptr<FitSuite> DomainFittingBuilder::createFitSuite(JobItem *jobItem)
                 builder.getSimulation(jobItem->getMultiLayerItem(),
                                         jobItem->getInstrumentItem()));
 
-    RealDataItem *realDataItem = dynamic_cast<RealDataItem*>(jobItem->getItem(JobItem::T_REALDATA));
+    RealDataItem *realDataItem = jobItem->realDataItem();
     if(!realDataItem)
         throw GUIHelpers::Error("DomainFittingBuilder::createFitSuite() -> No Real Data defined.");
 
diff --git a/GUI/coregui/Models/JobItem.cpp b/GUI/coregui/Models/JobItem.cpp
index ed7fa80f293..b3bb925f92a 100644
--- a/GUI/coregui/Models/JobItem.cpp
+++ b/GUI/coregui/Models/JobItem.cpp
@@ -27,6 +27,7 @@
 #include "FitSuiteItem.h"
 #include "ParameterTreeItems.h"
 #include "FitParameterItems.h"
+#include "RealDataItem.h"
 #include <QDateTime>
 #include <QDebug>
 
@@ -293,6 +294,11 @@ FitParameterContainerItem *JobItem::fitParameterContainerItem()
     return nullptr;
 }
 
+RealDataItem *JobItem::realDataItem()
+{
+    return dynamic_cast<RealDataItem*>(getItem(JobItem::T_REALDATA));
+}
+
 //! Updates the name of file to store intensity data.
 
 void JobItem::updateIntensityDataFileName()
diff --git a/GUI/coregui/Models/JobItem.h b/GUI/coregui/Models/JobItem.h
index 2a39644664e..14687a89f52 100644
--- a/GUI/coregui/Models/JobItem.h
+++ b/GUI/coregui/Models/JobItem.h
@@ -28,6 +28,7 @@ class SimulationOptionsItem;
 class FitSuiteItem;
 class ParameterContainerItem;
 class FitParameterContainerItem;
+class RealDataItem;
 
 class BA_CORE_API_ JobItem : public SessionItem
 {
@@ -98,6 +99,7 @@ public:
     FitSuiteItem *fitSuiteItem();
     ParameterContainerItem *parameterContainerItem();
     FitParameterContainerItem *fitParameterContainerItem();
+    RealDataItem *realDataItem();
 
 private:
     void updateIntensityDataFileName();
diff --git a/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp b/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp
index 6165939750f..2393a1fd75a 100644
--- a/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp
+++ b/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp
@@ -15,21 +15,40 @@
 // ************************************************************************** //
 
 #include "FitComparisonWidget.h"
+#include "ColorMapPlot.h"
+#include "JobItem.h"
+#include "RealDataItem.h"
+#include <QGridLayout>
 #include <QVBoxLayout>
 #include <QLabel>
 #include <QDebug>
 
 FitComparisonWidget::FitComparisonWidget(QWidget *parent)
     : SessionItemWidget(parent)
+    , m_realDataPlot(new ColorMapPlot)
+    , m_simulatedDataPlot(new ColorMapPlot)
+    , m_chi2DataPlot(new ColorMapPlot)
 {
-    QVBoxLayout *layout = new QVBoxLayout();
-    layout->addWidget(new QLabel("xxx"));
 
-    setLayout(layout);
+    QGridLayout *gridLayout = new QGridLayout;
+
+    gridLayout->addWidget(m_realDataPlot, 0, 0);
+    gridLayout->addWidget(m_simulatedDataPlot, 0, 1);
+    gridLayout->addWidget(m_chi2DataPlot, 1, 0);
+
+
+    setLayout(gridLayout);
 }
 
 void FitComparisonWidget::setItem(SessionItem *item)
 {
-    Q_UNUSED(item);
+    JobItem *jobItem = dynamic_cast<JobItem *>(item);
+    setJobItem(jobItem);
+}
+
+void FitComparisonWidget::setJobItem(JobItem *jobItem)
+{
 
+    m_realDataPlot->setItem(jobItem->realDataItem()->intensityDataItem());
+    m_simulatedDataPlot->setItem(jobItem->getIntensityDataItem());
 }
diff --git a/GUI/coregui/Views/FitWidgets/FitComparisonWidget.h b/GUI/coregui/Views/FitWidgets/FitComparisonWidget.h
index cbbda983f38..ea36347c446 100644
--- a/GUI/coregui/Views/FitWidgets/FitComparisonWidget.h
+++ b/GUI/coregui/Views/FitWidgets/FitComparisonWidget.h
@@ -31,6 +31,13 @@ public:
 
     void setItem(class SessionItem *item);
 
+protected:
+    void setJobItem(class JobItem *jobItem);
+
+private:
+    class ColorMapPlot *m_realDataPlot;
+    class ColorMapPlot *m_simulatedDataPlot;
+    class ColorMapPlot *m_chi2DataPlot;
 };
 
 #endif
-- 
GitLab