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

Description

The JobPropertiesTableModel is a table model for the properties of a job except for the comment. The name of the job is editable, all other fields are read only.

Definition at line 26 of file JobPropertiesTableModel.h.

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

Public Member Functions

 JobPropertiesTableModel (QObject *parent=nullptr)
 
 ~JobPropertiesTableModel () override
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
void setItem (JobItem *item)
 

Private Member Functions

void notifyJobPropertyChange ()
 

Private Attributes

JobItemm_item
 

Constructor & Destructor Documentation

◆ JobPropertiesTableModel()

JobPropertiesTableModel::JobPropertiesTableModel ( QObject *  parent = nullptr)
explicit

Definition at line 47 of file JobPropertiesTableModel.cpp.

48  : QAbstractTableModel(parent)
49  , m_item(nullptr)
50 {
51 }

◆ ~JobPropertiesTableModel()

JobPropertiesTableModel::~JobPropertiesTableModel ( )
override

Definition at line 53 of file JobPropertiesTableModel.cpp.

54 {
55  if (m_item)
56  disconnect(m_item, nullptr, this, nullptr);
57 }

References m_item.

Member Function Documentation

◆ columnCount()

int JobPropertiesTableModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 66 of file JobPropertiesTableModel.cpp.

67 {
68  if (!parent.isValid() && m_item)
69  return NumColumns;
70  return 0;
71 }

References m_item.

◆ data()

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

Definition at line 73 of file JobPropertiesTableModel.cpp.

74 {
75  if ((role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::ToolTipRole)
76  || index.column() < 0 || index.column() >= NumColumns || index.row() < 0
77  || index.row() >= NumRows || !m_item)
78  return QVariant();
79 
80  switch (index.column()) {
81  case Column::Name:
82  return RowNames[index.row()];
83  case Column::Value: {
84  switch (index.row()) {
85  case Row::Name:
86  return m_item->jobName();
87  case Row::Sample:
88  return m_item->sampleName();
89  case Row::Instrument:
90  return m_item->instrumentName();
91  case Row::Status:
93  case Row::Begin:
94  if (role == Qt::ToolTipRole)
95  return QLocale().toString(m_item->beginTime(), QLocale::LongFormat);
96  return m_item->beginTime().toString(ModelDateShortFormat);
97  case Row::End:
98  if (role == Qt::ToolTipRole)
99  return QLocale().toString(m_item->endTime(), QLocale::LongFormat);
100  return m_item->endTime().toString(ModelDateShortFormat);
101  case Row::Duration: {
102  std::optional<size_t> duration = m_item->duration();
103  if (duration)
104  return QString("%1 s").arg(duration.value() / 1000., 0, 'f', 3);
105  return QVariant();
106  }
107  default:
108  return QVariant();
109  }
110  }
111  default:
112  return QVariant();
113  }
114 }
QString jobStatusToString(JobStatus status)
get a string representation of the status
Definition: JobStatus.cpp:32
QString instrumentName() const
Definition: JobItem.cpp:325
QDateTime endTime() const
Definition: JobItem.cpp:170
QString sampleName() const
Definition: JobItem.cpp:320
QString jobName() const
Definition: JobItem.cpp:84
QDateTime beginTime() const
Definition: JobItem.cpp:159
JobStatus getStatus() const
Definition: JobItem.cpp:106
std::optional< size_t > duration() const
if begin and end time are both available the duration in ms, otherwise empty
Definition: JobItem.cpp:181
constexpr auto Value("value")

References JobItem::beginTime(), JobItem::duration(), JobItem::endTime(), JobItem::getStatus(), JobItem::instrumentName(), JobItem::jobName(), jobStatusToString(), m_item, JobItem::sampleName(), and XML::Tags::Value().

Here is the call graph for this function:

◆ flags()

Qt::ItemFlags JobPropertiesTableModel::flags ( const QModelIndex &  index) const
override

Definition at line 125 of file JobPropertiesTableModel.cpp.

