BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
EnvironmentEditor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Instrument/EnvironmentEditor.cpp
6 //! @brief Implements class EnvironmentEditor
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
21 #include <QFormLayout>
22 
24  : QGroupBox("Environment", parent)
25  , m_instrument(instrument)
26 {
27  ASSERT(instrument);
28  m_formLayout = new QFormLayout(this);
29  m_formLayout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
30 
31  auto* backgroundTypeCombo =
32  GUI::Util::createSelectionCombo(this, instrument->backgroundSelection(), [=](int) {
33  createBackgroundWidgets();
34  emit dataChanged();
35  });
36  m_formLayout->addRow("Background type:", backgroundTypeCombo);
37 
40 }
41 
43 {
44  while (m_formLayout->rowCount() > 1)
45  m_formLayout->removeRow(1);
46 
47  auto* backgroundItem = m_instrument->backgroundSelection().currentItem();
48  if (auto* p = dynamic_cast<ConstantBackgroundItem*>(backgroundItem)) {
49  auto* spinbox = new DoubleSpinBox(this, p->backgroundValue());
50  spinbox->setSingleStep(0.01);
51  m_formLayout->addRow("Background value:", spinbox);
52 
53  connect(spinbox, &DoubleSpinBox::baseValueChanged, [=](double newValue) {
54  p->setBackgroundValue(newValue);
55  emit dataChanged();
56  });
57  }
58 }
Defines BackgroundItem classes.
Defines class DoubleSpinBox.
Defines class EnvironmentEditor.
Defines class GroupBoxCollapser.
Defines class InstrumentItem and all its children.
Defines GUI::Util namespace.
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
InstrumentItem * m_instrument
QFormLayout * m_formLayout
EnvironmentEditor(QWidget *parent, InstrumentItem *instrument)
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Abstract base class for instrument-specific item classes.
SelectionDescriptor< BackgroundItem * > backgroundSelection() 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