BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
FitSessionManager.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Fit/FitSessionManager.cpp
6 //! @brief Implements class FitSessionManager
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "GUI/Model/Job/JobItem.h"
17 #include "GUI/Util/Error.h"
18 #include "GUI/View/Fit/FitLog.h"
20 
22  : QObject(parent)
23  , m_activeController(nullptr)
24 {
25 }
26 
28 {
29  for (auto* jobItem : m_item_to_controller.keys())
30  disconnect(jobItem, nullptr, this, nullptr);
31 }
32 
34 {
35  FitSessionController* result(nullptr);
36 
37  auto it = m_item_to_controller.find(jobItem);
38  if (it == m_item_to_controller.end()) {
39  result = createController(jobItem);
40  m_item_to_controller.insert(jobItem, result);
41  } else {
42  result = it.value();
43  }
44 
45  m_activeController = result;
46 
47  return result;
48 }
49 
51 {
52  // job destruction
53  connect(jobItem, &JobItem::jobDestroyed, this, [=]() { removeController(jobItem); });
54 
55  auto* result = new FitSessionController(this);
56  result->setItem(jobItem);
57  return result;
58 }
59 
60 //! Removes manager for given jobItem
61 
63 {
64  auto it = m_item_to_controller.find(jobItem);
65  if (it == m_item_to_controller.end())
66  throw Error("FitActivityManager::removeFitSession() -> Error. "
67  "Can't find fit session");
68 
69  if (m_activeController == it.value())
70  m_activeController = nullptr;
71  delete it.value();
72  m_item_to_controller.erase(it);
73 }
Defines error class.
Defines class FitLog.
Defines class FitSessionController.
Defines class FitSessionManager.
Defines class JobItem.
Controls all activity related to the single fitting task for JobItem. Provides interaction between Fi...
FitSessionManager(QObject *parent=nullptr)
FitSessionController * m_activeController
FitSessionController * createController(JobItem *jobItem)
FitSessionController * sessionController(JobItem *jobItem)
void removeController(JobItem *jobItem)
Fit controller which is currently attached to jobMessagePanel.
QMap< JobItem *, FitSessionController * > m_item_to_controller
void jobDestroyed()