BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
RealDataPropertiesWidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Import/RealDataPropertiesWidget.cpp
6 //! @brief Implements class RealDataPropertiesWidget
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
22 #include <QComboBox>
23 #include <QLabel>
24 #include <QVBoxLayout>
25 
27  : QWidget(parent)
28  , m_instrumentCombo(new QComboBox)
29  , m_currentDataItem(nullptr)
30  , m_document(document)
31 {
32  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
33  setWindowTitle("RealDataPropertiesWidget");
34 
35  auto* mainLayout = new QVBoxLayout;
36  mainLayout->setMargin(5);
37  mainLayout->setSpacing(2);
38 
39  m_instrumentCombo->setToolTip("Select instrument to link with real data");
40 
41  mainLayout->addWidget(new QLabel("Linked instrument"));
42  mainLayout->addWidget(m_instrumentCombo);
43 
44  mainLayout->addStretch();
45  setLayout(mainLayout);
46 
48  setEnabled(false);
49 
50  connect(m_instrumentCombo,
51  static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
53 
57 
61 
64 }
65 
67 {
68  m_currentDataItem = item;
70  setEnabled(m_currentDataItem != nullptr);
71 }
72 
74 {
75  if (!m_currentDataItem)
76  return;
77 
78  const QString newSelectedInstrumentId = m_instrumentCombo->currentData().toString();
79 
80  if (newSelectedInstrumentId == m_currentDataItem->instrumentId())
81  return;
82 
84  m_currentDataItem, newSelectedInstrumentId, GUI::Global::mainWindow)) {
85  const auto* newSelectedInstrument =
86  m_document->collectedItems()->findInstrumentById(newSelectedInstrumentId);
87  m_currentDataItem->linkToInstrument(newSelectedInstrument);
88  } else
89  // Linking was impossible or denied. Set combo to previous state
91 }
92 
93 //! Updates instrument selector for new instruments and their names.
94 //! Current selection will be preserved.
95 
97 {
98  QSignalBlocker b(m_instrumentCombo);
99 
100  m_instrumentCombo->clear();
101 
102  // fill the combo. Userdata contains instrument's uid
103  m_instrumentCombo->addItem("Undefined", ""); // undefined instrument
104  for (auto* instrumentItem : m_document->collectedItems()->collectedItems())
105  m_instrumentCombo->addItem(instrumentItem->instrumentName(), instrumentItem->id());
106 
108 }
109 
110 //! Sets instrument combo selector to the state corresponding to given instrument identifier.
111 
113 {
114  const QString instrumentId =
115  m_currentDataItem != nullptr ? m_currentDataItem->instrumentId() : "";
116 
117  QSignalBlocker b(m_instrumentCombo);
118  m_instrumentCombo->setCurrentIndex(m_instrumentCombo->findData(instrumentId));
119 }
Defines global pointers.
Defines class InstrumentItem and all its children.
Defines class InstrumentsEditController.
Defines class LinkInstrumentManager.
Defines class ProjectDocument.
Defines class RealDataItem.
Defines class RealDataPropertiesWidget.
InstrumentItem * findInstrumentById(const QString &instrumentId) const
QVector< InstrumentItem * > collectedItems() const
void instrumentNameChanged(const InstrumentItem *instrument)
Signals name change of the given instrument.
void instrumentAddedOrRemoved()
Signals a change in the list of instruments.
void linkToInstrumentChanged(const RealDataItem *realDataItem)
bool canLinkDataToInstrument(const RealDataItem *realDataItem, const QString &identifier, QWidget *parent)
Returns true if RealDataItem can be linked to the instrument (same number of bins)....
Project document class handles all data related to the opened project (sample, job,...
InstrumentCollection * collectedItems() const
LinkInstrumentManager * linkInstrumentManager()
InstrumentsEditController * instrumentsEditController()
The edit controller for the instruments in this project document.
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33
void linkToInstrument(const InstrumentItem *instrument)
QString instrumentId() const
void updateInstrumentComboEntries()
Updates instrument selector for new instruments and their names. Current selection will be preserved.
void updateInstrumentComboIndex()
Sets instrument combo selector to the state corresponding to given instrument identifier.
void setItem(RealDataItem *item)
Set current RealDataItem to display in instrument selector.
void onInstrumentComboIndexChanged(int index)
Processes user interaction with instrument selector combo. If there is realDataItem,...
RealDataPropertiesWidget(QWidget *parent, ProjectDocument *document)
static QMainWindow * mainWindow
Definition: Globals.h:22