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

Description

The MinimizerSettingsWidget contains editor for all minimizer settings and related fit options. Part of FitSuiteWidget.

Definition at line 34 of file MinimizerSettingsWidget.h.

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

Public Slots

void setItem (JobItem *jobItem)
 
void setItem (MinimizerContainerItem *minimizerItem)
 

Public Member Functions

 MinimizerSettingsWidget (QWidget *parent=nullptr)
 

Private Member Functions

QWidget * createComboBox (SelectionDescriptor< QString > d)
 
QWidget * createDoubleSpinbox (DoubleDescriptor d)
 
void createMimimizerEdits ()
 
QWidget * createSpinbox (UIntDescriptor d)
 
void updateUIValues ()
 

Private Attributes

MinimizerContainerItemm_currentItem
 
QFormLayout * m_mainLayout
 
QFormLayout * m_minimizerLayout
 
QList< function< void()> > m_updaters
 

Constructor & Destructor Documentation

◆ MinimizerSettingsWidget()

MinimizerSettingsWidget::MinimizerSettingsWidget ( QWidget *  parent = nullptr)

Definition at line 27 of file MinimizerSettingsWidget.cpp.

28  : QWidget(parent)
29  , m_currentItem(nullptr)
30 {
31  setWindowTitle(QLatin1String("Minimizer Settings"));
32  setAttribute(Qt::WA_StyledBackground, true);
33  setProperty("stylable", true); // for stylesheet addressing
34 
35  m_mainLayout = new QFormLayout(this);
36  m_mainLayout->setContentsMargins(8, 8, 8, 8);
37  m_mainLayout->setSpacing(5);
38 }
MinimizerContainerItem * m_currentItem

References m_mainLayout.

Member Function Documentation

◆ createComboBox()

QWidget * MinimizerSettingsWidget::createComboBox ( SelectionDescriptor< QString >  d)
private

Definition at line 79 of file MinimizerSettingsWidget.cpp.

80 {
81  auto* combo = new QComboBox(this);
82  combo->addItems(d.options);
83  combo->setMaxCount(d.options.size());
84  combo->setToolTip(d.tooltip);
85 
86  connect(combo, qOverload<int>(&QComboBox::currentIndexChanged),
87  [=](int newIndex) { d.setCurrentIndex(newIndex); });
88 
89  m_updaters << [=]() {
90  QSignalBlocker b(combo);
91  combo->setCurrentIndex(d.currentIndex());
92  };
93 
94  return combo;
95 }
QList< function< void()> > m_updaters
int currentIndex() const override
Get currently selected option.
QStringList options
List of options, usually presented as combo entries.
void setCurrentIndex(int newIndex) const override
Set currently selected option.
QString tooltip
Tooltip text.

References SelectionDescriptor< T >::currentIndex(), m_updaters, SelectionDescriptor< T >::options, SelectionDescriptor< T >::setCurrentIndex(), and SelectionDescriptor< T >::tooltip.

Referenced by createMimimizerEdits(), and setItem().

Here is the call graph for this function:

◆ createDoubleSpinbox()

QWidget * MinimizerSettingsWidget::createDoubleSpinbox ( DoubleDescriptor  d)
private

Definition at line 97 of file MinimizerSettingsWidget.cpp.

98 {
99  auto* spinBox = new DoubleSpinBox(this, d);
100  spinBox->setToolTip(d.tooltip);
101  QObject::connect(spinBox, &DoubleSpinBox::baseValueChanged,
102  [=](double newValue) { d.set(newValue); });
103 
104  m_updaters << [=]() { spinBox->updateValue(); };
105 
106  return spinBox;
107 }
function< void(double)> set
function to set the value
QString tooltip
Tooltip text.
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.

References DoubleSpinBox::baseValueChanged(), m_updaters, DoubleDescriptor::set, and DoubleDescriptor::tooltip.

Referenced by createMimimizerEdits().

◆ createMimimizerEdits()

void MinimizerSettingsWidget::createMimimizerEdits ( )
private

Definition at line 134 of file MinimizerSettingsWidget.cpp.

135 {
137 
138  for (auto v : m_currentItem->minimizers().currentItem()->valueDescriptorsForUI()) {
139  if (std::holds_alternative<DoubleDescriptor>(v)) {
140  auto d = std::get<DoubleDescriptor>(v);
141  m_minimizerLayout->addRow(d.label + ":", createDoubleSpinbox(d));
142  } else if (std::holds_alternative<SelectionDescriptor<QString>>(v)) {
143  auto d = std::get<SelectionDescriptor<QString>>(v);
144  m_minimizerLayout->addRow(d.label + ":", createComboBox(d));
145  } else if (std::holds_alternative<UIntDescriptor>(v)) {
146  auto d = std::get<UIntDescriptor>(v);
147  m_minimizerLayout->addRow(d.label + ":", createSpinbox(d));
148  }
149  }
150 }
SelectionDescriptor< MinimizerItem * > minimizers() const
QWidget * createSpinbox(UIntDescriptor d)
QWidget * createDoubleSpinbox(DoubleDescriptor d)
QWidget * createComboBox(SelectionDescriptor< QString > d)
Describes a selection (various possibilities and the current one).
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68

References GUI::Util::Layout::clearLayout(), createComboBox(), createDoubleSpinbox(), createSpinbox(), m_currentItem, m_minimizerLayout, and MinimizerContainerItem::minimizers().

