BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RealDataPropertiesWidget Class Reference

The RealDataPropertiesWidget class holds instrument selector to link with RealDataItem. More...

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

Public Slots

void onInstrumentComboIndexChanged (int index)
 Processes user interaction with instrument selector combo. More...
 
void onRealDataPropertyChanged ()
 Updates instrument combo if instrument link of current RealDataItem changed. More...
 
void updateInstrumentComboEntries ()
 Updates instrument selector for new instruments and their names. More...
 

Public Member Functions

 RealDataPropertiesWidget (QWidget *parent=0)
 
QSize minimumSizeHint () const
 
void setItem (RealDataItem *item)
 Set current RealDataItem to display in instrument selector. More...
 
QSize sizeHint () const
 

Private Member Functions

void setComboToIdentifier (const QString &instrumentId)
 Sets instrument combo selector to the state corresponding to given instrument identifier. More...
 
void setPropertiesEnabled (bool enabled)
 Sets all widget's children enabled/disabled. More...
 

Private Attributes

RealDataItemm_currentDataItem
 
QComboBox * m_instrumentCombo
 

Detailed Description

The RealDataPropertiesWidget class holds instrument selector to link with RealDataItem.

Part of RealDataSelectorWidget, resides at lower left corner of ImportDataView.

Definition at line 27 of file RealDataPropertiesWidget.h.

Constructor & Destructor Documentation

◆ RealDataPropertiesWidget()

RealDataPropertiesWidget::RealDataPropertiesWidget ( QWidget *  parent = 0)
explicit

Definition at line 26 of file RealDataPropertiesWidget.cpp.

27  : QWidget(parent), m_instrumentCombo(new QComboBox), m_currentDataItem(nullptr)
28 {
29  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
30  setWindowTitle("RealDataPropertiesWidget");
31 
32  QVBoxLayout* mainLayout = new QVBoxLayout;
33  mainLayout->setMargin(5);
34  mainLayout->setSpacing(2);
35 
36  m_instrumentCombo->setToolTip("Select instrument to link with real data");
37 
38  mainLayout->addWidget(new QLabel("Linked instrument"));
39  mainLayout->addWidget(m_instrumentCombo);
40 
41  mainLayout->addStretch();
42  setLayout(mainLayout);
43 
44  connect(m_instrumentCombo,
45  static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
47 
50 
51  connect(MainWindow::instance()->instrumentModel(), &InstrumentModel::instrumentNameChanged,
53 
55  setPropertiesEnabled(false);
56 }
void instrumentNameChanged(const InstrumentItem *instrument)
void instrumentAddedOrRemoved()
static MainWindow * instance()
Returns the one and only instance of this class.
Definition: mainwindow.cpp:129
void updateInstrumentComboEntries()
Updates instrument selector for new instruments and their names.
void setPropertiesEnabled(bool enabled)
Sets all widget's children enabled/disabled.
void onInstrumentComboIndexChanged(int index)
Processes user interaction with instrument selector combo.

References MainWindow::instance(), InstrumentModel::instrumentAddedOrRemoved(), InstrumentModel::instrumentNameChanged(), m_instrumentCombo, onInstrumentComboIndexChanged(), setPropertiesEnabled(), and updateInstrumentComboEntries().

Here is the call graph for this function:

Member Function Documentation

◆ minimumSizeHint()

QSize RealDataPropertiesWidget::minimumSizeHint ( ) const
inline

Definition at line 33 of file RealDataPropertiesWidget.h.

33 { return QSize(64, 128); }

◆ onInstrumentComboIndexChanged

void RealDataPropertiesWidget::onInstrumentComboIndexChanged ( int  index)
slot

Processes user interaction with instrument selector combo.

If there is realDataItem, it will be linked with selected instrument.

Definition at line 88 of file RealDataPropertiesWidget.cpp.

89 {
90  if (!m_currentDataItem)
91  return;
92 
93  const QString newSelectedInstrumentId = m_instrumentCombo->currentData().toString();
94 
95  if (newSelectedInstrumentId == m_currentDataItem->instrumentId())
96  return;
97 
98  if (MainWindow::instance()->linkInstrumentManager()->canLinkDataToInstrument(
99  m_currentDataItem, newSelectedInstrumentId)) {
100  m_currentDataItem->setInstrumentId(newSelectedInstrumentId);
101  m_currentDataItem->updateToInstrument(newSelectedInstrumentId);
102  } else
103  // Linking was impossible or denied. Set combo to previous state
105 }
void setInstrumentId(const QString &id)
void updateToInstrument(const InstrumentItem *instrument)
QString instrumentId() const
void setComboToIdentifier(const QString &instrumentId)
Sets instrument combo selector to the state corresponding to given instrument identifier.

References MainWindow::instance(), RealDataItem::instrumentId(), m_currentDataItem, m_instrumentCombo, setComboToIdentifier(), RealDataItem::setInstrumentId(), and RealDataItem::updateToInstrument().

Referenced by RealDataPropertiesWidget().

Here is the call graph for this function:

◆ onRealDataPropertyChanged

void RealDataPropertiesWidget::onRealDataPropertyChanged ( )
slot

Updates instrument combo if instrument link of current RealDataItem changed.

Definition at line 133 of file RealDataPropertiesWidget.cpp.

134 {
135  // This can be called when combo on this page was changed, but also when the linking
136  // is undone because of instrument deletion or similar
137  if (!m_currentDataItem)
138  return;
139 
140  // The notification comes for different reasons, therefore a check for "link changed" is done
141  // first
142  const bool linkChanged =
143  m_instrumentCombo->currentData().toString() != m_currentDataItem->instrumentId();
144 
145  if (linkChanged)
147 }

References RealDataItem::instrumentId(), m_currentDataItem, m_instrumentCombo, and setComboToIdentifier().

Referenced by setItem().

Here is the call graph for this function:

◆ setComboToIdentifier()

void RealDataPropertiesWidget::setComboToIdentifier ( const QString &  instrumentId)
private

Sets instrument combo selector to the state corresponding to given instrument identifier.

Definition at line 151 of file RealDataPropertiesWidget.cpp.

152 {
153  const int index = m_instrumentCombo->findData(instrumentId);
154  ASSERT(index >= 0);
155 
156  QSignalBlocker b(m_instrumentCombo);
157  m_instrumentCombo->setCurrentIndex(index);
158 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, and m_instrumentCombo.

Referenced by onInstrumentComboIndexChanged(), onRealDataPropertyChanged(), and setItem().

◆ setItem()

void RealDataPropertiesWidget::setItem ( RealDataItem item)

Set current RealDataItem to display in instrument selector.

Definition at line 60 of file RealDataPropertiesWidget.cpp.

61 {
62  if (item == m_currentDataItem)
63  return;
64 
67 
68  m_currentDataItem = item;
69 
71 
72  if (!m_currentDataItem)
73  return;
74 
76  [this](const QString&) { onRealDataPropertyChanged(); }, this);
77 
79  [this](SessionItem*) { m_currentDataItem = nullptr; }, this);
80 
81  // Set combo selector to show linked instrument
83 }
void unsubscribe(const void *caller)
Cancells all subscribtion of given caller.
Definition: ModelMapper.cpp:98
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=0)
Definition: ModelMapper.cpp:87
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=0)
Definition: ModelMapper.cpp:35
void onRealDataPropertyChanged()
Updates instrument combo if instrument link of current RealDataItem changed.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.

