BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
JobListModel Class Reference

Description

Definition at line 23 of file JobListModel.h.

Inheritance diagram for JobListModel:
[legend]
Collaboration diagram for JobListModel:
[legend]

Public Member Functions

 JobListModel (JobModel *jobs, QObject *parent=nullptr)
 
 ~JobListModel () override
 
void cancelJob (const QModelIndex &index)
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
QModelIndex indexForJob (JobItem *job)
 
JobItemjobForIndex (const QModelIndex &index) const
 
void removeJob (const QModelIndex &index)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
void runJob (const QModelIndex &index)
 

Private Slots

void emitJobListModelChanged (JobItem *job)
 
void onRowsAboutToBeInserted (const QModelIndex &parent, int start, int end)
 
void onRowsInserted (const QModelIndex &parent, int start, int end)
 

Private Member Functions

void disableJobNotification (JobItem *job)
 
void enableJobNotification (JobItem *job)
 

Private Attributes

JobModelm_jobs
 

Constructor & Destructor Documentation

◆ JobListModel()

JobListModel::JobListModel ( JobModel jobs,
QObject *  parent = nullptr 
)

Definition at line 27 of file JobListModel.cpp.

28  : QAbstractListModel(parent)
29  , m_jobs(jobs)
30 {
31  for (JobItem* job : m_jobs->jobItems())
33 
34  connect(jobs, &QAbstractItemModel::rowsAboutToBeInserted, this,
36  connect(jobs, &QAbstractItemModel::rowsInserted, this, &JobListModel::onRowsInserted);
37 }
void onRowsInserted(const QModelIndex &parent, int start, int end)
JobModel * m_jobs
Definition: JobListModel.h:51
void enableJobNotification(JobItem *job)
void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
QVector< JobItem * > jobItems() const
Definition: JobModel.cpp:77

References enableJobNotification(), JobModel::jobItems(), m_jobs, onRowsAboutToBeInserted(), and onRowsInserted().

Here is the call graph for this function:

◆ ~JobListModel()

JobListModel::~JobListModel ( )
override

Definition at line 39 of file JobListModel.cpp.

40 {
41  for (JobItem* job : m_jobs->jobItems()) {
43  }
44 }
void disableJobNotification(JobItem *job)

References disableJobNotification(), JobModel::jobItems(), and m_jobs.

Here is the call graph for this function:

Member Function Documentation

◆ cancelJob()

void JobListModel::cancelJob ( const QModelIndex &  index)

Definition at line 95 of file JobListModel.cpp.

96 {
97  m_jobs->cancelJob(jobForIndex(index));
98 }
JobItem * jobForIndex(const QModelIndex &index) const
void cancelJob(JobItem *jobItem)
Definition: JobModel.cpp:147

References JobModel::cancelJob(), jobForIndex(), and m_jobs.

Referenced by JobListView::onCancel().

Here is the call graph for this function:

◆ data()

QVariant JobListModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 51 of file JobListModel.cpp.

52 {
53  QVector<JobItem*> jobs = m_jobs->jobItems();
54  if (!index.isValid() || index.row() >= jobs.size() || index.row() < 0)
55  return {};
56 
57  JobItem* item = jobs[index.row()];
58  if (role == Qt::DisplayRole)
59  return item->jobName();
60 
61  return {};
62 }
QString jobName() const
Definition: JobItem.cpp:84

References JobModel::jobItems(), JobItem::jobName(), and m_jobs.

Here is the call graph for this function:

◆ disableJobNotification()

void JobListModel::disableJobNotification ( JobItem job)
private

Definition at line 148 of file JobListModel.cpp.

149 {
150  disconnect(job, nullptr, this, nullptr);
151 }

Referenced by ~JobListModel(), and removeJob().

◆ emitJobListModelChanged

void JobListModel::emitJobListModelChanged ( JobItem job)
privateslot

Definition at line 100 of file JobListModel.cpp.

101 {
102  QVector<JobItem*> jobs = m_jobs->jobItems();
103  int i = jobs.indexOf(job);
104  if (i != -1) {
105  QModelIndex idx = index(i, 0);
106  emit dataChanged(idx, idx);
107  }
108 }

References JobModel::jobItems(), and m_jobs.

Referenced by enableJobNotification().

Here is the call graph for this function:

◆ enableJobNotification()

void JobListModel::enableJobNotification ( JobItem job)
private

Definition at line 134 of file JobListModel.cpp.

135 {
136  // name
137  connect(job, &JobItem::jobNameChanged, this,
138  [=](const QString&) { emitJobListModelChanged(job); });
139 
140  // status
141  connect(job, &JobItem::jobStatusChanged, this,
142  [=](const JobStatus) { emitJobListModelChanged(job); });
143 
144  // progress
145  connect(job, &JobItem::jobProgressChanged, this, [=](int) { emitJobListModelChanged(job); });
146 }
JobStatus
The JobStatus enum lists the possible states of a job.
Definition: JobStatus.h:22
void jobStatusChanged(const JobStatus status)
void jobProgressChanged(int progress)
void jobNameChanged(const QString &name)
void emitJobListModelChanged(JobItem *job)

References emitJobListModelChanged(), JobItem::jobNameChanged(), JobItem::jobProgressChanged(), and JobItem::jobStatusChanged().

Referenced by JobListModel(), and onRowsInserted().

Here is the call graph for this function:

◆ indexForJob()

QModelIndex JobListModel::indexForJob ( JobItem job)

Definition at line 72 of file JobListModel.cpp.

73 {
74  QVector<JobItem*> jobs = m_jobs->jobItems();
75  int idx = jobs.indexOf(job);
76  if (idx != -1)
77  return index(idx, 0);
78  return {};
79 }

References JobModel::jobItems(), and m_jobs.

Referenced by JobListView::selectJob().

Here is the call graph for this function:

◆ jobForIndex()

JobItem * JobListModel::jobForIndex ( const QModelIndex &  index) const

Definition at line 64 of file JobListModel.cpp.

65 {
66  QVector<JobItem*> jobs = m_jobs->jobItems();
67  if (index.row() >= 0 && index.row() < jobs.size())
68  return jobs[index.row()];
69  return nullptr;
70 }

References JobModel::jobItems(), and m_jobs.

Referenced by cancelJob(), JobListView::equalizeSelectedToJob(), removeJob(), runJob(), JobListView::selectedJobs(), JobListView::showContextMenu(), and JobListView::updateActions().

Here is the call graph for this function:

◆ onRowsAboutToBeInserted

void JobListModel::onRowsAboutToBeInserted ( const QModelIndex &  parent,
int  start,
int  end 
)
privateslot

Definition at line 114 of file JobListModel.cpp.

115 {
116  if (!parent.isValid())
117  beginInsertRows(QModelIndex(), start, end);
118 }

Referenced by JobListModel().

◆ onRowsInserted

void JobListModel::onRowsInserted ( const QModelIndex &  parent,
int  start,
int  end 
)
privateslot

Definition at line 120 of file JobListModel.cpp.

121 {
122  if (!parent.isValid()) {
123  endInsertRows();
124  QVector<JobItem*> jobs = m_jobs->jobItems();
125  for (int i = start; i <= end; i++)
126  enableJobNotification(jobs.at(i));
127  }
128 }

References enableJobNotification(), JobModel::jobItems(), and m_jobs.

Referenced by JobListModel().

Here is the call graph for this function:

◆ removeJob()

void JobListModel::removeJob ( const QModelIndex &  index)

Definition at line 86 of file JobListModel.cpp.

87 {
88  beginRemoveRows(QModelIndex(), index.row(), index.row());
89  JobItem* job = jobForIndex(index);
91  m_jobs->removeJob(job);
92  endRemoveRows();
93 }
void removeJob(JobItem *jobItem)
Definition: JobModel.cpp:152

References disableJobNotification(), jobForIndex(), m_jobs, and JobModel::removeJob().

Referenced by JobListView::onRemove().

Here is the call graph for this function:

◆ rowCount()

int JobListModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 46 of file JobListModel.cpp.

47 {
48  return m_jobs->jobItems().size();
49 }

References JobModel::jobItems(), and m_jobs.

Referenced by JobListView::ensureItemSelected().

Here is the call graph for this function:

◆ runJob()

void JobListModel::runJob ( const QModelIndex &  index)

Definition at line 81 of file JobListModel.cpp.

82 {
83  m_jobs->runJob(jobForIndex(index));
84 }
void runJob(JobItem *jobItem)
Definition: JobModel.cpp:142

References jobForIndex(), m_jobs, and JobModel::runJob().

Referenced by JobListView::onRun().

Here is the call graph for this function:

Member Data Documentation

◆ m_jobs


The documentation for this class was generated from the following files: