BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
OffspecBeamEditor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Instrument/OffspecBeamEditor.cpp
6 //! @brief Implements class OffspecBeamEditor
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
24 #include <QDoubleValidator>
25 #include <QFormLayout>
26 #include <QGridLayout>
27 #include <QLineEdit>
28 
30  : QGroupBox("Beam parameters", parent)
31 {
32  ASSERT(item);
33 
34  auto* vLayout = new QVBoxLayout(this);
35  vLayout->setContentsMargins(30, 8, 0, 0);
36  auto* form = new QFormLayout();
37  form->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
38  vLayout->addLayout(form);
39  auto* intensityEditor = new QLineEdit(this);
40  intensityEditor->setToolTip("Beam intensity in neutrons (or gammas per second.");
41  auto* validator = new FixupDoubleValidator(intensityEditor);
42  validator->setNotation(QDoubleValidator::ScientificNotation);
43  validator->setRange(0.0, 1e+32, 1000);
44  intensityEditor->setValidator(validator);
45  form->addRow("Intensity:", intensityEditor);
46 
47  auto* wavelengthEditor =
48  new DistributionEditor("Wavelength", MeanConfig{true}, GUI::ID::Distributions::All, this,
49  item->beamItem()->wavelengthItem());
50  vLayout->addWidget(wavelengthEditor);
51 
52  auto* inclinationEditor = new AxisPropertyEditor(this, "Inclination angle", &item->alphaAxis());
53  vLayout->addWidget(inclinationEditor);
54 
55  auto* azimuthalEditor =
56  new DistributionEditor("Azimuthal angle", MeanConfig{false}, GUI::ID::Distributions::All,
57  this, item->beamItem()->azimuthalAngleItem());
58  vLayout->addWidget(azimuthalEditor);
59 
60  intensityEditor->setText(QString::number(item->beamItem()->intensity()));
61 
63 
64  connect(wavelengthEditor, &DistributionEditor::distributionChanged, this,
66  connect(inclinationEditor, &AxisPropertyEditor::dataChanged, this,
68  connect(azimuthalEditor, &DistributionEditor::distributionChanged, this,
70 
71  // validate value while typing
72  connect(intensityEditor, &QLineEdit::textEdited, [=]() {
73  QString str = intensityEditor->text();
74  int pos;
75  if (intensityEditor->validator()->validate(str, pos) == QValidator::Acceptable) {
76  item->beamItem()->setIntensity(intensityEditor->text().toDouble());
77  emit dataChanged();
78  }
79  });
80  // if validator does not assert the input value, it says about that,
81  // and here we return to the last correct value
82  connect(validator, &FixupDoubleValidator::fixupSignal, [=]() {
83  auto* editor = qobject_cast<QLineEdit*>(validator->parent());
84  editor->setText(QString::number(item->beamItem()->intensity(), 'g'));
85  });
86 }
Defines class AxisPropertyEditor.
Defines class BeamAngleItems.
Defines class BeamWavelengthItem.
A widget for selecting a distribution and setting its parameters.
Defines class DoubleDescriptor.
Defines class FixupDoubleValidator.
Defines class GroupBoxCollapser.
Defines class InstrumentItem and all its children.
Defines class OffspecBeamEditor.
Use this to edit an AxisProperty.
DistributionSelector as above but contained in a GroupBox with a title and a button to open the distr...
void distributionChanged()
The FixupDoubleValidator class is a derivative of QDoubleValidator with non-empty "fixup" method....
void fixupSignal() const
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
virtual BeamItem * beamItem() const
OffspecBeamEditor(QWidget *parent, OffspecInstrumentItem *item)
configuration to control how the user can enter a mean value