BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DistributionSelector Class Reference

Description

Widget for selecting a distribution (combo box) and input of the corresponding values with respect to the given distribution (e.g. mean and deviation for gauss distribution)

Definition at line 46 of file DistributionEditor.h.

Inheritance diagram for DistributionSelector:
[legend]
Collaboration diagram for DistributionSelector:
[legend]

Signals

void distributionChanged ()
 

Public Member Functions

 DistributionSelector (std::optional< MeanConfig > mean_config, GUI::ID::Distributions distributions, QWidget *parent, BeamDistributionItem *item)
 
GUI::ID::Distributions distributions () const
 
BeamDistributionItemitem () const
 
void refresh ()
 

Private Member Functions

void createDistributionWidgets ()
 
void createMeanSpinBox (const DoubleDescriptor &d)
 
DoubleSpinBoxcreateSpinBox (const DoubleDescriptor &d)
 
QSpinBox * createSpinBox (const UIntDescriptor &d)
 

Private Attributes

QComboBox * m_distributionCombo
 
GUI::ID::Distributions m_distributions
 
QFormLayout * m_formLayout
 
BeamDistributionItemm_item
 
std::optional< MeanConfigm_meanConfig
 

Constructor & Destructor Documentation

◆ DistributionSelector()

DistributionSelector::DistributionSelector ( std::optional< MeanConfig mean_config,
GUI::ID::Distributions  distributions,
QWidget *  parent,
BeamDistributionItem item 
)
Parameters
mean_configcontrols how the mean value is shown and can be input. If this parameter is nullopt then the mean value can not be input and only symmetric distributions are provided
Precondition
! mean_config && distributions == Distributions::Symmetric (i.e. the combination of all distributions without mean input is currently not supported)

Definition at line 35 of file DistributionEditor.cpp.

38  : QWidget(parent)
39  , m_item(item)
40  , m_meanConfig(std::move(mean_config))
42 {
43  ASSERT(item);
44  m_formLayout = new QFormLayout(this);
45  m_formLayout->setMargin(0);
46 
49  createDistributionWidgets();
50  emit distributionChanged();
51  });
52  m_formLayout->addRow("Distribution:", m_distributionCombo);
53 
55 }
SelectionDescriptor< DistributionItem * > distributionSelection() const
BeamDistributionItem * m_item
GUI::ID::Distributions m_distributions
QComboBox * m_distributionCombo
GUI::ID::Distributions distributions() const
BeamDistributionItem * item() const
QFormLayout * m_formLayout
std::optional< MeanConfig > m_meanConfig
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

References createDistributionWidgets(), GUI::Util::createSelectionCombo(), BeamDistributionItem::distributionSelection(), item(), m_distributionCombo, and m_formLayout.

Here is the call graph for this function:

Member Function Documentation

◆ createDistributionWidgets()

void DistributionSelector::createDistributionWidgets ( )
private

Definition at line 57 of file DistributionEditor.cpp.

58 {
59  while (m_formLayout->rowCount() > 1)
60  m_formLayout->removeRow(1);
61 
62  if (auto* cosine = dynamic_cast<DistributionCosineItem*>(m_item->distribution())) {
63  createMeanSpinBox(cosine->mean());
64  createSpinBox(cosine->sigma());
65  createSpinBox(cosine->numberOfSamples());
66  createSpinBox(cosine->sigmaFactor());
67  } else if (auto* gate = dynamic_cast<DistributionGateItem*>(m_item->distribution())) {
68  auto* minSpinbox = createSpinBox(gate->minimum());
69  auto* maxSpinbox = createSpinBox(gate->maximum());
70  connect(minSpinbox, &DoubleSpinBox::baseValueChanged, [=](double d) {
71  if (d > gate->maximum()) {
72  gate->setMaximum(d);
73  maxSpinbox->updateValue();
74  }
75  });
76  connect(maxSpinbox, &DoubleSpinBox::baseValueChanged, [=](double d) {
77  if (d < gate->minimum()) {
78  gate->setMinimum(d);
79  minSpinbox->updateValue();
80  }
81  });
82  createSpinBox(gate->numberOfSamples());
83  } else if (auto* gauss = dynamic_cast<DistributionGaussianItem*>(m_item->distribution())) {
84  createMeanSpinBox(gauss->mean());
85  createSpinBox(gauss->standardDeviation());
86  createSpinBox(gauss->numberOfSamples());
87  createSpinBox(gauss->sigmaFactor());
88  } else if (auto* logNormal = dynamic_cast<DistributionLogNormalItem*>(m_item->distribution())) {
89  createSpinBox(logNormal->median());
90  createSpinBox(logNormal->scaleParameter());
91  createSpinBox(logNormal->numberOfSamples());
92  createSpinBox(logNormal->sigmaFactor());
93  } else if (auto* lorentz = dynamic_cast<DistributionLorentzItem*>(m_item->distribution())) {
94  createMeanSpinBox(lorentz->mean());
95  createSpinBox(lorentz->hwhm());
96  createSpinBox(lorentz->numberOfSamples());
97  createSpinBox(lorentz->sigmaFactor());
98  } else if (auto* none = dynamic_cast<DistributionNoneItem*>(m_item->distribution())) {
99  createMeanSpinBox(none->mean());
100  } else if (auto* trapezoid = dynamic_cast<DistributionTrapezoidItem*>(m_item->distribution())) {
101  createSpinBox(trapezoid->center());
102  createSpinBox(trapezoid->leftWidth());
103  createSpinBox(trapezoid->middleWidth());
104  createSpinBox(trapezoid->rightWidth());
105  createSpinBox(trapezoid->numberOfSamples());
106  }
107 }
DistributionItem * distribution() const
DoubleSpinBox * createSpinBox(const DoubleDescriptor &d)
void createMeanSpinBox(const DoubleDescriptor &d)
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.

