26 #include <QMessageBox>
27 #include <QPushButton>
30 bool QuestionOnInstrumentReshaping(
const QString& message);
34 : QObject(parent), m_instrumentModel(nullptr), m_realDataModel(nullptr)
43 ASSERT(instrumentModel !=
nullptr);
44 ASSERT(realDataModel !=
nullptr);
65 const QString& identifier,
78 "Can't link, data is incompatible with the instrument.");
85 "Can't link, data is empty.");
89 if (instrumentItem->alignedWith(realDataItem))
94 ?
"Experimental data carries information on the range/points of measurement."
96 if (!QuestionOnInstrumentReshaping(message))
99 instrumentItem->updateToRealData(realDataItem);
107 if (child ==
nullptr)
110 ASSERT(instrument !=
nullptr);
116 realDataItem->clearInstrumentId();
118 realDataItem->updateToInstrument(instrument);
128 realDataItem->clearInstrumentId();
139 instrumentItem->mapper()->unsubscribe(
this);
141 instrumentItem->mapper()->setOnAnyChildChange(
153 ASSERT(instrumentItem !=
nullptr);
155 QList<RealDataItem*> result;
157 const QString linkedIdentifier = realDataItem->instrumentId();
158 const QString instrumentIdentifier = instrumentItem->
id();
160 if (linkedIdentifier == instrumentIdentifier)
161 result.append(realDataItem);
167 bool QuestionOnInstrumentReshaping(
const QString& message)
170 msgBox.setText(
"Instrument description conflicts with the experimental data.");
173 informative.append(message);
174 informative.append(
"\n\nDo you want to adjust the instrument to the experimental data?\n\n");
175 msgBox.setInformativeText(informative);
177 QPushButton* modifyInstrumentButton =
178 msgBox.addButton(
"Yes, please modify instrument", QMessageBox::YesRole);
179 msgBox.addButton(
"No, leave as it is", QMessageBox::NoRole);
183 return msgBox.clickedButton() == modifyInstrumentButton;
#define ASSERT(condition)
Defines various axis items.
Defines classes DetectorItems.
Defines class MainWindow.
Defines ImportDataUtils namespace.
Defines InstrumentItems classes.
Defines class InstrumentModel.
Defines class LinkInstrumentManager.
Defines MaskItems classes.
Defines class RealDataItem.
Defines class RealDataModel.
virtual bool alignedWith(const RealDataItem *item) const
bool instrumentExists(const QString &instrumentId) const
InstrumentItem * findInstrumentById(const QString &instrumentId) const
QVector< InstrumentItem * > instrumentItems() const
void instrumentAddedOrRemoved()
void onInstrumentAddedOrRemoved()
Updates map of instruments on insert/remove InstrumentItem event.
bool canLinkDataToInstrument(const RealDataItem *realDataItem, const QString &identifier, bool quiet=false)
quiet defines whether a "not possible" message box is shown if link is not possible.
LinkInstrumentManager(QObject *parent=nullptr)
QList< RealDataItem * > linkedRealDataItems(InstrumentItem *instrumentItem)
Returns list of RealDataItem's linked to given instrument.
void setModels(InstrumentModel *instrumentModel, RealDataModel *realDataModel)
Sets models and builds initial links.
void onInstrumentChildChange(InstrumentItem *instrument, SessionItem *child)
Perform actions on instrument children change.
void updateInstrumentSubscriptions()
Set up callbacks to all instrument items.
InstrumentModel * m_instrumentModel
RealDataModel * m_realDataModel
static MainWindow * instance()
Returns the one and only instance of this class.
The RealDataItem class represents intensity data imported from file and intended for fitting.
bool holdsDimensionalData() const
std::vector< int > shape() const
Returns the shape of underlying data item.
bool isSpecularData() const
bool hasNativeData() const
The RealDataModel class is a model to store all imported RealDataItem's.
QVector< RealDataItem * > realDataItems() const
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
QString printShapeMessage(const std::vector< int > &instrument_shape, const std::vector< int > &data_shape)
Composes a message with the shapes of InstrumentItem and RealDataItem.
bool Compatible(const InstrumentItem &instrumentItem, const RealDataItem &realDataItem)
Check whether data item is compatible with instrument (same rank)