References RealDataItem::instrumentId(), m_currentDataItem, SessionItem::mapper(), onRealDataPropertyChanged(), setComboToIdentifier(), ModelMapper::setOnItemDestroy(), ModelMapper::setOnPropertyChange(), setPropertiesEnabled(), and ModelMapper::unsubscribe().

Referenced by RealDataSelectorWidget::onSelectionChanged().

Here is the call graph for this function:

◆ setPropertiesEnabled()

void RealDataPropertiesWidget::setPropertiesEnabled ( bool  enabled)
private

Sets all widget's children enabled/disabled.

Definition at line 162 of file RealDataPropertiesWidget.cpp.

163 {
164  setEnabled(enabled);
165  if (!enabled)
166  m_instrumentCombo->setCurrentIndex(0);
167 }

References m_instrumentCombo.

Referenced by RealDataPropertiesWidget(), and setItem().

◆ sizeHint()

QSize RealDataPropertiesWidget::sizeHint ( ) const
inline

Definition at line 32 of file RealDataPropertiesWidget.h.

32 { return QSize(64, 135); }

◆ updateInstrumentComboEntries

void RealDataPropertiesWidget::updateInstrumentComboEntries ( )
slot

Updates instrument selector for new instruments and their names.

Current selection will be preserved.

Definition at line 110 of file RealDataPropertiesWidget.cpp.

111 {
112  QString currentId = m_currentDataItem != nullptr ? m_currentDataItem->instrumentId() : "";
113 
114  QSignalBlocker b(m_instrumentCombo);
115 
116  m_instrumentCombo->clear();
117 
118  // fill the combo. Userdata contains instrument's uid
119  m_instrumentCombo->addItem("Undefined", ""); // undefined instrument
120  for (auto instrumentItem : MainWindow::instance()->instrumentModel()->instrumentItems())
121  m_instrumentCombo->addItem(instrumentItem->name(), instrumentItem->id());
122 
123  const int index = m_instrumentCombo->findData(currentId);
124  if (index >= 0)
125  m_instrumentCombo->setCurrentIndex(index);
126  else
127  // instrument selected in data item was deleted
128  m_instrumentCombo->setCurrentIndex(0);
129 }

References MainWindow::instance(), RealDataItem::instrumentId(), m_currentDataItem, and m_instrumentCombo.

Referenced by RealDataPropertiesWidget().

Here is the call graph for this function:

Member Data Documentation

◆ m_currentDataItem

RealDataItem* RealDataPropertiesWidget::m_currentDataItem
private

◆ m_instrumentCombo

QComboBox* RealDataPropertiesWidget::m_instrumentCombo
private

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