References DoubleSpinBox::baseValueChanged(), createMeanSpinBox(), createSpinBox(), BeamDistributionItem::distribution(), m_formLayout, and m_item.

Referenced by DistributionSelector(), and refresh().

Here is the call graph for this function:

◆ createMeanSpinBox()

void DistributionSelector::createMeanSpinBox ( const DoubleDescriptor d)
private

Definition at line 129 of file DistributionEditor.cpp.

130 {
131  if (m_meanConfig) {
132  if (m_meanConfig->scientific) {
134  connect(sb, &ScientificSpinBox::valueChanged, [=](double v) {
135  d.set(v);
136  emit distributionChanged();
137  });
138  } else
139  createSpinBox(d);
140  }
141 }
function< void(double)> set
function to set the value
void valueChanged(double value)
ScientificSpinBox * createScientificSpinBox(QFormLayout *parentLayout, const DoubleDescriptor &d, std::function< void(double)> slot=nullptr)
Create a label and a scientific spin box with the information found in a DoubleDescriptor and place t...
Definition: WidgetUtils.cpp:82

References GUI::Util::createScientificSpinBox(), createSpinBox(), distributionChanged(), m_formLayout, m_meanConfig, DoubleDescriptor::set, and ScientificSpinBox::valueChanged().

Referenced by createDistributionWidgets().

Here is the call graph for this function:

◆ createSpinBox() [1/2]

DoubleSpinBox * DistributionSelector::createSpinBox ( const DoubleDescriptor d)
private

Definition at line 109 of file DistributionEditor.cpp.

110 {
111  auto* sb = GUI::Util::createSpinBox(m_formLayout, d);
112  connect(sb, &DoubleSpinBox::baseValueChanged, [=](double v) {
113  d.set(v);
114  emit distributionChanged();
115  });
116  return sb;
117 }
QSpinBox * createSpinBox(QWidget *parent, const UIntDescriptor &d, std::function< void(uint)> slot=nullptr)
Create a spin box with the information found in a UIntDescriptor.
Definition: WidgetUtils.cpp:24

References DoubleSpinBox::baseValueChanged(), GUI::Util::createSpinBox(), distributionChanged(), m_formLayout, and DoubleDescriptor::set.

Referenced by createDistributionWidgets(), and createMeanSpinBox().

Here is the call graph for this function:

◆ createSpinBox() [2/2]

QSpinBox * DistributionSelector::createSpinBox ( const UIntDescriptor d)
private

Definition at line 119 of file DistributionEditor.cpp.

120 {
121  auto* sb = GUI::Util::createSpinBox(m_formLayout, d);
122  connect(sb, QOverload<int>::of(&QSpinBox::valueChanged), [=](int v) {
123  d.set(v);
124  emit distributionChanged();
125  });
126  return sb;
127 }
function< void(uint)> set
function to set the value

References GUI::Util::createSpinBox(), distributionChanged(), m_formLayout, and UIntDescriptor::set.

Here is the call graph for this function:

◆ distributionChanged

void DistributionSelector::distributionChanged ( )
signal

◆ distributions()

GUI::ID::Distributions DistributionSelector::distributions ( ) const

Definition at line 148 of file DistributionEditor.cpp.

149 {
150  return m_distributions;
151 }

References m_distributions.

◆ item()

BeamDistributionItem * DistributionSelector::item ( ) const

Definition at line 143 of file DistributionEditor.cpp.

144 {
145  return m_item;
146 }

References m_item.

Referenced by DistributionSelector(), DistributionEditor::updatePlot(), and InclinationAnglesEditor::updatePlot().

◆ refresh()

void DistributionSelector::refresh ( )

Definition at line 153 of file DistributionEditor.cpp.

154 {
155  QSignalBlocker b(m_distributionCombo);
156  m_distributionCombo->setCurrentIndex(m_item->distributionSelection().currentIndex());
158 }

References createDistributionWidgets(), BeamDistributionItem::distributionSelection(), m_distributionCombo, and m_item.

Referenced by DistributionEditor::updateData().

Here is the call graph for this function:

Member Data Documentation

◆ m_distributionCombo

QComboBox* DistributionSelector::m_distributionCombo
private

Definition at line 78 of file DistributionEditor.h.

Referenced by DistributionSelector(), and refresh().

◆ m_distributions

GUI::ID::Distributions DistributionSelector::m_distributions
private

Definition at line 76 of file DistributionEditor.h.

Referenced by distributions().

◆ m_formLayout

QFormLayout* DistributionSelector::m_formLayout
private

◆ m_item

BeamDistributionItem* DistributionSelector::m_item
private

Definition at line 74 of file DistributionEditor.h.

Referenced by createDistributionWidgets(), item(), and refresh().

◆ m_meanConfig

std::optional<MeanConfig> DistributionSelector::m_meanConfig
private

Definition at line 75 of file DistributionEditor.h.

Referenced by createMeanSpinBox().


The documentation for this class was generated from the following files: