BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InstrumentEditorWidget.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/InstrumentEditorWidget.cpp
6 //! @brief Implements class InstrumentEditorWidget
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 <QBoxLayout>
21 #include <QGroupBox>
22 #include <QLabel>
23 #include <QLineEdit>
24 
26  : QWidget(parent)
27  , m_nameLineEdit(new QLineEdit)
28  , m_instrumentPresenter(new InstrumentPresenter)
29  , m_currentItem(nullptr)
30  , m_block_signals(false)
31 {
32  setMinimumSize(400, 400);
33  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
34 
35  auto mainLayout = new QVBoxLayout;
36  mainLayout->setContentsMargins(0, 20, 0, 20);
37  mainLayout->addLayout(createTopLayout());
38 
39  auto scrollArea = new AdjustingScrollArea;
40  scrollArea->setWidget(m_instrumentPresenter);
41  mainLayout->addWidget(scrollArea, 1);
42  mainLayout->addStretch();
43 
44  setLayout(mainLayout);
45 
46  connect(m_nameLineEdit, &QLineEdit::textChanged, this,
48 }
49 
51 {
52  return QSize(600, 600);
53 }
54 
56 {
57  m_currentItem = instrument;
58  updateWidgets();
59 
60  m_instrumentPresenter->setItem(instrument);
61 }
62 
64 {
65  if (m_block_signals)
66  return;
67 
68  if (m_currentItem)
70 }
71 
72 //! top block with instrument name
73 
75 {
76  auto result = new QHBoxLayout;
77 
78  m_nameLineEdit->setMinimumWidth(200);
79 
80  result->addSpacing(17);
81  result->addWidget(new QLabel("Instrument name"));
82  result->addWidget(m_nameLineEdit);
83  result->addStretch(1);
84 
85  return result;
86 }
87 
89 {
90  m_block_signals = true;
91 
92  if (m_currentItem) {
93  m_nameLineEdit->setEnabled(true);
95  } else {
96  m_nameLineEdit->setText(QString());
97  m_nameLineEdit->setEnabled(false);
98  }
99 
100  m_block_signals = false;
101 }
Defines class AdjustingScrollArea.
Defines classes DetectorItems.
Defines class InstrumentEditorWidget.
Defines InstrumentItems classes.
Defines class InstrumentPresenter.
Modification of standard scroll area, which makes widget with dynamic layout ocuupy whole available s...
void setWidget(QWidget *w)
void onChangedEditor(const QString &)
void setItem(SessionItem *instrument)
InstrumentPresenter * m_instrumentPresenter
InstrumentEditorWidget(QWidget *parent=nullptr)
QLayout * createTopLayout()
top block with instrument name
Contains stack of instrument editors and the logic to show proper editor for certain type of instrume...
virtual void setItem(SessionItem *item)
QString itemName() const
Get item name, return display name if no name is set.
void setItemName(const QString &name)
Set item name, add property if necessary.