BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
AxisPropertyEditor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Instrument/AxisPropertyEditor.cpp
6 //! @brief Implement class AxisPropertyEditor
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2022
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include <QFormLayout>
21 #include <QGroupBox>
22 #include <QSpinBox>
23 
24 AxisPropertyEditor::AxisPropertyEditor(QWidget* parent, const QString& groupTitle,
25  AxisProperty* axisProperty)
26  : QGroupBox(groupTitle, parent)
27  , m_axisProperty(axisProperty)
28 {
29  setProperty("subgroup", true); // for stylesheet addressing
30  auto* formLayout = new QFormLayout(this);
31  formLayout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
32 
33  m_nbinsSpinBox = GUI::Util::createSpinBox(formLayout, axisProperty->nbins());
34  m_minSpinBox = GUI::Util::createSpinBox(formLayout, axisProperty->min());
35  m_maxSpinBox = GUI::Util::createSpinBox(formLayout, axisProperty->max());
36 
38 
39  connect(m_nbinsSpinBox, qOverload<int>(&QSpinBox::valueChanged), [=](int v) {
40  if (axisProperty->nbins() != static_cast<uint>(v)) {
41  axisProperty->setNbins(v);
42  emit dataChanged();
43  }
44  });
45 
46  connect(m_minSpinBox, qOverload<double>(&DoubleSpinBox::baseValueChanged), [=](double v) {
47  if (m_axisProperty->min() != v) {
48  m_axisProperty->setMin(v);
49  emit dataChanged();
50  if (m_axisProperty->max() < v) {
51  m_axisProperty->setMax(v);
52  m_maxSpinBox->updateValue();
53  }
54  }
55  });
56 
57  connect(m_maxSpinBox, qOverload<double>(&DoubleSpinBox::baseValueChanged), [=](double v) {
58  if (m_axisProperty->max() != v) {
59  m_axisProperty->setMax(v);
60  emit dataChanged();
61  if (m_axisProperty->min() > v) {
62  m_axisProperty->setMin(v);
63  m_minSpinBox->updateValue();
64  }
65  }
66  });
67 }
68 
70 {
71  QSignalBlocker b(m_nbinsSpinBox);
72  m_nbinsSpinBox->setValue(m_axisProperty->nbins());
75 }
Defines class AxisPropertyEditor.
Defines class AxisProperty.
Defines class DoubleSpinBox.
Defines class GroupBoxCollapser.
Defines GUI::Util namespace.
AxisPropertyEditor(QWidget *parent, const QString &groupTitle, AxisProperty *axisProperty)
DoubleSpinBox * m_minSpinBox
void updateData()
Reload UI from data.
DoubleSpinBox * m_maxSpinBox
AxisProperty * m_axisProperty
Holds values which can be used to describe a FixedBinAxis.
Definition: AxisProperty.h:38
void updateValue()
Update the shown value to the one contained in the value descriptor.
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
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