BornAgain  1.19.79
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/Model/Model/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(GUI::Session::XML::RealDataModelTag, parent)
22 {
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  auto* r = insertItem<RealDataItem>();
60  r->initAsSpecularItem();
61  return r;
62 }
63 
65 {
66  auto* r = insertItem<RealDataItem>();
67  r->initAsIntensityItem();
68  return r;
69 }
70 
72 {
73  return (rank == 1) ? insertSpecularDataItem() : insertIntensityDataItem();
74 }
75 
76 QVector<RealDataItem*> RealDataModel::realDataItems() const
77 {
78  return topItems<RealDataItem>();
79 }
80 
81 
82 QVector<RealDataItem*> RealDataModel::realDataItems(int rank) const
83 {
84  return rank == 1 ? realDataItems1D() : realDataItems2D();
85 }
86 
87 QVector<RealDataItem*> RealDataModel::realDataItems1D() const
88 {
89  return topItems<RealDataItem>([](const RealDataItem& item) { return item.isSpecularData(); });
90 }
91 
92 QVector<RealDataItem*> RealDataModel::realDataItems2D() const
93 {
94  return topItems<RealDataItem>([](const RealDataItem& item) { return !item.isSpecularData(); });
95 }
96 
98 {
99  removeItem(item);
100 }
101 
102 QStringList RealDataModel::realDataNames() const
103 {
104  QStringList result;
105  for (auto item : realDataItems())
106  result.append(item->dataName());
107  return result;
108 }
109 
110 void RealDataModel::onRowsChange(const QModelIndex& parent, int, int)
111 {
112  // valid parent means not a data (which is top level item) but something below
113  if (parent.isValid())
114  return;
115 
116  emit realDataAddedOrRemoved();
117 }
Declares class DataItem.
Defines class RealDataItem.
Defines class RealDataModel.
Defines reader and writer classes for SessionModel.
The service to collect messages from different senders.
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33
bool isSpecularData() const
QVector< RealDataItem * > realDataItems2D() const
RealDataItem * insertIntensityDataItem()
void readFrom(QXmlStreamReader *reader, MessageService *messageService=nullptr) override
void onRowsChange(const QModelIndex &parent, int, int)
void realDataAddedOrRemoved()
QVector< RealDataItem * > realDataItems() const
RealDataItem * insertDataItem(int rank)
void removeItem(SessionItem *item)
RealDataModel(QObject *parent=nullptr)
QVector< RealDataItem * > realDataItems1D() const
RealDataItem * insertSpecularDataItem()
QStringList realDataNames() const
void remove(RealDataItem *item)
QVector< SessionItem * > nonXMLItems() const override
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
Definition: SessionModel.h:42
QModelIndex parent(const QModelIndex &child) const override
virtual void readFrom(QXmlStreamReader *reader, MessageService *messageService=nullptr)
constexpr auto RealDataModelTag("RealDataModel")
Definition: def.cpp:20
Definition: Streamer.h:23