BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
PolarizationAnalysisEditor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Instrument/PolarizationAnalysisEditor.cpp
6 //! @brief Implements class PolarizationAnalysisEditor
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 
20 #include <QCheckBox>
21 #include <QFormLayout>
22 #include <QLabel>
23 
25  : QGroupBox("Polarization analysis", parent)
26  , m_instrument(instrument)
27 {
28  ASSERT(instrument);
29 
30  auto* layout = new QVBoxLayout(this);
31 
32  auto* checkbox = new QCheckBox(QString("Enable %1").arg(title()));
33  checkbox->setChecked(m_instrument->withPolarizerAnalyzer());
34  layout->addWidget(checkbox);
35 
36  auto* polarizerAnalyzerWidget = new QWidget(this);
37  auto* formlayout = new QFormLayout(polarizerAnalyzerWidget);
38  formlayout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
39 
40  addVector(formlayout, m_instrument->polarization());
41  addVector(formlayout, m_instrument->analyzerDirection());
42  formlayout->addRow(GUI::Util::labelWithUnit(m_instrument->analyzerEfficiency()) + ":",
43  createSpinBox(polarizerAnalyzerWidget, m_instrument->analyzerEfficiency()));
44  formlayout->addRow(
45  GUI::Util::labelWithUnit(m_instrument->analyzerTotalTransmission()) + ":",
46  createSpinBox(polarizerAnalyzerWidget, m_instrument->analyzerTotalTransmission()));
47 
48  layout->addWidget(polarizerAnalyzerWidget);
49  polarizerAnalyzerWidget->setVisible(m_instrument->withPolarizerAnalyzer());
50 
51  connect(checkbox, &QCheckBox::toggled, [=](bool b) {
52  polarizerAnalyzerWidget->setVisible(b);
54  emit dataChanged();
55  });
56 
58 }
59 
61 {
62  auto* sb = new DoubleSpinBox(parent, d);
63  connect(sb, &DoubleSpinBox::baseValueChanged, [=](double v) {
64  if (d.get() != v) {
65  d.set(v);
66  emit dataChanged();
67  }
68  });
69  return sb;
70 }
71 
72 void PolarizationAnalysisEditor::addVector(QFormLayout* parentLayout, const VectorDescriptor& d)
73 {
74  auto* layout = new QHBoxLayout;
75 
76  const auto add = [&](const DoubleDescriptor& d) {
77  layout->addWidget(new QLabel(GUI::Util::labelWithUnit(d) + ":"));
78  layout->addWidget(createSpinBox(parentLayout->parentWidget(), d));
79  };
80 
81  add(d.x);
82  add(d.y);
83  add(d.z);
84 
85  layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
86 
87  parentLayout->addRow(d.label + ":", layout);
88 }
Defines class DoubleSpinBox.
Defines class GroupBoxCollapser.
Defines class InstrumentItem and all its children.
Defines class PolarizationAnalysisEditor.
Defines GUI::Util namespace.
Describes properties of a double value which are necessary to allow GUI representation,...
function< double()> get
function to get the current value
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Abstract base class for instrument-specific item classes.
bool withPolarizerAnalyzer() const
void setWithPolarizerAnalyzer(bool with)
DoubleSpinBox * createSpinBox(QWidget *parent, const DoubleDescriptor &d)
void addVector(QFormLayout *parentLayout, const VectorDescriptor &d)
PolarizationAnalysisEditor(QWidget *parent, InstrumentItem *instrument)
Describes properties of a 3D vector, consisting of three double values.
DoubleDescriptor y
DoubleDescriptor x
QString label
A label text (short, no trailing colon)
DoubleDescriptor z
QString labelWithUnit(const QString &label, std::variant< QString, Unit > unit)
Create a label with an optional unit in brackets.