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

Description

The RunFitControlWidget contains elements to start/stop fitting and to provide minimal diagnostic. Part of FitSuiteWidget.

Definition at line 31 of file RunFitControlWidget.h.

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

Public Slots

void onFittingError (const QString &what)
 

Signals

void startFittingPushed ()
 
void stopFittingPushed ()
 

Public Member Functions

 RunFitControlWidget (QWidget *parent=nullptr)
 
 ~RunFitControlWidget () override
 
virtual QList< QAction * > actionList ()
 
SessionItemcurrentItem ()
 
const SessionItemcurrentItem () const
 
virtual void setItem (SessionItem *item)
 

Protected Member Functions

void hideEvent (QHideEvent *) override
 
void showEvent (QShowEvent *) override
 
void subscribeToItem () override
 
void unsubscribeFromItem () override
 

Private Slots

void onFitSuitePropertyChange (const QString &name)
 
void onSliderValueChanged (int value)
 

Private Member Functions

FitSuiteItemfitSuiteItem ()
 
bool isValidJobItem ()
 
JobItemjobItem ()
 
int sliderUpdateInterval ()
 
int sliderValueToUpdateInterval (int value)
 converts slider value (1-15) to update interval to be propagated to FitSuiteWidget More...
 
void unsubscribeFromChildren ()
 
void updateControlElements ()
 Updates button "enabled" status and caution status depending on current job conditions. More...
 
void updateIterationsCountLabel ()
 

Private Attributes

CautionSignm_cautionSign
 
QSlider * m_intervalSlider
 
SessionItemControllerm_itemController
 
QLabel * m_iterationsCountLabel
 
QPushButton * m_startButton
 
QPushButton * m_stopButton
 
QLabel * m_updateIntervalLabel
 

Constructor & Destructor Documentation

◆ RunFitControlWidget()

RunFitControlWidget::RunFitControlWidget ( QWidget *  parent = nullptr)

Definition at line 36 of file RunFitControlWidget.cpp.

