BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
InterferenceForm.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/SampleDesigner/InterferenceForm.cpp
6 //! @brief Implements class InterferenceForm
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 
26 
29  : QGroupBox(parent)
30  , m_layoutItem(layoutItem)
31  , m_ec(ec)
32 {
33  setTitle("Interference Function");
34 
35  FormLayouter layouter(this, ec);
36  layouter.setContentsMargins(6, 6, 0, 6);
38 
39  m_interferenceTypeCombo = new QComboBox(this);
41  auto d = layoutItem->interference();
42  m_interferenceTypeCombo->addItems(d.options);
43  m_interferenceTypeCombo->setCurrentIndex(d.currentIndex());
44  m_interferenceTypeCombo->setMaxVisibleItems(m_interferenceTypeCombo->count());
45  m_interferenceTypeCombo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
46  layouter.addRow("Type:", m_interferenceTypeCombo);
47 
49  updateTitle();
50 
51  connect(m_interferenceTypeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
52  [=](int newIndex) { m_ec->selectInterference(this, newIndex); });
53 }
54 
56 {
57  return m_layoutItem;
58 }
59 
61 {
62  FormLayouter layouter(this, m_ec);
63  while (layouter.layout()->rowCount() > 1)
64  layouter.layout()->removeRow(1);
65 
67  updateTitle();
68 }
69 
71 {
72  FormLayouter layouter(this, m_ec);
73  auto* interference = m_layoutItem->interference().currentItem();
74 
75  // Some values in interference settings affect the total density in the particle layout. To
76  // provide all the updating (data & UI), the method
77  // SampleEditorController::setDensityRelatedValueValue has to be called (instead of
78  // SampleEditorController::setDouble). For this we have the following lambda to add a value:
79  const auto addDensityRelatedValue = [&](DoubleDescriptor d) {
80  layouter.addValue(
81  d, [=](double newValue) { m_ec->setDensityRelatedValue(interference, newValue, d); });
82  };
83 
84  if (auto* itf = dynamic_cast<Interference1DLatticeItem*>(interference)) {
85  layouter.addValue(itf->positionVariance());
86  layouter.addValue(itf->length());
87  layouter.addValue(itf->rotationAngle());
88  layouter.addSelection(itf->decayFunction());
89  } else if (auto* itf = dynamic_cast<InterferenceRadialParaCrystalItem*>(interference)) {
90  layouter.addValue(itf->positionVariance());
91  layouter.addValue(itf->peakDistance());
92  layouter.addValue(itf->dampingLength());
93  layouter.addValue(itf->domainSize());
94  layouter.addValue(itf->kappa());
95  layouter.addSelection(itf->probabilityDistribution());
96  } else if (auto* itf = dynamic_cast<InterferenceHardDiskItem*>(interference)) {
97  layouter.addValue(itf->positionVariance());
98  layouter.addValue(itf->radius());
99  addDensityRelatedValue(itf->density());
100  } else if (auto* itf = dynamic_cast<Interference2DLatticeItem*>(interference)) {
101  layouter.addValue(itf->positionVariance());
102  auto* w = new LatticeTypeSelectionForm(this, itf, m_ec);
103  layouter.addRow(itf->latticeType().label, w);
104  layouter.addSelection(itf->decayFunction());
105  } else if (auto* itf = dynamic_cast<InterferenceFinite2DLatticeItem*>(interference)) {
106  layouter.addValue(itf->positionVariance());
107  layouter.addValue(itf->domainSize1());
108  layouter.addValue(itf->domainSize2());
109  auto* w = new LatticeTypeSelectionForm(this, itf, m_ec);
110  layouter.addRow(itf->latticeType().label, w);
111  } else if (auto* itf = dynamic_cast<Interference2DParaCrystalItem*>(interference)) {
112  layouter.addValue(itf->positionVariance());
113  layouter.addValue(itf->dampingLength());
114  layouter.addValue(itf->domainSize1());
115  layouter.addValue(itf->domainSize2());
116  auto* w = new LatticeTypeSelectionForm(this, itf, m_ec);
117  layouter.addRow(itf->latticeType().label, w);
118  layouter.addSelection(itf->probabilityDistribution1());
119  layouter.addSelection(itf->probabilityDistribution2());
120  }
121 }
122 
124 {
125  m_collapser->setTitle("Interference Function (" + m_interferenceTypeCombo->currentText() + ")");
126 }
Defines classes releted to event filtering.
Defines classes FormLayouter.
Defines class GroupBoxCollapser.
Defines class InterferenceForm.
Defines InterferenceItems's classes.
Defines classes Lattice2DItems.
Defines class LatticeTypeSelectionForm.
Defines class ParticleLayoutItem.
Defines class SampleEditorController.
Defines class SelectionContainerForm.
Defines class UIntDescriptor.
Describes properties of a double value which are necessary to allow GUI representation,...
Utility class to populate a QFormLayout.
Definition: FormLayouter.h:36
QFormLayout * layout()
The layout where this layouter is operating on.
int addRow(QWidget *w)
Convenience method to add a widget.
int addValue(const DoubleDescriptor &d)
Adds a row with a bold printed label and a DoubleSpinBox.
void setContentsMargins(int left, int top, int right, int bottom)
Convenience method to set the contents margins.
int addSelection(const SelectionDescriptor< T > &d)
Add a row with a selection.
Definition: FormLayouter.h:170
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
void setTitle(const QString &title)
Set the title of the group box. Do not use the method groupBox->setTitle() any more once the add-on i...
void onInterferenceTypeChanged()
ParticleLayoutItem * layoutItem() const
GroupBoxCollapser * m_collapser
InterferenceForm(QWidget *parent, ParticleLayoutItem *layoutItem, SampleEditorController *ec)
QComboBox * m_interferenceTypeCombo
ParticleLayoutItem * m_layoutItem
void createInterferenceWidgets()
SampleEditorController * m_ec
Form for editing lattice type values.
SelectionDescriptor< InterferenceItem * > interference() const
Class to modify a sample from the layer oriented sample editor.
void setDensityRelatedValue(InterferenceItem *interferenceItem, double newValue, DoubleDescriptor d)
Set an interference function's value which affects the total particle density of the containing parti...
void selectInterference(InterferenceForm *widget, int newIndex)
static void install(QObject *obj)