20 #include <QMessageBox>
21 #include <QPushButton>
25 bool QuestionOnInstrumentReshaping(
const QString& message)
28 msgBox.setText(
"Instrument description conflicts with the experimental data.");
31 informative.append(message);
32 informative.append(
"\n\nDo you want to adjust the instrument to the experimental data?\n\n");
33 msgBox.setInformativeText(informative);
35 QPushButton* modifyInstrumentButton =
36 msgBox.addButton(
"Yes, please modify instrument", QMessageBox::YesRole);
37 msgBox.addButton(
"No, leave as it is", QMessageBox::NoRole);
41 return msgBox.clickedButton() == modifyInstrumentButton;
45 QString printShapeMessage(
const std::vector<int>& instrument_shape,
46 const std::vector<int>& data_shape)
48 auto to_str = [](
const std::vector<int>& shape) {
50 for (
size_t i = 0, size = shape.size(); i < size; ++i) {
51 result += std::to_string(shape[i]);
58 std::string message_string =
"instrument [";
59 message_string += to_str(instrument_shape);
60 message_string +=
"], data [";
61 message_string += to_str(data_shape);
62 message_string +=
"]";
63 return QString::fromStdString(message_string);
69 : m_document(document)
80 const QString& identifier, QWidget* parent)
88 if (instrumentItem->shape().size() != realDataItem->
shape().size()) {
91 "Can't link, data is incompatible with the instrument.");
101 if (instrumentItem->alignedWith(realDataItem))
106 ?
"Experimental data carries information on the range/points of measurement."
107 : printShapeMessage(instrumentItem->shape(), realDataItem->
shape());
108 if (!QuestionOnInstrumentReshaping(message))
121 if (realDataItem->instrumentId() == instrument->
id()) {
123 realDataItem->unlinkFromInstrument();
126 realDataItem->linkToInstrument(instrument);
135 realDataItem->unlinkFromInstrument();
Defines class InstrumentItem and all its children.
Defines class LinkInstrumentManager.
Defines class ProjectDocument.
Defines class RealDataItem.
Defines class RealDataModel.
InstrumentItem * findInstrumentById(const QString &instrumentId) const
bool instrumentExists(const QString &instrumentId) const
Abstract base class for instrument-specific item classes.
virtual bool alignedWith(const RealDataItem *item) const
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.
void updateInstrumentToRealDataItem(InstrumentItem *instrument, const RealDataItem *realDataItem)
Calls the instrument's updateToRealData and emits the respective signal.
void onInstrumentAddedOrRemoved()
LinkInstrumentManager(ProjectDocument *document)
ProjectDocument * m_document
void linkToInstrumentChanged(const RealDataItem *realDataItem)
void onInstrumentChanged(const InstrumentItem *instrument)
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,...
RealDataModel * realDataModel() const
InstrumentCollection * collectedItems() const
InstrumentsEditController * instrumentsEditController()
The edit controller for the instruments in this project document.
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
bool holdsDimensionalData() const
std::vector< int > shape() const
Returns the shape of underlying data item.
bool isSpecularData() const
bool hasNativeData() const
QVector< RealDataItem * > realDataItems() const
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)