BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RealDataModel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/RealDataModel.cpp
6 //! @brief Implements class RealDataModel
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
19 
21  : SessionModel(SessionXML::RealDataModelTag, parent), m_instrumentModel(nullptr)
22 {
23  setObjectName(SessionXML::RealDataModelTag);
24 
25  connect(this, &SessionModel::rowsInserted, this, &RealDataModel::onRowsChange);
26  connect(this, &SessionModel::rowsRemoved, this, &RealDataModel::onRowsChange);
27 }
28 
29 QVector<SessionItem*> RealDataModel::nonXMLItems() const
30 {
31  QVector<SessionItem*> result;
32 
33  for (auto realData : topItems<RealDataItem>()) {
34  if (auto intensityItem = realData->dataItem())
35  result.push_back(intensityItem);
36  if (auto native_data_item = realData->nativeData())
37  result.push_back(native_data_item);
38  }
39 
40  return result;
41 }
42 
43 void RealDataModel::readFrom(QXmlStreamReader* reader, MessageService* messageService /*= 0*/)
44 {
45  // do not send added-notifications until completely read - otherwise partially
46  // initialized items will be notified
47  disconnect(this, &SessionModel::rowsInserted, this, &RealDataModel::onRowsChange);
48 
49  SessionModel::readFrom(reader, messageService);
50 
51  connect(this, &SessionModel::rowsInserted, this, &RealDataModel::onRowsChange);
52 
53  if (!realDataItems().isEmpty())
55 }
56 
58 {
59  return insertItem<RealDataItem>();
60 }
61 
63 {
64  auto r = insertRealDataItem();
65  r->initAsSpecularItem();
66  return r;
67 }
68 
70 {
71  auto r = insertRealDataItem();
72  r->initAsIntensityItem();
73  return r;
74 }
75 
76 QVector<RealDataItem*> RealDataModel::realDataItems() const
77 {
78  return topItems<RealDataItem>();
79 }
80 
81 QVector<RealDataItem*> RealDataModel::realDataItems1D() const
82 {
83  return topItems<RealDataItem>([](const RealDataItem& item) { return item.isSpecularData(); });
84 }
85 
86 QVector<RealDataItem*> RealDataModel::realDataItems2D() const
87 {
88  return topItems<RealDataItem>([](const RealDataItem& item) { return !item.isSpecularData(); });
89 }
90 
92 {
93  return m_instrumentModel;
94 }
95 
97 {
99 }
100 
101 void RealDataModel::onRowsChange(const QModelIndex& parent, int, int)
102 {
103  // valid parent means not a data (which is top level item) but something below
104  if (parent.isValid())
105  return;
106 
107  emit realDataAddedOrRemoved();
108 }
Declares class DataItem.
Defines MessageService class.
Defines class RealDataItem.
Defines class RealDataModel.
The service to collect messages from different senders.
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35
bool isSpecularData() const
void setInstrumentModel(InstrumentModel *instrumentModel)
QVector< RealDataItem * > realDataItems2D() const
RealDataItem * insertIntensityDataItem()
QPointer< InstrumentModel > m_instrumentModel
Definition: RealDataModel.h:55
void onRowsChange(const QModelIndex &parent, int, int)
RealDataItem * insertRealDataItem()
void realDataAddedOrRemoved()
QVector< RealDataItem * > realDataItems() const
InstrumentModel * instrumentModel() const
QVector< RealDataItem * > realDataItems1D() const
RealDataModel(QObject *parent=0)
RealDataItem * insertSpecularDataItem()
virtual QVector< SessionItem * > nonXMLItems() const override
virtual void readFrom(QXmlStreamReader *reader, MessageService *messageService=0) override
virtual QModelIndex parent(const QModelIndex &child) const
virtual void readFrom(QXmlStreamReader *reader, MessageService *messageService=0)
const QString RealDataModelTag("RealDataModel")