37  : SessionItemWidget(parent)
38  , m_startButton(new QPushButton)
39  , m_stopButton(new QPushButton)
40  , m_intervalSlider(new QSlider)
41  , m_updateIntervalLabel(new QLabel)
42  , m_iterationsCountLabel(new QLabel)
43  , m_cautionSign(new CautionSign(this))
44 {
45  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
47 
48  m_startButton->setText("Run");
49  m_startButton->setToolTip("Run fitting");
50  m_startButton->setMaximumWidth(80);
51 
52  m_stopButton->setText("Stop");
53  m_stopButton->setToolTip("Interrupt fitting");
54  m_stopButton->setMaximumWidth(80);
55 
56  m_intervalSlider->setToolTip(slider_tooltip);
57  m_intervalSlider->setOrientation(Qt::Horizontal);
58  m_intervalSlider->setRange(0, static_cast<int>(slider_to_interval.size()) - 1);
59  m_intervalSlider->setMaximumWidth(120);
60  m_intervalSlider->setMinimumWidth(120);
61  m_intervalSlider->setFocusPolicy(Qt::NoFocus);
62  m_intervalSlider->setValue(5);
63 
64  QFont font("Monospace", DesignerHelper::getLabelFontSize(), QFont::Normal);
65  font.setPointSize(DesignerHelper::getPortFontSize());
66  m_updateIntervalLabel->setToolTip(slider_tooltip);
67  m_updateIntervalLabel->setFont(font);
68  m_updateIntervalLabel->setText(QString::number(sliderUpdateInterval()));
69 
70  auto* layout = new QHBoxLayout;
71  layout->setSpacing(0);
72  layout->addWidget(m_startButton);
73  layout->addSpacing(5);
74  layout->addWidget(m_stopButton);
75  layout->addSpacing(5);
76  layout->addWidget(m_intervalSlider);
77  layout->addSpacing(2);
78  layout->addWidget(m_updateIntervalLabel);
79  layout->addSpacing(5);
80  layout->addStretch();
81  layout->addWidget(m_iterationsCountLabel);
82  setLayout(layout);
83 
84  connect(m_startButton, &QPushButton::clicked, [&]() { startFittingPushed(); });
85  connect(m_stopButton, &QPushButton::clicked, this, [&]() { stopFittingPushed(); });
86  connect(m_intervalSlider, &QSlider::valueChanged, this,
88 
89  setEnabled(false);
90 }
The CautionSign controls appearance of CautionSignWidget on top of parent widget.
Definition: CautionSign.h:25
static int getLabelFontSize()
static int getPortFontSize()
CautionSign * m_cautionSign
QPushButton * m_stopButton
QPushButton * m_startButton
void onSliderValueChanged(int value)
SessionItemWidget(QWidget *parent=nullptr)
const unsigned int RUN_FIT_CONTROL_WIDGET_HEIGHT

References DesignerHelper::getLabelFontSize(), DesignerHelper::getPortFontSize(), m_intervalSlider, m_iterationsCountLabel, m_startButton, m_stopButton, m_updateIntervalLabel, onSliderValueChanged(), GUI::Constants::RUN_FIT_CONTROL_WIDGET_HEIGHT, sliderUpdateInterval(), startFittingPushed(), and stopFittingPushed().

Here is the call graph for this function:

◆ ~RunFitControlWidget()

RunFitControlWidget::~RunFitControlWidget ( )
override

Definition at line 92 of file RunFitControlWidget.cpp.

93 {
95 }

References unsubscribeFromChildren().

Here is the call graph for this function:

Member Function Documentation

◆ actionList()

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

◆ 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:

◆ fitSuiteItem()

FitSuiteItem * RunFitControlWidget::fitSuiteItem ( )
private

Definition at line 173 of file RunFitControlWidget.cpp.

174 {
175  return jobItem() ? jobItem()->fitSuiteItem() : nullptr;
176 }
FitSuiteItem * fitSuiteItem()
Definition: JobItem.cpp:257

References JobItem::fitSuiteItem(), and jobItem().

Referenced by onSliderValueChanged(), subscribeToItem(), unsubscribeFromChildren(), and updateIterationsCountLabel().

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:

◆ isValidJobItem()

bool RunFitControlWidget::isValidJobItem ( )
private

Definition at line 178 of file RunFitControlWidget.cpp.

179 {
180  return jobItem() ? jobItem()->isValidForFitting() : false;
181 }
bool isValidForFitting()
Definition: JobItem.cpp:154

References JobItem::isValidForFitting(), and jobItem().

Referenced by updateControlElements().

Here is the call graph for this function:

◆ jobItem()

JobItem * RunFitControlWidget::jobItem ( )
private

Definition at line 168 of file RunFitControlWidget.cpp.

169 {
170  return dynamic_cast<JobItem*>(currentItem());
171 }

References SessionItemWidget::currentItem().

Referenced by fitSuiteItem(), isValidJobItem(), subscribeToItem(), and updateControlElements().

Here is the call graph for this function:

◆ onFitSuitePropertyChange

void RunFitControlWidget::onFitSuitePropertyChange ( const QString &  name)
privateslot

Definition at line 112 of file RunFitControlWidget.cpp.

113 {
116 }
static bool isIterationCountPropertyName(const QString &name)
QString const & name(EShape k)
Definition: particles.cpp:20

References FitSuiteItem::isIterationCountPropertyName(), GUI::RealSpace::Particles::name(), and updateIterationsCountLabel().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ onFittingError

void RunFitControlWidget::onFittingError ( const QString &  what)
slot

Definition at line 97 of file RunFitControlWidget.cpp.

98 {
100  m_iterationsCountLabel->setText("");
102 }
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(), m_cautionSign, m_iterationsCountLabel, and CautionSign::setCautionMessage().

Referenced by FitSessionWidget::onFittingError().

Here is the call graph for this function:

◆ onSliderValueChanged

void RunFitControlWidget::onSliderValueChanged ( int  value)
privateslot

Definition at line 104 of file RunFitControlWidget.cpp.

105 {
106  int interval = sliderValueToUpdateInterval(value);
107  m_updateIntervalLabel->setText(QString::number(interval));
108  if (fitSuiteItem())
109  fitSuiteItem()->setUpdateInterval(interval);
110 }
void setUpdateInterval(int interval)
FitSuiteItem * fitSuiteItem()
int sliderValueToUpdateInterval(int value)
converts slider value (1-15) to update interval to be propagated to FitSuiteWidget

References fitSuiteItem(), m_updateIntervalLabel, FitSuiteItem::setUpdateInterval(), and sliderValueToUpdateInterval().

Referenced by RunFitControlWidget().

Here is the call graph for this function:

◆ setItem()

◆ 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:

◆ sliderUpdateInterval()

int RunFitControlWidget::sliderUpdateInterval ( )
private

Definition at line 139 of file RunFitControlWidget.cpp.

140 {
142 }

References m_intervalSlider, and sliderValueToUpdateInterval().

Referenced by RunFitControlWidget(), and subscribeToItem().

Here is the call graph for this function:

◆ sliderValueToUpdateInterval()

int RunFitControlWidget::sliderValueToUpdateInterval ( int  value)
private

converts slider value (1-15) to update interval to be propagated to FitSuiteWidget

Definition at line 146 of file RunFitControlWidget.cpp.

147 {
148  auto svalue = static_cast<size_t>(value);
149  return svalue < slider_to_interval.size() ? slider_to_interval[svalue] : default_interval;
150 }

Referenced by onSliderValueChanged(), and sliderUpdateInterval().

◆ startFittingPushed

void RunFitControlWidget::startFittingPushed ( )
signal

◆ stopFittingPushed

void RunFitControlWidget::stopFittingPushed ( )
signal

◆ subscribeToItem()

void RunFitControlWidget::subscribeToItem ( )
overrideprotectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 118 of file RunFitControlWidget.cpp.

119 {
121 
123 
125  [this](const QString& name) { onFitSuitePropertyChange(name); }, this);
126 
128 
129  connect(jobItem(), &JobItem::jobStatusChanged, this,
130  [=](const JobStatus) { updateControlElements(); });
131 }
JobStatus
The JobStatus enum lists the possible states of a job.
Definition: JobStatus.h:22
void jobStatusChanged(const JobStatus status)
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:39
void updateControlElements()
Updates button "enabled" status and caution status depending on current job conditions.
void onFitSuitePropertyChange(const QString &name)
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.

