From 074c9c922937f07937d4ebb7eb5e73e7024a38c1 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Fri, 20 Oct 2017 15:40:44 +0200
Subject: [PATCH] Bug in setting activity layout for new jobItem

---
 .../Views/CommonWidgets/ItemComboToolBar.cpp     |  2 +-
 .../Views/FitWidgets/FitActivityPanel.cpp        | 14 ++++----------
 GUI/coregui/Views/JobView.cpp                    | 16 ++++++++++------
 3 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/GUI/coregui/Views/CommonWidgets/ItemComboToolBar.cpp b/GUI/coregui/Views/CommonWidgets/ItemComboToolBar.cpp
index 5cfb81d436f..279a7d9fd27 100644
--- a/GUI/coregui/Views/CommonWidgets/ItemComboToolBar.cpp
+++ b/GUI/coregui/Views/CommonWidgets/ItemComboToolBar.cpp
@@ -49,7 +49,7 @@ void ItemComboToolBar::setPresentationList(const QStringList& presentationList,
     setComboConnected(false);
     m_comboBox->clear();
     m_comboBox->addItems(presentationList);
-    if (presentationList.contains(previous))
+    if (activeList.contains(previous))
         m_comboBox->setCurrentText(previous);
 
     if(!activeList.isEmpty())
diff --git a/GUI/coregui/Views/FitWidgets/FitActivityPanel.cpp b/GUI/coregui/Views/FitWidgets/FitActivityPanel.cpp
index 68c3421fa9d..fa4c7cfca25 100644
--- a/GUI/coregui/Views/FitWidgets/FitActivityPanel.cpp
+++ b/GUI/coregui/Views/FitWidgets/FitActivityPanel.cpp
@@ -83,16 +83,10 @@ void FitActivityPanel::setItem(JobItem* item)
         return;
     }
 
-    bool isNew(false);
-    m_stackedWidget->setItem(item, &isNew);
-
-    if (isNew) {
-        FitSessionWidget* widget = m_stackedWidget->currentWidget();
-        widget->setModelTuningWidget(m_realTimeWidget->parameterTuningWidget(item));
-    }
-
-    if (FitSessionWidget* widget = m_stackedWidget->currentWidget())
-        widget->setFitSessionActivity(m_fitActivityManager->sessionActivity(item));
+    m_stackedWidget->setItem(item);
+    FitSessionWidget* widget = m_stackedWidget->currentWidget();
+    widget->setModelTuningWidget(m_realTimeWidget->parameterTuningWidget(item));
+    widget->setFitSessionActivity(m_fitActivityManager->sessionActivity(item));
 }
 
 bool FitActivityPanel::isValidJobItem(JobItem* item)
diff --git a/GUI/coregui/Views/JobView.cpp b/GUI/coregui/Views/JobView.cpp
index 20ec826efea..80b278cc110 100644
--- a/GUI/coregui/Views/JobView.cpp
+++ b/GUI/coregui/Views/JobView.cpp
@@ -43,8 +43,8 @@ void JobView::onFocusRequest(JobItem* jobItem)
     if (jobItem->runInBackground())
         return;
 
-    setAppropriateActivityForJob(jobItem);
     m_docks->jobSelector()->makeJobItemSelected(jobItem);
+    setAppropriateActivityForJob(jobItem);
 
     emit focusRequest(MainWindow::JOB);
 }
@@ -67,7 +67,9 @@ void JobView::onDockMenuRequest()
 
 //! Propagates change in JobItem's selection down into main widgets.
 
-void JobView::onSelectionChanged(JobItem* jobItem) { m_docks->setItem(jobItem); }
+void JobView::onSelectionChanged(JobItem* jobItem) {
+    m_docks->setItem(jobItem);
+}
 
 void JobView::showEvent(QShowEvent*)
 {
@@ -136,8 +138,10 @@ void JobView::connectJobRelated()
 
 void JobView::setAppropriateActivityForJob(JobItem* jobItem)
 {
-    if (m_docks->jobSelector()->currentJobItem() != jobItem) {
-        if (jobItem->isValidForFitting())
-            setActivity(JobViewFlags::FITTING_ACTIVITY);
-    }
+    if (!jobItem) return;
+
+    if (jobItem->isValidForFitting())
+        setActivity(JobViewFlags::FITTING_ACTIVITY);
+    else
+        setActivity(JobViewFlags::JOB_VIEW_ACTIVITY);
 }
-- 
GitLab