BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
JobSelectorActions Class Reference

The JobSelectorActions class contains actions to run/remove jobs. More...

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

Public Slots

void equalizeSelectedToJob (int selected_id)
 Puts all IntensityDataItem axes range to the selected job. More...
 
void onContextMenuRequest (const QPoint &point, const QModelIndex &indexAtPoint={})
 Generates context menu at given point. More...
 
void onRemoveJob ()
 
void onRunJob ()
 

Public Member Functions

 JobSelectorActions (JobModel *jobModel, QObject *parent=0)
 
void setSelectionModel (QItemSelectionModel *selectionModel)
 

Private Member Functions

bool canRemoveJob (const QModelIndex &index) const
 
bool canRunJob (const QModelIndex &index) const
 
void initItemContextMenu (QMenu &menu, const QModelIndex &indexAtPoint)
 
void setAllActionsEnabled (bool value)
 
void setupEqualizeMenu (QMenu &menu)
 

Private Attributes

JobModelm_jobModel
 
QAction * m_removeJobAction
 
QAction * m_runJobAction
 
QItemSelectionModel * m_selectionModel
 

Detailed Description

The JobSelectorActions class contains actions to run/remove jobs.

Actions are used by the toolbar and JobSelectorList's context menu.

Definition at line 30 of file JobSelectorActions.h.

Constructor & Destructor Documentation

◆ JobSelectorActions()

JobSelectorActions::JobSelectorActions ( JobModel jobModel,
QObject *  parent = 0 
)

Definition at line 26 of file JobSelectorActions.cpp.

27  : QObject(parent)
28  , m_runJobAction(nullptr)
29  , m_removeJobAction(nullptr)
30  , m_selectionModel(nullptr)
31  , m_jobModel(jobModel)
32 {
33  m_runJobAction = new QAction("Run", this);
34  m_runJobAction->setIcon(QIcon(":/images/play.svg"));
35  m_runJobAction->setToolTip("Run currently selected job");
36  connect(m_runJobAction, &QAction::triggered, this, &JobSelectorActions::onRunJob);
37 
38  m_removeJobAction = new QAction("Remove", this);
39  m_removeJobAction->setIcon(QIcon(":/images/delete.svg"));
40  m_removeJobAction->setToolTip("Remove currently selected job.");
41  connect(m_removeJobAction, &QAction::triggered, this, &JobSelectorActions::onRemoveJob);
42 }
QItemSelectionModel * m_selectionModel

References m_removeJobAction, m_runJobAction, onRemoveJob(), and onRunJob().

Here is the call graph for this function:

Member Function Documentation

◆ canRemoveJob()

bool JobSelectorActions::canRemoveJob ( const QModelIndex &  index) const
private

Definition at line 173 of file JobSelectorActions.cpp.

174 {
175  if (!index.isValid())
176  return false;
177 
178  const JobItem* jobItem = m_jobModel->getJobItemForIndex(index);
179  if (jobItem->isRunning() || jobItem->getStatus() == "Fitting")
180  return false;
181 
182  return true;
183 }
QString getStatus() const
Definition: JobItem.cpp:123
bool isRunning() const
Definition: JobItem.cpp:145
const JobItem * getJobItemForIndex(const QModelIndex &index) const
Definition: JobModel.cpp:46

References JobModel::getJobItemForIndex(), JobItem::getStatus(), JobItem::isRunning(), and m_jobModel.

Referenced by initItemContextMenu(), and onRemoveJob().

Here is the call graph for this function:

◆ canRunJob()

bool JobSelectorActions::canRunJob ( const QModelIndex &  index) const
private

Definition at line 160 of file JobSelectorActions.cpp.

161 {
162  if (!index.isValid())
163  return false;
164 
165  const JobItem* jobItem = m_jobModel->getJobItemForIndex(index);
166 
167  if (jobItem->isRunning() || jobItem->getStatus() == "Fitting")
168  return false;
169 
170  return true;
171 }

References JobModel::getJobItemForIndex(), JobItem::getStatus(), JobItem::isRunning(), and m_jobModel.

Referenced by initItemContextMenu(), and onRunJob().

Here is the call graph for this function:

◆ equalizeSelectedToJob

