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

Description

Main widget for real time parameter tuning. Contains a tree for parameter tuning and the model to provide drag-and-drop in FitActivityPanel.

Definition at line 34 of file ParameterTuningWidget.h.

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

Public Slots

void makeSelected (ParameterItem *item)
 
void onCurrentLinkChanged (ParameterItem *item)
 
void onLockZValueChanged (bool value)
 
void onSliderValueChanged (double value)
 
void restoreModelsOfCurrentJobItem ()
 

Signals

void itemContextMenuRequest (const QPoint &point)
 

Public Member Functions

 ParameterTuningWidget (QWidget *parent=nullptr)
 
virtual QList< QAction * > actionList ()
 
SessionItemcurrentItem ()
 
const SessionItemcurrentItem () const
 
QVector< ParameterItem * > getSelectedParameters ()
 Returns list of ParameterItem's currently selected in parameter tree. More...
 
QItemSelectionModel * selectionModel ()
 
virtual void setItem (SessionItem *item)
 

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *) override
 
void hideEvent (QHideEvent *) override
 
void showEvent (QShowEvent *) override
 
void subscribeToItem () override
 
virtual void unsubscribeFromItem ()
 

Private Slots

void onCustomContextMenuRequested (const QPoint &point)
 
void updateParameterModel ()
 

Private Member Functions

void closeActiveEditors ()
 
JobItemjobItem ()
 
void setTuningDelegateEnabled (bool enabled)
 Sets delegate to enabled/disabled state. In 'disabled' state the delegate is in ReadOnlyMode, if it was containing already some editing widget, it will be forced to close. More...
 
void updateDragAndDropSettings ()
 Disable drag-and-drop abilities, if job is in fit running state. More...
 
void updateJobStatus ()
 

Private Attributes

CautionSignm_cautionSign
 
ParameterTuningDelegatem_delegate
 
SessionItemControllerm_itemController
 
JobModelm_jobModel
 
ParameterTuningModelm_parameterTuningModel
 
SliderSettingsWidgetm_sliderSettingsWidget
 
QTreeView * m_treeView
 

Constructor & Destructor Documentation

◆ ParameterTuningWidget()

ParameterTuningWidget::ParameterTuningWidget ( QWidget *  parent = nullptr)
explicit

Definition at line 30 of file ParameterTuningWidget.cpp.

31  : SessionItemWidget(parent)
32  , m_jobModel(nullptr)
33  , m_parameterTuningModel(nullptr)
35  , m_treeView(new QTreeView)
38 {
39  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
40 
41  m_treeView->setItemDelegate(m_delegate);
42  m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
43  m_treeView->setDragDropMode(QAbstractItemView::NoDragDrop);
44  m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false);
45 
46  auto* resetValuesAction = new QAction(QIcon(":/images/undo-variant.svg"), "Reset values", this);
47  resetValuesAction->setToolTip("Reset parameter tree to initial values");
48  connect(resetValuesAction, &QAction::triggered, this,
50 
51  auto* toolbar = new StyledToolbar(this);
52  toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
53  toolbar->addAction(resetValuesAction);
54 
55  auto* mainLayout = new QVBoxLayout;
56  mainLayout->setMargin(0);
57  mainLayout->setSpacing(0);
58  mainLayout->addWidget(toolbar);
59  mainLayout->addWidget(m_sliderSettingsWidget);
60  mainLayout->addWidget(m_treeView);
61  setLayout(mainLayout);
62 
69  connect(m_treeView, &QTreeView::customContextMenuRequested, this,
71 }
The CautionSign controls appearance of CautionSignWidget on top of parent widget.
Definition: CautionSign.h:25
void currentLinkChanged(ParameterItem *item)
void onCustomContextMenuRequested(const QPoint &point)
ParameterTuningModel * m_parameterTuningModel
void onLockZValueChanged(bool value)
SliderSettingsWidget * m_sliderSettingsWidget
ParameterTuningDelegate * m_delegate
void onCurrentLinkChanged(ParameterItem *item)
void onSliderValueChanged(double value)
SessionItemWidget(QWidget *parent=nullptr)
void sliderRangeFactorChanged(double value)
void lockzChanged(bool value)
The StyledToolbar class represents our standard narrow toolbar with the height 24 pixels.
Definition: StyledToolbar.h:22

References ParameterTuningDelegate::currentLinkChanged(), SliderSettingsWidget::lockzChanged(), m_delegate, m_sliderSettingsWidget, m_treeView, onCurrentLinkChanged(), onCustomContextMenuRequested(), onLockZValueChanged(), onSliderValueChanged(), restoreModelsOfCurrentJobItem(), and SliderSettingsWidget::sliderRangeFactorChanged().

Here is the call graph for this function:

Member Function Documentation

◆ actionList()

QList< QAction * > SessionItemWidget::actionList ( )
virtualinherited

◆ closeActiveEditors()

void ParameterTuningWidget::closeActiveEditors ( )
private

Definition at line 215 of file ParameterTuningWidget.cpp.

216 {
217  QModelIndex index = m_treeView->currentIndex();
218  QWidget* editor = m_treeView->indexWidget(index);
219  if (editor) {
220  // m_delegate->commitData(editor);
221  m_delegate->closeEditor(editor, QAbstractItemDelegate::NoHint);
222  }
223  m_treeView->selectionModel()->clearSelection();
224 }

References m_delegate, and m_treeView.

Referenced by restoreModelsOfCurrentJobItem(), and setTuningDelegateEnabled().

◆ contextMenuEvent()

void ParameterTuningWidget::contextMenuEvent ( QContextMenuEvent *  )
overrideprotected

Definition at line 164 of file ParameterTuningWidget.cpp.

165 {
166  // reimplemented to suppress context menu from QMainWindow
167 }

◆ currentItem() [1/2]

◆ currentItem() [2/2]

const SessionItem * SessionItemWidget::currentItem ( ) const
inherited

Definition at line 46 of file SessionItemWidget.cpp.

47 {
48  return m_itemController->currentItem();
49 }
SessionItemController * m_itemController

References SessionItemController::currentItem(), and SessionItemWidget::m_itemController.

Here is the call graph for this function:

◆ getSelectedParameters()

QVector< ParameterItem * > ParameterTuningWidget::getSelectedParameters ( )

Returns list of ParameterItem's currently selected in parameter tree.

Definition at line 81 of file ParameterTuningWidget.cpp.

82 {
83  QVector<ParameterItem*> result;
84  for (auto index : selectionModel()->selectedIndexes())
86  result.push_back(parItem);
87 
88  return result;
89 }
The ParameterItem class represent a tuning value in a parameter tuning tree.
ParameterItem * getParameterItem(const QModelIndex &index) const
Returns ParameterItem from given index.
QItemSelectionModel * selectionModel()

References ParameterTuningModel::getParameterItem(), m_parameterTuningModel, and selectionModel().

Referenced by FitParameterWidget::canCreateFitParameter(), FitParameterWidget::canRemoveFromFitParameters(), FitParameterWidget::onAddToFitParAction(), FitParameterWidget::onCreateFitParAction(), and FitParameterWidget::onRemoveFromFitParAction().

Here is the call graph for this function:

◆ hideEvent()

void SessionItemWidget::hideEvent ( QHideEvent *  )
overrideprotectedinherited

Definition at line 56 of file SessionItemWidget.cpp.

57 {
59 }
void unsubscribe()
Fully unsubscribes the parent from listening item's signals. Controller stays active to track item de...

References SessionItemWidget::m_itemController, and SessionItemController::unsubscribe().

Here is the call graph for this function:

◆ itemContextMenuRequest

void ParameterTuningWidget::itemContextMenuRequest ( const QPoint &  point)
signal

◆ jobItem()

JobItem * ParameterTuningWidget::jobItem ( )
private

Definition at line 182 of file ParameterTuningWidget.cpp.

183 {
184  return dynamic_cast<JobItem*>(currentItem());
185 }

References SessionItemWidget::currentItem().

Referenced by onCurrentLinkChanged(), onLockZValueChanged(), restoreModelsOfCurrentJobItem(), subscribeToItem(), updateDragAndDropSettings(), updateJobStatus(), and updateParameterModel().

Here is the call graph for this function:

◆ makeSelected

void ParameterTuningWidget::makeSelected ( ParameterItem item)
slot

Definition at line 157 of file ParameterTuningWidget.cpp.

158 {
159  QModelIndex index = m_parameterTuningModel->indexForItem(item);
160  if (index.isValid())
161  selectionModel()->select(index, QItemSelectionModel::Select);
162 }
QModelIndex indexForItem(ParameterItem *item) const

References ParameterTuningModel::indexForItem(), m_parameterTuningModel, and selectionModel().

Referenced by FitParameterWidget::onFitParametersSelectionChanged().

Here is the call graph for this function:

◆ onCurrentLinkChanged

void ParameterTuningWidget::onCurrentLinkChanged ( ParameterItem item)
slot

Definition at line 91 of file ParameterTuningWidget.cpp.

92 {
93  ASSERT(jobItem());
94 
95  if (jobItem()->isRunning())
96  return;
97 
98  if (item) {
99  // link.updateItem(); // FIXME circular dependency if uncomment
101  }
102 }
void runJob(JobItem *jobItem)
Definition: JobModel.cpp:142

References jobItem(), m_jobModel, and JobModel::runJob().

Referenced by ParameterTuningWidget().

Here is the call graph for this function:

◆ onCustomContextMenuRequested

void ParameterTuningWidget::onCustomContextMenuRequested ( const QPoint &  point)
privateslot

Definition at line 138 of file ParameterTuningWidget.cpp.

139 {
140  emit itemContextMenuRequest(m_treeView->mapToGlobal(point + QPoint(2, 22)));
141 }
void itemContextMenuRequest(const QPoint &point)

References itemContextMenuRequest(), and m_treeView.

Referenced by ParameterTuningWidget().

◆ onLockZValueChanged

void ParameterTuningWidget::onLockZValueChanged ( bool  value)
slot

Definition at line 109 of file ParameterTuningWidget.cpp.

110 {
111  if (!jobItem())
112  return;
115 }
void setZAxisLocked(bool state)
IntensityDataItem * intensityDataItem(SessionItem *parent)
Returns IntensityDataItem contained as a child in givent parent.

References GUI::Model::DataItemUtils::intensityDataItem(), jobItem(), and IntensityDataItem::setZAxisLocked().

Referenced by ParameterTuningWidget().

Here is the call graph for this function:

◆ onSliderValueChanged

void ParameterTuningWidget::onSliderValueChanged ( double  value)
slot

Definition at line 104 of file ParameterTuningWidget.cpp.

105 {
107 }
void setSliderRangeFactor(double value)

References m_delegate, and ParameterTuningDelegate::setSliderRangeFactor().

Referenced by ParameterTuningWidget().

Here is the call graph for this function:

◆ restoreModelsOfCurrentJobItem

void ParameterTuningWidget::restoreModelsOfCurrentJobItem ( )
slot

Definition at line 143 of file ParameterTuningWidget.cpp.

144 {
145  ASSERT(m_jobModel);
146  ASSERT(jobItem());
147 
148  if (jobItem()->isRunning())
149  return;
150 
152 
155 }
void restore(JobItem *jobItem)
restore instrument and sample model from backup for given JobItem
Definition: JobModel.cpp:83

References closeActiveEditors(), jobItem(), m_jobModel, JobModel::restore(), and JobModel::runJob().

Referenced by ParameterTuningWidget().

Here is the call graph for this function:

◆ selectionModel()

QItemSelectionModel * ParameterTuningWidget::selectionModel ( )

Definition at line 73 of file ParameterTuningWidget.cpp.

74 {
75  ASSERT(m_treeView);
76  return m_treeView->selectionModel();
77 }

References m_treeView.

Referenced by getSelectedParameters(), makeSelected(), and FitParameterWidget::onFitParametersSelectionChanged().

◆ setItem()

◆ setTuningDelegateEnabled()

void ParameterTuningWidget::setTuningDelegateEnabled ( bool  enabled)
private

Sets delegate to enabled/disabled state. In 'disabled' state the delegate is in ReadOnlyMode, if it was containing already some editing widget, it will be forced to close.

Definition at line 205 of file ParameterTuningWidget.cpp.

206 {
207  if (enabled)
208  m_delegate->setReadOnly(false);
209  else {
210  m_delegate->setReadOnly(true);
212  }
213 }
void setReadOnly(bool isReadOnly)

References closeActiveEditors(), m_delegate, and ParameterTuningDelegate::setReadOnly().

Referenced by updateDragAndDropSettings().

Here is the call graph for this function:

◆ showEvent()

void SessionItemWidget::showEvent ( QShowEvent *  )
overrideprotectedinherited

Definition at line 51 of file SessionItemWidget.cpp.

52 {
54 }

References SessionItemWidget::m_itemController, and SessionItemController::subscribe().

Here is the call graph for this function:

◆ subscribeToItem()

void ParameterTuningWidget::subscribeToItem ( )
overrideprotectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 169 of file ParameterTuningWidget.cpp.

170 {
171  m_jobModel = dynamic_cast<JobModel*>(jobItem()->model());
172 
175 
176  connect(jobItem(), &JobItem::jobStatusChanged, this,
177  [=](const JobStatus) { updateJobStatus(); });
178 
179  updateJobStatus();
180 }
JobStatus
The JobStatus enum lists the possible states of a job.
Definition: JobStatus.h:22
void jobStatusChanged(const JobStatus status)
void updateDragAndDropSettings()
Disable drag-and-drop abilities, if job is in fit running state.
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:60

References jobItem(), JobItem::jobStatusChanged(), m_jobModel, SessionItem::model(), updateDragAndDropSettings(), updateJobStatus(), and updateParameterModel().

Here is the call graph for this function:

◆ unsubscribeFromItem()

virtual void SessionItemWidget::unsubscribeFromItem ( )
inlineprotectedvirtualinherited

◆ updateDragAndDropSettings()

void ParameterTuningWidget::updateDragAndDropSettings ( )
private

Disable drag-and-drop abilities, if job is in fit running state.

Definition at line 189 of file ParameterTuningWidget.cpp.

190 {
191  ASSERT(jobItem());
192  if (jobItem()->getStatus() == JobStatus::Fitting) {
194  m_treeView->setDragDropMode(QAbstractItemView::NoDragDrop);
195  } else {
197  if (jobItem()->isValidForFitting())
198  m_treeView->setDragDropMode(QAbstractItemView::DragOnly);
199  }
200 }
@ Fitting
the job is busy fitting
void setTuningDelegateEnabled(bool enabled)
Sets delegate to enabled/disabled state. In 'disabled' state the delegate is in ReadOnlyMode,...

References Fitting, jobItem(), m_treeView, and setTuningDelegateEnabled().

Referenced by subscribeToItem(), and updateJobStatus().

Here is the call graph for this function:

◆ updateJobStatus()

void ParameterTuningWidget::updateJobStatus ( )
private

Definition at line 226 of file ParameterTuningWidget.cpp.

227 {
228  m_cautionSign->clear();
229 
230  if (jobItem()->isFailed()) {
231  QString message;
232  message.append("Current parameter values cause simulation failure.\n\n");
233  message.append(jobItem()->getComments());
235  }
236 
238 }
void clear()
Clears caution message;.
Definition: CautionSign.cpp:42
void setCautionMessage(const QString &cautionMessage)
Shows caution sign on the screen. If clear of previous caution sign had happened just few msec ago,...
Definition: CautionSign.cpp:60

References CautionSign::clear(), jobItem(), m_cautionSign, CautionSign::setCautionMessage(), and updateDragAndDropSettings().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ updateParameterModel

void ParameterTuningWidget::updateParameterModel ( )
privateslot

Definition at line 117 of file ParameterTuningWidget.cpp.

118 {
119  ASSERT(m_jobModel);
120 
121  if (!jobItem())
122  return;
123 
124  if (!jobItem()->sampleItem() || !jobItem()->instrumentItem())
125  throw Error("ModelTuningWidget::updateParameterModel() -> Error."
126  "JobItem doesn't have sample or instrument model.");
127 
128  delete m_parameterTuningModel;
130  new ParameterTuningModel(jobItem()->parameterContainerItem()->parameterTreeRoot(), this);
131 
133  if (m_treeView->columnWidth(0) < 170)
134  m_treeView->setColumnWidth(0, 170);
135  m_treeView->expandAll();
136 }
The ParameterTuningModel class represents parameters which can be tuned in real time in ParameterTuni...

References Error, jobItem(), m_jobModel, m_parameterTuningModel, and m_treeView.

Referenced by subscribeToItem().

Here is the call graph for this function:

Member Data Documentation

◆ m_cautionSign

CautionSign* ParameterTuningWidget::m_cautionSign
private

Definition at line 74 of file ParameterTuningWidget.h.

Referenced by updateJobStatus().

◆ m_delegate

ParameterTuningDelegate* ParameterTuningWidget::m_delegate
private

◆ m_itemController

◆ m_jobModel

JobModel* ParameterTuningWidget::m_jobModel
private

◆ m_parameterTuningModel

ParameterTuningModel* ParameterTuningWidget::m_parameterTuningModel
private

◆ m_sliderSettingsWidget

SliderSettingsWidget* ParameterTuningWidget::m_sliderSettingsWidget
private

Definition at line 71 of file ParameterTuningWidget.h.

Referenced by ParameterTuningWidget().

◆ m_treeView

QTreeView* ParameterTuningWidget::m_treeView
private

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