BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
InstrumentView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Instrument/InstrumentView.cpp
6 //! @brief Implements class InstrumentView
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 
25 #include <QBoxLayout>
26 #include <QFormLayout>
27 #include <QGroupBox>
28 #include <QLabel>
29 #include <QLineEdit>
30 #include <QScrollArea>
31 #include <QTextEdit>
32 
34  : QWidget(parent)
35  , m_document(document)
36 {
37  setAttribute(Qt::WA_StyledBackground, true);
38  setProperty("stylable", true); // for stylesheet addressing
39 
40  auto* horizontalLayout = new QHBoxLayout;
41  m_instrumentListView = new InstrumentListView(document, this);
42  horizontalLayout->addWidget(m_instrumentListView);
43 
44  m_scrollArea = new QScrollArea(this);
45  m_scrollArea->setWidgetResizable(true);
46  m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
47  horizontalLayout->addWidget(m_scrollArea, 1);
48 
49  auto* toolbar = new StyledToolbar(this);
50  toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
51  toolbar->addActions(m_instrumentListView->toolbarActions());
52 
53  auto* mainLayout = new QVBoxLayout(this);
54  mainLayout->setMargin(0);
55  mainLayout->setSpacing(0);
56  mainLayout->addWidget(toolbar);
57  mainLayout->addLayout(horizontalLayout);
58 
61 
64 
67 }
68 
69 void InstrumentView::showEvent(QShowEvent*)
70 {
71  // disconnect because when this view is visible, no other instance is modifying instruments. By
72  // disconnecting, no additional logic is necessary to avoid recursive calls (recursive since
73  // this view also causes instrumentChanged to be emitted).
77 }
78 
79 void InstrumentView::hideEvent(QHideEvent*)
80 {
81  // when the instrument view gets hidden (meaning another view is shown), it's necessary to
82  // listen to changes (e.g. performed by the LinkInstrumentManager).
85 }
86 
88 {
89  auto* currentInstrument = m_instrumentListView->currentInstrument();
90  if (!currentInstrument) {
91  m_scrollArea->setWidget(new QWidget(m_scrollArea)); // blank widget
92  return;
93  }
94 
95  QWidget* w = new QWidget(m_scrollArea);
96  auto* layout = new QVBoxLayout(w);
97 
98  w->setAttribute(Qt::WA_StyledBackground, true);
99  w->setProperty("stylable", true); // for stylesheet addressing
100 
101  auto* g = new QGroupBox(m_scrollArea);
102  g->setTitle(QString("Information (%1 instrument)").arg(currentInstrument->instrumentType()));
103 
104  auto* formLayout = new QFormLayout(g);
105  formLayout->setMargin(17);
106  formLayout->setSpacing(8);
107  layout->addWidget(g);
108 
109  auto* nameEdit = new QLineEdit(g);
110  formLayout->addRow("Name:", nameEdit);
111  nameEdit->setText(currentInstrument->instrumentName());
112  connect(nameEdit, &QLineEdit::textEdited, this, &InstrumentView::onInstrumentNameEdited);
113 
114  auto* descriptionEdit = new QTextEdit(g);
115  descriptionEdit->setMinimumWidth(300);
116  descriptionEdit->setMaximumHeight(100);
117  descriptionEdit->setAcceptRichText(false);
118  descriptionEdit->setTabChangesFocus(true);
119  descriptionEdit->setPlainText(currentInstrument->description());
120  formLayout->addRow("Description:", descriptionEdit);
121  connect(descriptionEdit, &QTextEdit::textChanged,
122  [=]() { onInstrumentdescriptionEdited(descriptionEdit->toPlainText()); });
123 
125 
126  if (auto* sp = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) {
127  auto* editor =
129  connect(editor, &SpecularInstrumentEditor::dataChanged, this,
131  layout->addWidget(editor);
132  } else if (auto* os = dynamic_cast<OffspecInstrumentItem*>(currentInstrument)) {
133  auto* editor = new OffspecInstrumentEditor(m_scrollArea, os);
134  connect(editor, &OffspecInstrumentEditor::dataChanged, this,
136  layout->addWidget(editor);
137  } else if (auto* gisas = dynamic_cast<GISASInstrumentItem*>(currentInstrument)) {
138  auto* editor = new GISASInstrumentEditor(m_scrollArea, gisas);
139  connect(editor, &GISASInstrumentEditor::dataChanged, this,
141  layout->addWidget(editor);
142  } else if (auto* dp = dynamic_cast<DepthProbeInstrumentItem*>(currentInstrument)) {
143  auto* editor = new DepthProbeInstrumentEditor(m_scrollArea, dp);
144  connect(editor, &DepthProbeInstrumentEditor::dataChanged, this,
146  layout->addWidget(editor);
147  } else
148  ASSERT(false);
149 
150  m_scrollArea->setWidget(w);
151 }
152 
153 void InstrumentView::onInstrumentNameEdited(const QString& newName)
154 {
155  auto* currentInstrument = m_instrumentListView->currentInstrument();
156  if (currentInstrument && currentInstrument->instrumentName() != newName)
157  m_document->instrumentsEditController()->setInstrumentName(currentInstrument, newName);
158 }
159 
161 {
162  auto* currentInstrument = m_instrumentListView->currentInstrument();
163  if (currentInstrument && currentInstrument->description() != t) {
164  currentInstrument->setDescription(t);
166  }
167 }
168 
170 {
173 }
174 
176 {
177  if (instrument == m_instrumentListView->currentInstrument())
179 }
180 
182 {
184 }
Defines class DepthProbeInstrumentEditor.
Defines class GISASInstrumentEditor.
Defines class GroupBoxCollapser.
Defines class InstrumentItem and all its children.
Defines class InstrumentListView.
Defines class InstrumentView.
Defines class OffspecInstrumentEditor.
Defines class ProjectDocument.
Defines class SpecularInstrumentEditor.
Defines class StyledToolbar.
Editor for GISAS instruments.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Abstract base class for instrument-specific item classes.
void setDescription(const QString &description)
Instrument selector on the left side of InstrumentView.
InstrumentItem * currentInstrument() const
void instrumentSelected(InstrumentItem *instrument)
QList< QAction * > toolbarActions() const
void onInstrumentdescriptionEdited(const QString &t)
void onInstrumentNameEdited(const QString &newName)
void hideEvent(QHideEvent *) override
void createWidgetsForCurrentInstrument()
QScrollArea * m_scrollArea
void onInstrumentChangedByEditor()
InstrumentListView * m_instrumentListView
InstrumentView(QWidget *parent, ProjectDocument *document)
ProjectDocument * m_document
void onInstrumentChangedFromExternal(const InstrumentItem *instrument)
void updateSingleInstrumentMode()
void showEvent(QShowEvent *) override
void instrumentChanged(const InstrumentItem *instrument)
Signals any change in the settings of the given instrument.
void notifyInstrumentChanged(InstrumentItem *instrument)
Simply emits the instrumentChanged signal. Call this whenever you change an instrument's data without...
void setInstrumentName(InstrumentItem *instrument, const QString &name)
Set an instrument's name and emit the respective signal.
Project document class handles all data related to the opened project (sample, job,...
void singleInstrumentModeChanged()
Emitted when single instrument mode has changed.
bool singleInstrumentMode() const
InstrumentsEditController * instrumentsEditController()
The edit controller for the instruments in this project document.
The StyledToolbar class represents our standard narrow toolbar with the height 24 pixels.
Definition: StyledToolbar.h:22