BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
FitWorkerLauncher.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Fit/FitWorkerLauncher.cpp
6 //! @brief Implements class FitWorkerLauncher
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/View/Fit/FitWorker.h"
17 #include <QThread>
18 
20  : QObject(parent)
21  , m_is_fit_running(false)
22 {
23 }
24 
25 void FitWorkerLauncher::runFitting(std::shared_ptr<FitObjectiveBuilder> suite)
26 {
27  if (!suite || m_is_fit_running)
28  return;
29 
30  auto* thread = new QThread();
31  auto* fw = new FitWorker(suite);
32  fw->moveToThread(thread);
33 
34  // start fitting when thread starts
35  connect(thread, &QThread::started, fw, &FitWorker::startFit);
37 
39  &FitWorker::interruptFitting, Qt::DirectConnection);
40 
43 
44  // delete fitting worker and thread when done
45  connect(fw, &FitWorker::finished, fw, &FitWorker::deleteLater);
46  connect(thread, &QThread::finished, thread, &QThread::deleteLater);
47 
48  m_is_fit_running = true;
49  thread->start();
50 }
51 
52 const QDateTime& FitWorkerLauncher::fitStart() const
53 {
54  return m_fit_start;
55 }
56 
57 const QDateTime& FitWorkerLauncher::fitEnd() const
58 {
59  return m_fit_end;
60 }
61 
63 {
64  if (m_is_fit_running)
65  emit intern_interruptFittingWorker(QPrivateSignal());
66 }
67 
69 {
70  m_is_fit_running = false;
71  m_fit_end = QDateTime::currentDateTime();
72  emit fittingFinished();
73 }
74 
76 {
77  m_fit_start = QDateTime::currentDateTime();
78  m_fit_end = QDateTime();
79  emit fittingStarted();
80 }
81 
82 void FitWorkerLauncher::intern_error(const QString& mesg)
83 {
84  emit fittingError(mesg);
85 }
Implements class FitWorkerLauncher.
Implements class FitWorker.
const QDateTime & fitEnd() const
void runFitting(std::shared_ptr< FitObjectiveBuilder > suite)
void intern_interruptFittingWorker(QPrivateSignal)
FitWorkerLauncher(QObject *parent)
std::atomic< bool > m_is_fit_running
void fittingError(const QString &message)
const QDateTime & fitStart() const
void intern_error(const QString &mesg)
void interruptFitting()
Definition: FitWorker.cpp:30
void startFit()
Definition: FitWorker.cpp:19
void started()
void finished()
void error(const QString &message)