BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GISASBeamEditor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Instrument/GISASBeamEditor.cpp
6 //! @brief Implements class GISASBeamEditor
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 
23 #include <QDoubleValidator>
24 #include <QFormLayout>
25 #include <QGridLayout>
26 #include <QLineEdit>
27 
29  : QGroupBox("Beam parameters", parent)
30 {
31  ASSERT(item);
32  auto* vLayout = new QVBoxLayout(this);
33  vLayout->setContentsMargins(30, 8, 0, 0);
34  auto* form = new QFormLayout();
35  form->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
36  vLayout->addLayout(form);
37  auto* intensityEditor = new QLineEdit(this);
38  intensityEditor->setToolTip("Beam intensity in neutrons (or gammas per second.");
39  auto* validator = new FixupDoubleValidator(intensityEditor);
40  validator->setNotation(QDoubleValidator::ScientificNotation);
41  validator->setRange(0.0, 1e+32, 1000);
42  intensityEditor->setValidator(validator);
43 
44  form->addRow("Intensity:", intensityEditor);
45 
46  auto* wavelengthEditor = new DistributionEditor(
47  "Wavelength", MeanConfig{true}, GUI::ID::Distributions::All, this, item->wavelengthItem());
48  vLayout->addWidget(wavelengthEditor);
49 
50  auto* inclinationEditor =
51  new DistributionEditor("Inclination angle", MeanConfig{false}, GUI::ID::Distributions::All,
52  this, item->inclinationAngleItem());
53  vLayout->addWidget(inclinationEditor);
54 
55  auto* azimuthalEditor =
56  new DistributionEditor("Azimuthal angle", MeanConfig{false}, GUI::ID::Distributions::All,
57  this, item->azimuthalAngleItem());
58  vLayout->addWidget(azimuthalEditor);
59 
60  intensityEditor->setText(QString::number(item->intensity()));
61 
63 
64  connect(wavelengthEditor, &DistributionEditor::distributionChanged, this,
66  connect(inclinationEditor, &DistributionEditor::distributionChanged, 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->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->intensity(), 'g'));
85  });
86 }
Defines class BeamAngleItems.
Defines BeamItem hierarchy.
Defines class BeamWavelengthItem.
A widget for selecting a distribution and setting its parameters.
Defines class DoubleDescriptor.
Defines class FixupDoubleValidator.
Defines class GISASBeamEditor.
Defines class GroupBoxCollapser.
virtual BeamDistributionItem * inclinationAngleItem() const
Definition: BeamItems.cpp:77
BeamAzimuthalAngleItem * azimuthalAngleItem() const
Definition: BeamItems.cpp:92
BeamWavelengthItem * wavelengthItem() const
Definition: BeamItems.cpp:67
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
GISASBeamEditor(QWidget *parent, BeamItem *item)
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
configuration to control how the user can enter a mean value