Referenced by setItem().

Here is the call graph for this function:

◆ createSpinbox()

QWidget * MinimizerSettingsWidget::createSpinbox ( UIntDescriptor  d)
private

Definition at line 109 of file MinimizerSettingsWidget.cpp.

110 {
111  auto* spinBox = new QSpinBox(this);
112  spinBox->setToolTip(d.tooltip);
113  spinBox->setMaximum(std::numeric_limits<int>::max());
114  spinBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
115 
116  if (d.limits.hasLowerLimit())
117  spinBox->setMinimum(static_cast<int>(d.limits.lowerLimit()));
118  if (d.limits.hasUpperLimit())
119  spinBox->setMaximum(static_cast<int>(d.limits.upperLimit()));
120 
121  spinBox->setValue(d.get());
122 
123  QObject::connect(spinBox, QOverload<int>::of(&QSpinBox::valueChanged),
124  [=](int newValue) { d.set(newValue); });
125 
126  m_updaters << [=]() {
127  QSignalBlocker b(spinBox);
128  spinBox->setValue(d.get());
129  };
130 
131  return spinBox;
132 }
function< void(uint)> set
function to set the value
QString tooltip
Tooltip text.
RealLimits limits
Limits of the value.
function< uint()> get
function to get the current value

References UIntDescriptor::get, UIntDescriptor::limits, m_updaters, UIntDescriptor::set, and UIntDescriptor::tooltip.

Referenced by createMimimizerEdits().

◆ setItem [1/2]

void MinimizerSettingsWidget::setItem ( JobItem jobItem)
slot

Definition at line 40 of file MinimizerSettingsWidget.cpp.

41 {
42  ASSERT(jobItem);
44 }
MinimizerContainerItem * minimizerContainerItem()
FitSuiteItem * fitSuiteItem()
Definition: JobItem.cpp:257
void setItem(JobItem *jobItem)

References JobItem::fitSuiteItem(), and FitSuiteItem::minimizerContainerItem().

Referenced by FitSessionWidget::setItem().

Here is the call graph for this function:

◆ setItem [2/2]

void MinimizerSettingsWidget::setItem ( MinimizerContainerItem minimizerItem)
slot

Definition at line 46 of file MinimizerSettingsWidget.cpp.

47 {
48  ASSERT(minimizerItem);
49 
51  m_updaters.clear();
52  m_currentItem = minimizerItem;
53 
54  if (!m_currentItem)
55  return;
56 
57  auto minimizerDescriptor = m_currentItem->minimizers();
58  auto* minimizerCombo = GUI::Util::createSelectionCombo(this, minimizerDescriptor,
59  [=](int) { createMimimizerEdits(); });
60 
61  m_updaters << [=]() {
62  QSignalBlocker b(minimizerCombo);
63  minimizerCombo->setCurrentIndex(minimizerDescriptor.currentIndex());
64  };
65  m_mainLayout->addRow("Minimizer:", minimizerCombo);
66 
67  auto* w = new QWidget(this);
68  m_minimizerLayout = new QFormLayout(w);
69  m_minimizerLayout->setContentsMargins(10, 8, 0, 8);
70  m_mainLayout->addRow("", w);
71 
72  m_mainLayout->addRow("Objective metric:", createComboBox(m_currentItem->objectiveMetric()));
73  m_mainLayout->addRow("Norm function:", createComboBox(m_currentItem->normFunction()));
74 
77 }
SelectionDescriptor< QString > objectiveMetric() const
SelectionDescriptor< QString > normFunction() const
QComboBox * createSelectionCombo(QWidget *parent, const SelectionDescriptor< T > d, std::function< void(int)> slot=nullptr)
Create a combo box with the information found in a selection descriptor.
Definition: WidgetUtils.h:45

References GUI::Util::Layout::clearLayout(), createComboBox(), createMimimizerEdits(), GUI::Util::createSelectionCombo(), m_currentItem, m_mainLayout, m_minimizerLayout, m_updaters, MinimizerContainerItem::minimizers(), MinimizerContainerItem::normFunction(), MinimizerContainerItem::objectiveMetric(), and updateUIValues().

Here is the call graph for this function:

◆ updateUIValues()

void MinimizerSettingsWidget::updateUIValues ( )
private

Definition at line 152 of file MinimizerSettingsWidget.cpp.

153 {
154  for (const auto& updater : m_updaters)
155  updater();
156 }

References m_updaters.

Referenced by setItem().

Member Data Documentation

◆ m_currentItem

MinimizerContainerItem* MinimizerSettingsWidget::m_currentItem
private

Definition at line 54 of file MinimizerSettingsWidget.h.

Referenced by createMimimizerEdits(), and setItem().

◆ m_mainLayout

QFormLayout* MinimizerSettingsWidget::m_mainLayout
private

Definition at line 55 of file MinimizerSettingsWidget.h.

Referenced by MinimizerSettingsWidget(), and setItem().

◆ m_minimizerLayout

QFormLayout* MinimizerSettingsWidget::m_minimizerLayout
private

Definition at line 56 of file MinimizerSettingsWidget.h.

Referenced by createMimimizerEdits(), and setItem().

◆ m_updaters

QList<function<void()> > MinimizerSettingsWidget::m_updaters
private

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