126 {
127  Qt::ItemFlags f = QAbstractTableModel::flags(index);
128  if (index.column() == Column::Value && index.row() == Row::Name && m_item)
129  f.setFlag(Qt::ItemIsEditable);
130  return f;
131 }

References m_item, and XML::Tags::Value().

Here is the call graph for this function:

◆ headerData()

QVariant JobPropertiesTableModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

Definition at line 116 of file JobPropertiesTableModel.cpp.

118 {
119  if (role == Qt::DisplayRole && orientation == Qt::Horizontal && section >= 0
120  && section < NumColumns)
121  return ColumnNames[section];
122  return QVariant();
123 }

◆ notifyJobPropertyChange()

void JobPropertiesTableModel::notifyJobPropertyChange ( )
private

Definition at line 157 of file JobPropertiesTableModel.cpp.

158 {
159  // name
160  connect(m_item, &JobItem::jobNameChanged, this, [=](const QString&) {
161  emit dataChanged(index(Row::Name, Column::Value), index(Row::Name, Column::Value),
162  {Qt::DisplayRole, Qt::EditRole});
163  });
164 
165  // status
166  connect(m_item, &JobItem::jobStatusChanged, this, [=](const JobStatus) {
167  emit dataChanged(index(Row::Status, Column::Value), index(Row::Status, Column::Value),
168  {Qt::DisplayRole, Qt::EditRole});
169  });
170 
171  // begin time
172  connect(m_item, &JobItem::jobBeginTimeChanged, this, [=](const QDateTime&) {
173  emit dataChanged(index(Row::Begin, Column::Value), index(Row::Begin, Column::Value),
174  {Qt::DisplayRole, Qt::EditRole});
175  });
176 
177  // end time and duration
178  connect(m_item, &JobItem::jobEndTimeChanged, this, [=](const QDateTime&) {
179  emit dataChanged(index(Row::End, Column::Value), index(Row::Duration, Column::Value),
180  {Qt::DisplayRole, Qt::EditRole});
181  });
182 }
JobStatus
The JobStatus enum lists the possible states of a job.
Definition: JobStatus.h:22
void jobStatusChanged(const JobStatus status)
void jobEndTimeChanged(const QDateTime &end_time)
void jobBeginTimeChanged(const QDateTime &begin_time)
void jobNameChanged(const QString &name)

References JobItem::jobBeginTimeChanged(), JobItem::jobEndTimeChanged(), JobItem::jobNameChanged(), JobItem::jobStatusChanged(), m_item, and XML::Tags::Value().

Referenced by setItem().

Here is the call graph for this function:

◆ rowCount()

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

Definition at line 59 of file JobPropertiesTableModel.cpp.

60 {
61  if (!parent.isValid() && m_item)
62  return NumRows;
63  return 0;
64 }

References m_item.

◆ setData()

bool JobPropertiesTableModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
override

Definition at line 133 of file JobPropertiesTableModel.cpp.

134 {
135  if (role != Qt::EditRole || index.column() != Column::Value || index.row() != Row::Name
136  || !m_item)
137  return false;
138  m_item->setJobName(value.toString());
139  return true;
140 }
void setJobName(const QString &name)
Definition: JobItem.cpp:89

References m_item, JobItem::setJobName(), and XML::Tags::Value().

Here is the call graph for this function:

◆ setItem()

void JobPropertiesTableModel::setItem ( JobItem item)

Definition at line 142 of file JobPropertiesTableModel.cpp.

143 {
144  beginResetModel();
145  if (m_item)
146  disconnect(m_item, nullptr, this, nullptr);
147  m_item = item;
148  if (m_item)
150  endResetModel();
151 }

References m_item, and notifyJobPropertyChange().

Referenced by JobPropertiesWidget::setItem().

Here is the call graph for this function:

Member Data Documentation

◆ m_item

JobItem* JobPropertiesTableModel::m_item
private

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