void JobSelectorActions::equalizeSelectedToJob ( int  selected_id)
slot

Puts all IntensityDataItem axes range to the selected job.

Definition at line 82 of file JobSelectorActions.cpp.

83 {
84  QModelIndexList selectedList = m_selectionModel->selectedIndexes();
85 
86  if (selected_id >= selectedList.size())
87  return;
88 
89  JobItem* referenceItem = m_jobModel->getJobItemForIndex(selectedList.at(selected_id));
90  ASSERT(referenceItem);
91 
92  IntensityDataItem* referenceDataItem = referenceItem->intensityDataItem();
93  if (!referenceDataItem)
94  return;
95 
96  for (auto index : selectedList) {
97  JobItem* jobItem = m_jobModel->getJobItemForIndex(index);
98  if (jobItem == referenceItem)
99  continue;
100  if (IntensityDataItem* dataItem = jobItem->intensityDataItem()) {
101  dataItem->setLowerX(referenceDataItem->getLowerX());
102  dataItem->setUpperX(referenceDataItem->getUpperX());
103  dataItem->setLowerY(referenceDataItem->getLowerY());
104  dataItem->setUpperY(referenceDataItem->getUpperY());
105  dataItem->setLowerZ(referenceDataItem->getLowerZ());
106  dataItem->setUpperZ(referenceDataItem->getUpperZ());
107  }
108  }
109 }
#define ASSERT(condition)
Definition: Assert.h:31
double getLowerZ() const
returns lower and upper zoom ranges of z-axis
double getLowerY() const
returns lower and upper zoom ranges of y-axis
double getUpperY() const
double getUpperX() const
double getLowerX() const
returns lower and upper zoom ranges of x-axis
double getUpperZ() const
IntensityDataItem * intensityDataItem()
Definition: JobItem.cpp:113

References ASSERT, JobModel::getJobItemForIndex(), IntensityDataItem::getLowerX(), IntensityDataItem::getLowerY(), IntensityDataItem::getLowerZ(), IntensityDataItem::getUpperX(), IntensityDataItem::getUpperY(), IntensityDataItem::getUpperZ(), JobItem::intensityDataItem(), m_jobModel, and m_selectionModel.

Referenced by setupEqualizeMenu().

Here is the call graph for this function:

◆ initItemContextMenu()

void JobSelectorActions::initItemContextMenu ( QMenu &  menu,
const QModelIndex &  indexAtPoint 
)
private

Definition at line 111 of file JobSelectorActions.cpp.

112 {
113  menu.setToolTipsVisible(true);
114 
115  menu.addAction(m_runJobAction);
116  menu.addAction(m_removeJobAction);
117 
118  QModelIndex targetIndex = indexAtPoint;
119  if (!targetIndex.isValid()) {
120  QModelIndexList indexList = m_selectionModel->selectedIndexes();
121  if (!indexList.empty())
122  targetIndex = indexList.first();
123  }
124  m_runJobAction->setEnabled(canRunJob(targetIndex));
125  m_removeJobAction->setEnabled(canRemoveJob(targetIndex));
126 
127  setupEqualizeMenu(menu);
128 }
void setupEqualizeMenu(QMenu &menu)
bool canRemoveJob(const QModelIndex &index) const
bool canRunJob(const QModelIndex &index) const

References canRemoveJob(), canRunJob(), m_removeJobAction, m_runJobAction, m_selectionModel, and setupEqualizeMenu().

Referenced by onContextMenuRequest().

Here is the call graph for this function:

◆ onContextMenuRequest

void JobSelectorActions::onContextMenuRequest ( const QPoint &  point,
const QModelIndex &  indexAtPoint = {} 
)
slot

Generates context menu at given point.

If indexAtPoint is provided, the actions will be done for corresponding JobItem

Definition at line 72 of file JobSelectorActions.cpp.

73 {
74  QMenu menu;
75  initItemContextMenu(menu, indexAtPoint);
76  menu.exec(point);
78 }
void initItemContextMenu(QMenu &menu, const QModelIndex &indexAtPoint)
void setAllActionsEnabled(bool value)

References initItemContextMenu(), and setAllActionsEnabled().