References fitSuiteItem(), jobItem(), JobItem::jobStatusChanged(), SessionItem::mapper(), GUI::RealSpace::Particles::name(), onFitSuitePropertyChange(), ModelMapper::setOnPropertyChange(), FitSuiteItem::setUpdateInterval(), sliderUpdateInterval(), updateControlElements(), and updateIterationsCountLabel().

Here is the call graph for this function:

◆ unsubscribeFromChildren()

void RunFitControlWidget::unsubscribeFromChildren ( )
private

Definition at line 183 of file RunFitControlWidget.cpp.

184 {
185  if (fitSuiteItem())
186  fitSuiteItem()->mapper()->unsubscribe(this);
187 }
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78

References fitSuiteItem(), SessionItem::mapper(), and ModelMapper::unsubscribe().

Referenced by ~RunFitControlWidget(), and unsubscribeFromItem().

Here is the call graph for this function:

◆ unsubscribeFromItem()

void RunFitControlWidget::unsubscribeFromItem ( )
overrideprotectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 133 of file RunFitControlWidget.cpp.

134 {
135  setEnabled(false);
137 }

References unsubscribeFromChildren().

Here is the call graph for this function:

◆ updateControlElements()

void RunFitControlWidget::updateControlElements ( )
private

Updates button "enabled" status and caution status depending on current job conditions.

Definition at line 154 of file RunFitControlWidget.cpp.

155 {
156  setEnabled(isValidJobItem());
157 
158  if (jobItem()->getStatus() == JobStatus::Fitting) {
159  m_startButton->setEnabled(false);
160  m_stopButton->setEnabled(true);
161  m_cautionSign->clear();
162  } else {
163  m_startButton->setEnabled(true);
164  m_stopButton->setEnabled(false);
165  }
166 }
@ Fitting
the job is busy fitting

References CautionSign::clear(), Fitting, isValidJobItem(), jobItem(), m_cautionSign, m_startButton, and m_stopButton.

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ updateIterationsCountLabel()

void RunFitControlWidget::updateIterationsCountLabel ( )
private

Definition at line 189 of file RunFitControlWidget.cpp.

190 {
191  int niter = fitSuiteItem()->iterationCount();
192  m_iterationsCountLabel->setText(QString::number(niter));
193 }
int iterationCount() const

References fitSuiteItem(), FitSuiteItem::iterationCount(), and m_iterationsCountLabel.

Referenced by onFitSuitePropertyChange(), and subscribeToItem().

Here is the call graph for this function:

Member Data Documentation

◆ m_cautionSign

CautionSign* RunFitControlWidget::m_cautionSign
private

Definition at line 67 of file RunFitControlWidget.h.

Referenced by onFittingError(), and updateControlElements().

◆ m_intervalSlider

QSlider* RunFitControlWidget::m_intervalSlider
private

Definition at line 64 of file RunFitControlWidget.h.

Referenced by RunFitControlWidget(), and sliderUpdateInterval().

◆ m_itemController

◆ m_iterationsCountLabel

QLabel* RunFitControlWidget::m_iterationsCountLabel
private

◆ m_startButton

QPushButton* RunFitControlWidget::m_startButton
private

Definition at line 62 of file RunFitControlWidget.h.

Referenced by RunFitControlWidget(), and updateControlElements().

◆ m_stopButton

QPushButton* RunFitControlWidget::m_stopButton
private

Definition at line 63 of file RunFitControlWidget.h.

Referenced by RunFitControlWidget(), and updateControlElements().

◆ m_updateIntervalLabel

QLabel* RunFitControlWidget::m_updateIntervalLabel
private

Definition at line 65 of file RunFitControlWidget.h.

Referenced by RunFitControlWidget(), and onSliderValueChanged().


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