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

Description

Widget for selecting the alignment of a detector (combo box) and input of the corresponding values.

Definition at line 30 of file DetectorAlignmentEditor.h.

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

Signals

void dataChanged ()
 

Public Member Functions

 DetectorAlignmentEditor (QWidget *parent, RectangularDetectorItem *item)
 

Private Member Functions

void addVector (QFormLayout *parentLayout, const VectorDescriptor &d)
 
void createAligmentWidgets ()
 
DoubleSpinBoxcreateSpinBox (QFormLayout *parentFormLayout, const DoubleDescriptor &d)
 
DoubleSpinBoxcreateSpinBox (QWidget *parent, const DoubleDescriptor &d)
 

Private Attributes

QFormLayout * m_formLayout
 
RectangularDetectorItemm_item
 

Constructor & Destructor Documentation

◆ DetectorAlignmentEditor()

DetectorAlignmentEditor::DetectorAlignmentEditor ( QWidget *  parent,
RectangularDetectorItem item 
)

Definition at line 44 of file DetectorAlignmentEditor.cpp.

45  : QWidget(parent)
46  , m_item(item)
47 {
48  ASSERT(m_item);
49  m_formLayout = new QFormLayout(this);
50  m_formLayout->setContentsMargins(0, 15, 0, 0);
51  m_formLayout->setSpacing(8);
52 
53  auto* m_combo =
55  createAligmentWidgets();
56  emit dataChanged();
57  });
58  m_formLayout->addRow("Alignment:", m_combo);
59 
61 }
RectangularDetectorItem * m_item
SelectionDescriptor< RectangularDetector::EDetectorArrangement > detectorAlignmentSelection() const
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 createAligmentWidgets(), GUI::Util::createSelectionCombo(), RectangularDetectorItem::detectorAlignmentSelection(), m_formLayout, and m_item.

Here is the call graph for this function:

Member Function Documentation

◆ addVector()

void DetectorAlignmentEditor::addVector ( QFormLayout *  parentLayout,
const VectorDescriptor d 
)
private

Definition at line 88 of file DetectorAlignmentEditor.cpp.

89 {
90  auto* layout = new QHBoxLayout;
91 
92  const auto add = [&](const DoubleDescriptor& d) {
93  layout->addWidget(new QLabel(GUI::Util::labelWithUnit(d) + ":"));
94  layout->addWidget(createSpinBox(parentLayout->parentWidget(), d));
95  };
96 
97  add(d.x);
98  add(d.y);
99  add(d.z);
100 
101  layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
102 
103  parentLayout->addRow(d.label + ":", layout);
104 }
DoubleSpinBox * createSpinBox(QFormLayout *parentFormLayout, const DoubleDescriptor &d)
Describes properties of a double value which are necessary to allow GUI representation,...
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.

References createSpinBox(), VectorDescriptor::label, GUI::Util::labelWithUnit(), VectorDescriptor::x, VectorDescriptor::y, and VectorDescriptor::z.

Referenced by createAligmentWidgets().

Here is the call graph for this function:

◆ createAligmentWidgets()

void DetectorAlignmentEditor::createAligmentWidgets ( )
private

Definition at line 106 of file DetectorAlignmentEditor.cpp.

107 {
108  while (m_formLayout->rowCount() > 1)
109  m_formLayout->removeRow(1);
110 
111  const QString descr = alignmentDescription(m_item->detectorAlignment());
112  auto* layout = new QFormLayout;
113  layout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
114  layout->setContentsMargins(0, 0, 0, 0);
115  m_formLayout->addRow("", layout);
116 
117  if (m_item->detectorAlignment() == RectangularDetector::GENERIC) {
118  addVector(layout, m_item->normalVector());
119  addVector(layout, m_item->directionVector());
120  auto* layoutUV = new QFormLayout;
121  createSpinBox(layoutUV, m_item->u0());
122  createSpinBox(layoutUV, m_item->v0());
123  layout->addRow(descr + ":", layoutUV);
124  } else {
125  auto* layoutUVD = new QFormLayout;
126  createSpinBox(layoutUVD, m_item->u0());
127  createSpinBox(layoutUVD, m_item->v0());
128  createSpinBox(layoutUVD, m_item->distance());
129  layout->addRow(descr + ":", layoutUVD);
130  }
131 }
void addVector(QFormLayout *parentLayout, const VectorDescriptor &d)
RectangularDetector::EDetectorArrangement detectorAlignment() const

References addVector(), createSpinBox(), RectangularDetectorItem::detectorAlignment(), m_formLayout, and m_item.

Referenced by DetectorAlignmentEditor().

Here is the call graph for this function:

◆ createSpinBox() [1/2]

DoubleSpinBox * DetectorAlignmentEditor::createSpinBox ( QFormLayout *  parentFormLayout,
const DoubleDescriptor d 
)
private

Definition at line 63 of file DetectorAlignmentEditor.cpp.

65 {
66  auto* sb = GUI::Util::createSpinBox(parentFormLayout, d);
67  connect(sb, &DoubleSpinBox::baseValueChanged, [=](double v) {
68  if (d.get() != v) {
69  d.set(v);
70  emit dataChanged();
71  }
72  });
73  return sb;
74 }
function< double()> get
function to get the current value
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
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(), and DoubleDescriptor::get.

Referenced by addVector(), and createAligmentWidgets().

Here is the call graph for this function:

◆ createSpinBox() [2/2]

DoubleSpinBox * DetectorAlignmentEditor::createSpinBox ( QWidget *  parent,
const DoubleDescriptor d 
)
private

Definition at line 76 of file DetectorAlignmentEditor.cpp.

77 {
78  auto* sb = new DoubleSpinBox(parent, d);
79  connect(sb, &DoubleSpinBox::baseValueChanged, [=](double v) {
80  if (d.get() != v) {
81  d.set(v);
82  emit dataChanged();
83  }
84  });
85  return sb;
86 }
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22

References DoubleSpinBox::baseValueChanged(), and DoubleDescriptor::get.

◆ dataChanged

void DetectorAlignmentEditor::dataChanged ( )
signal

Member Data Documentation

◆ m_formLayout

QFormLayout* DetectorAlignmentEditor::m_formLayout
private

Definition at line 46 of file DetectorAlignmentEditor.h.

Referenced by DetectorAlignmentEditor(), and createAligmentWidgets().

◆ m_item

RectangularDetectorItem* DetectorAlignmentEditor::m_item
private

Definition at line 45 of file DetectorAlignmentEditor.h.

Referenced by DetectorAlignmentEditor(), and createAligmentWidgets().


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