BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
LinkInstrumentManager Class Reference

Description

The LinkInstrumentManager class provides communication between InstrumentCollection and RealDataModel. Particularly, it notifies RealDataItem about changes in linked instruments to adjust axes of IntensityDataItem.

Definition at line 31 of file LinkInstrumentManager.h.

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

Signals

void linkToInstrumentChanged (const RealDataItem *realDataItem)
 

Public Member Functions

 LinkInstrumentManager (ProjectDocument *document)
 
bool canLinkDataToInstrument (const RealDataItem *realDataItem, const QString &identifier, QWidget *parent)
 Returns true if RealDataItem can be linked to the instrument (same number of bins). Also offers dialog to adjust instrument to match shape of real data. quiet defines whether a "not possible" message box is shown if link is not possible. Use this e.g. for unit tests. The question for adjusting the instrument is not suppressed by this flag. More...
 

Private Member Functions

void onInstrumentAddedOrRemoved ()
 
void onInstrumentChanged (const InstrumentItem *instrument)
 

Private Attributes

ProjectDocumentm_document
 

Constructor & Destructor Documentation

◆ LinkInstrumentManager()

LinkInstrumentManager::LinkInstrumentManager ( ProjectDocument document)

Definition at line 68 of file LinkInstrumentManager.cpp.

69  : m_document(document)
70 {
74 
77 }
void instrumentAddedOrRemoved()
Signals a change in the list of instruments.
void instrumentChanged(const InstrumentItem *instrument)
Signals any change in the settings of the given instrument.
ProjectDocument * m_document
void onInstrumentChanged(const InstrumentItem *instrument)
InstrumentsEditController * instrumentsEditController()
The edit controller for the instruments in this project document.

References InstrumentsEditController::instrumentAddedOrRemoved(), InstrumentsEditController::instrumentChanged(), ProjectDocument::instrumentsEditController(), m_document, onInstrumentAddedOrRemoved(), and onInstrumentChanged().

Here is the call graph for this function:

Member Function Documentation

◆ canLinkDataToInstrument()

bool LinkInstrumentManager::canLinkDataToInstrument ( const RealDataItem realDataItem,
const QString &  identifier,
QWidget *  parent 
)

Returns true if RealDataItem can be linked to the instrument (same number of bins). Also offers dialog to adjust instrument to match shape of real data. quiet defines whether a "not possible" message box is shown if link is not possible. Use this e.g. for unit tests. The question for adjusting the instrument is not suppressed by this flag.

Definition at line 79 of file LinkInstrumentManager.cpp.

81 {
82  auto* instrumentItem = m_document->collectedItems()->findInstrumentById(identifier);
83 
84  // linking to null instrument is possible, it means unlinking from currently linked
85  if (!instrumentItem)
86  return true;
87 
88  if (instrumentItem->shape().size() != realDataItem->shape().size()) {
89  if (parent)
90  QMessageBox::warning(parent, "Can't link to instrument",
91  "Can't link, data is incompatible with the instrument.");
92  return false;
93  }
94 
95  if (realDataItem->isSpecularData() && !realDataItem->hasNativeData()) {
96  if (parent)
97  QMessageBox::warning(parent, "Can't link to instrument", "Can't link, data is empty.");
98  return false;
99  }
100 
101  if (instrumentItem->alignedWith(realDataItem))
102  return true;
103 
104  QString message =
105  realDataItem->holdsDimensionalData()
106  ? "Experimental data carries information on the range/points of measurement."
107  : printShapeMessage(instrumentItem->shape(), realDataItem->shape());
108  if (!QuestionOnInstrumentReshaping(message))
109  return false;
110 
112  realDataItem);
113  return true;
114 }
InstrumentItem * findInstrumentById(const QString &instrumentId) const
void updateInstrumentToRealDataItem(InstrumentItem *instrument, const RealDataItem *realDataItem)
Calls the instrument's updateToRealData and emits the respective signal.
InstrumentCollection * collectedItems() const
bool holdsDimensionalData() const
std::vector< int > shape() const
Returns the shape of underlying data item.
bool isSpecularData() const
bool hasNativeData() const
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:37

References ProjectDocument::collectedItems(), InstrumentCollection::findInstrumentById(), RealDataItem::hasNativeData(), RealDataItem::holdsDimensionalData(), ProjectDocument::instrumentsEditController(), RealDataItem::isSpecularData(), m_document, RealDataItem::shape(), InstrumentsEditController::updateInstrumentToRealDataItem(), and GUI::View::Helpers::warning().

Referenced by RealDataPropertiesWidget::onInstrumentComboIndexChanged().

Here is the call graph for this function:

◆ linkToInstrumentChanged

void LinkInstrumentManager::linkToInstrumentChanged ( const RealDataItem realDataItem)
signal

◆ onInstrumentAddedOrRemoved()

void LinkInstrumentManager::onInstrumentAddedOrRemoved ( )
private

Definition at line 130 of file LinkInstrumentManager.cpp.

131 {
132  // remove links in realDataItems (in case of a linked instrument was removed)
133  for (auto* realDataItem : m_document->realDataModel()->realDataItems())
134  if (!m_document->collectedItems()->instrumentExists(realDataItem->instrumentId()))
135  realDataItem->unlinkFromInstrument();
136 }
bool instrumentExists(const QString &instrumentId) const
RealDataModel * realDataModel() const
QVector< RealDataItem * > realDataItems() const

References ProjectDocument::collectedItems(), InstrumentCollection::instrumentExists(), m_document, RealDataModel::realDataItems(), and ProjectDocument::realDataModel().

Referenced by LinkInstrumentManager().

Here is the call graph for this function:

◆ onInstrumentChanged()

void LinkInstrumentManager::onInstrumentChanged ( const InstrumentItem instrument)
private

Definition at line 116 of file LinkInstrumentManager.cpp.

117 {
118  // Run through all RealDataItem and refresh linking to match possible change in detector
119  // axes definition.
120  for (auto* realDataItem : m_document->realDataModel()->realDataItems())
121  if (realDataItem->instrumentId() == instrument->id()) {
122  if (!instrument->alignedWith(realDataItem)) {
123  realDataItem->unlinkFromInstrument();
124  emit linkToInstrumentChanged(realDataItem);
125  } else
126  realDataItem->linkToInstrument(instrument); // link stays same, only data is updated
127  }
128 }
QString id() const
virtual bool alignedWith(const RealDataItem *item) const
void linkToInstrumentChanged(const RealDataItem *realDataItem)

References InstrumentItem::alignedWith(), InstrumentItem::id(), linkToInstrumentChanged(), m_document, RealDataModel::realDataItems(), and ProjectDocument::realDataModel().

Referenced by LinkInstrumentManager().

Here is the call graph for this function:

Member Data Documentation

◆ m_document

ProjectDocument* LinkInstrumentManager::m_document
private

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