Referenced by JobSelectorWidget::JobSelectorWidget().

Here is the call graph for this function:

◆ onRemoveJob

void JobSelectorActions::onRemoveJob ( )
slot

Definition at line 58 of file JobSelectorActions.cpp.

59 {
60  QList<QPersistentModelIndex> toRemove;
61  for (auto index : m_selectionModel->selectedIndexes())
62  if (canRemoveJob(index))
63  toRemove.append(QPersistentModelIndex(index));
64 
65  for (auto index : toRemove)
66  m_jobModel->removeJob(index);
67 }
void removeJob(const QModelIndex &index)
Definition: JobModel.cpp:189

References canRemoveJob(), m_jobModel, m_selectionModel, and JobModel::removeJob().

Referenced by JobSelectorActions(), and JobSelectorToolBar::JobSelectorToolBar().

Here is the call graph for this function:

◆ onRunJob

void JobSelectorActions::onRunJob ( )
slot

Definition at line 49 of file JobSelectorActions.cpp.

50 {
51  QModelIndexList indexList = m_selectionModel->selectedIndexes();
52  for (auto index : indexList) {
53  if (canRunJob(index))
54  m_jobModel->runJob(index);
55  }
56 }
void runJob(const QModelIndex &index)
Definition: JobModel.cpp:179

References canRunJob(), m_jobModel, m_selectionModel, and JobModel::runJob().

Referenced by JobSelectorActions(), and JobSelectorToolBar::JobSelectorToolBar().

Here is the call graph for this function:

◆ setAllActionsEnabled()

void JobSelectorActions::setAllActionsEnabled ( bool  value)
private

Definition at line 154 of file JobSelectorActions.cpp.

155 {
156  m_runJobAction->setEnabled(value);
157  m_removeJobAction->setEnabled(value);
158 }

References m_removeJobAction, and m_runJobAction.

Referenced by onContextMenuRequest().

◆ setSelectionModel()

void JobSelectorActions::setSelectionModel ( QItemSelectionModel *  selectionModel)

Definition at line 44 of file JobSelectorActions.cpp.

45 {
46  m_selectionModel = selectionModel;
47 }

References m_selectionModel.

Referenced by JobSelectorWidget::JobSelectorWidget().

◆ setupEqualizeMenu()

void JobSelectorActions::setupEqualizeMenu ( QMenu &  menu)
private

Definition at line 130 of file JobSelectorActions.cpp.

131 {
132  menu.addSeparator();
133 
134  QMenu* equalize_menu = menu.addMenu("Equalize selected plots");
135  equalize_menu->setToolTipsVisible(true);
136  equalize_menu->setToolTip(
137  "All plots from the list of selected jobs will be equalized to the one.");
138  QModelIndexList selected = m_selectionModel->selectedIndexes();
139 
140  if (selected.size() <= 1) {
141  equalize_menu->setDisabled(true);
142  return;
143  }
144  std::sort(selected.begin(), selected.end(),
145  [](const QModelIndex& a, const QModelIndex& b) { return a.row() < b.row(); });
146 
147  for (int i = 0; i < selected.count(); ++i) {
148  JobItem* jobItem = m_jobModel->getJobItemForIndex(selected.at(i));
149  QAction* action = equalize_menu->addAction(QString("to ").append(jobItem->itemName()));
150  connect(action, &QAction::triggered, [=] { equalizeSelectedToJob(i); });
151  }
152 }
void equalizeSelectedToJob(int selected_id)
Puts all IntensityDataItem axes range to the selected job.
QString itemName() const
Get item name, return display name if no name is set.

References equalizeSelectedToJob(), JobModel::getJobItemForIndex(), SessionItem::itemName(), m_jobModel, and m_selectionModel.

Referenced by initItemContextMenu().

Here is the call graph for this function:

Member Data Documentation

◆ m_jobModel

JobModel* JobSelectorActions::m_jobModel
private

◆ m_removeJobAction

QAction* JobSelectorActions::m_removeJobAction
private

◆ m_runJobAction

QAction* JobSelectorActions::m_runJobAction
private

◆ m_selectionModel

QItemSelectionModel* JobSelectorActions::m_selectionModel
private

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