BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
JobQueueData.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Model/JobQueueData.h
6 //! @brief Defines class JobQueueData
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 
15 #ifndef BORNAGAIN_GUI_MODEL_MODEL_JOBQUEUEDATA_H
16 #define BORNAGAIN_GUI_MODEL_MODEL_JOBQUEUEDATA_H
17 
18 #include <QMap>
19 #include <QObject>
20 
21 class JobItem;
22 class JobModel;
23 class ISimulation;
24 class JobWorker;
25 
26 //! The JobQueueData class holds all objects/logic to run simulation in a thread.
27 
28 class JobQueueData : public QObject {
29  Q_OBJECT
30 public:
31  JobQueueData(JobModel* jobModel);
32 
33  bool hasUnfinishedJobs();
34 
35 signals:
36  void globalProgress(int);
37  void focusRequest(JobItem* jobItem);
38 
39 public slots:
40  void onStartedJob();
41  void onProgressUpdate();
42  void onFinishedJob();
43 
44  void onFinishedThread();
45  void onCancelAllJobs();
46 
47  void runJob(JobItem* jobItem);
48  void cancelJob(const QString& identifier);
49  void removeJob(const QString& identifier);
50 
51 private:
52  void assignForDeletion(QThread* thread);
53  void assignForDeletion(JobWorker* worker);
54  void clearSimulation(const QString& identifier);
55  void processFinishedJob(JobWorker* worker, JobItem* jobItem);
56 
57  void updateGlobalProgress();
58 
59  QThread* getThread(const QString& identifier);
60  JobWorker* getWorker(const QString& identifier);
61  ISimulation* getSimulation(const QString& identifier);
62 
63  QMap<QString, QThread*> m_threads; //! job identifier to the thread
64  QMap<QString, JobWorker*> m_workers; //! job identifier to jobWorker
65  QMap<QString, ISimulation*> m_simulations; //! job identifier to simulation
66 
68 };
69 
70 #endif // BORNAGAIN_GUI_MODEL_MODEL_JOBQUEUEDATA_H
The JobQueueData class holds all objects/logic to run simulation in a thread.
Definition: JobQueueData.h:28
JobWorker * getWorker(const QString &identifier)
Returns job runner for given identifier.
bool hasUnfinishedJobs()
void onStartedJob()
Sets JobItem properties when the job is going to start.
void focusRequest(JobItem *jobItem)
void updateGlobalProgress()
Estimates global progress from the progress of multiple running jobs and emits appropriate signal.
void globalProgress(int)
QThread * getThread(const QString &identifier)
Returns the thread for given identifier.
JobQueueData(JobModel *jobModel)
ISimulation * getSimulation(const QString &identifier)
Returns the simulation (if exists) for given identifier.
void removeJob(const QString &identifier)
Remove job from list completely.
void processFinishedJob(JobWorker *worker, JobItem *jobItem)
Set all data of finished job.
void cancelJob(const QString &identifier)
Cancels running job.
QMap< QString, ISimulation * > m_simulations
job identifier to jobWorker
Definition: JobQueueData.h:65
void clearSimulation(const QString &identifier)
void onFinishedJob()
Performs necessary actions when job is finished.
void onProgressUpdate()
void onFinishedThread()
void assignForDeletion(QThread *thread)
Removes QThread from the map of known threads, assigns it for deletion.
JobModel * m_jobModel
job identifier to simulation
Definition: JobQueueData.h:67
QMap< QString, JobWorker * > m_workers
job identifier to the thread
Definition: JobQueueData.h:64
QMap< QString, QThread * > m_threads
Definition: JobQueueData.h:63
void runJob(JobItem *jobItem)
Submits job and run it in a thread.
void onCancelAllJobs()
Cancels all running jobs.
The JobWorker class provides running the domain simulation in a thread.
Definition: JobWorker.h:28