BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RectangularDetectorEditor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/InstrumentWidgets/RectangularDetectorEditor.cpp
6 //! @brief Implements class RectangularDetectorEditor
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 <QGridLayout>
21 
23  : SessionItemWidget(parent)
24  , m_xAxisEditor(nullptr)
25  , m_yAxisEditor(nullptr)
26  , m_resolutionFunctionEditor(nullptr)
27  , m_alignmentEditor(nullptr)
28  , m_positionsEditor(nullptr)
29  , m_normalEditor(nullptr)
30  , m_directionEditor(nullptr)
31  , m_gridLayout(new QGridLayout)
32 {
34 
35  auto mainLayout = new QVBoxLayout;
36  mainLayout->setContentsMargins(0, 0, 0, 0);
37  mainLayout->addLayout(m_gridLayout);
38  mainLayout->addStretch();
39  setLayout(mainLayout);
40 }
41 
42 void RectangularDetectorEditor::onPropertyChanged(const QString& propertyName)
43 {
44  if (propertyName == RectangularDetectorItem::P_ALIGNMENT)
46 }
47 
49 {
51  [this](const QString& name) { onPropertyChanged(name); }, this);
52 
53  init_editors();
54 }
55 
57 {
65 }
66 
68 {
69  auto result = dynamic_cast<RectangularDetectorItem*>(currentItem());
70  ASSERT(result);
71  return result;
72 }
73 
75 {
76  // axes and resolution function editors
78  m_gridLayout->addWidget(m_xAxisEditor, 1, 0);
79 
81  m_gridLayout->addWidget(m_yAxisEditor, 1, 1);
82 
84  new ComponentEditor(ComponentEditor::GroupWidget, "Resolution function");
85  m_gridLayout->addWidget(m_resolutionFunctionEditor, 1, 2);
86 
87  // alignment selector editors
89  m_gridLayout->addWidget(m_alignmentEditor, 2, 0);
90 
91  // editors for various positions
93  m_gridLayout->addWidget(m_positionsEditor, 3, 0);
94 
96  m_gridLayout->addWidget(m_normalEditor, 3, 1);
97 
99  m_gridLayout->addWidget(m_directionEditor, 3, 2);
100 }
101 
103 {
105  m_xAxisEditor->setItem(detectorItem()->xAxisItem());
106 
108  m_yAxisEditor->setItem(detectorItem()->yAxisItem());
109 
112  m_resolutionFunctionEditor->setItem(resFuncGroup);
113 
116 
118 }
119 
121 {
123  m_positionsEditor->hide();
124 
126  m_normalEditor->hide();
127 
129  m_directionEditor->hide();
130 
131  ComboProperty alignment =
133 
134  if (alignment.getValue() == "Generic") {
135  m_positionsEditor->show();
136  m_normalEditor->show();
137  m_directionEditor->show();
138 
141 
142  auto normalVectorItem = detectorItem()->getItem(RectangularDetectorItem::P_NORMAL);
143  m_normalEditor->setItem(normalVectorItem);
144 
145  auto directionVectorItem = detectorItem()->getItem(RectangularDetectorItem::P_DIRECTION);
146  m_directionEditor->setItem(directionVectorItem);
147 
148  } else if (alignment.getValue() == "Perpendicular to direct beam"
149  || alignment.getValue() == "Perpendicular to reflected beam (dpos)") {
150  m_positionsEditor->show();
154 
155  } else if (alignment.getValue() == "Perpendicular to sample x-axis"
156  || alignment.getValue() == "Perpendicular to reflected beam") {
157  m_positionsEditor->show();
158 
162  }
163 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines various axis items.
Defines class ComboProperty.
Defines ComponentEditor class.
Defines class RectangularDetectorEditor.
Defines class RectangularDetectorItem.
Custom property to define list of string values with multiple selections.
Definition: ComboProperty.h:25
QString getValue() const
Component editor for SessionItem.
void addItem(SessionItem *item)
void setItem(SessionItem *item)
static const QString P_RESOLUTION_FUNCTION
Definition: DetectorItems.h:28
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=0)
Definition: ModelMapper.cpp:35
RectangularDetectorItem * detectorItem()
RectangularDetectorEditor(QWidget *parent=nullptr)
void onPropertyChanged(const QString &propertyName)
ComponentEditor * m_resolutionFunctionEditor
static const QString P_DIRECTION
static const QString P_NORMAL
static const QString P_DBEAM_V0
static const QString P_DISTANCE
static const QString P_ALIGNMENT
static const QString P_DBEAM_U0
The SessionItemWidget class is a base for all widgets representing the content of SessionItem.
SessionItem * currentItem()
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
QString const & name(EShape k)
Definition: particles.cpp:21