BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ApplicationModels.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Model/ApplicationModels.cpp
6 //! @brief Defines class holding all application models
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 
20 #include <QXmlStreamWriter>
21 
23  : m_realDataModel(nullptr)
24  , m_jobModel(nullptr)
25 {
26  //! creates and initializes models, order is important
27  m_realDataModel = new RealDataModel(this);
28  m_jobModel = new JobModel(this);
29 
32 }
33 
35 {
36  return m_realDataModel;
37 }
38 
40 {
41  return m_jobModel;
42 }
43 
44 //! Writes all model in file one by one
45 
46 void ApplicationModels::writeTo(QXmlStreamWriter* writer)
47 {
48  m_realDataModel->writeTo(writer);
49  m_jobModel->writeTo(writer);
50 }
51 
52 void ApplicationModels::readFrom(QXmlStreamReader* reader, MessageService* messageService)
53 {
54  try {
55  if (m_realDataModel->getModelTag() == reader->name())
56  m_realDataModel->readFrom(reader, messageService);
57  else if (m_jobModel->getModelTag() == reader->name())
58  m_jobModel->readFrom(reader, messageService);
59  } catch (DeserializationException& ex) {
61  m_jobModel->clear();
62  reader->raiseError(ex.text());
63  }
64 }
65 
66 
67 QVector<SessionItem*> ApplicationModels::nonXMLItems() const
68 {
69  ASSERT(m_realDataModel && m_jobModel);
70  return QVector<SessionItem*>() << m_realDataModel->nonXMLItems() << m_jobModel->nonXMLItems();
71 }
72 
74 {
75  if (!model)
76  return;
77  connect(model, &SessionModel::dataChanged, this, &ApplicationModels::modelChanged,
78  Qt::UniqueConnection);
79  connect(model, &SessionModel::rowsRemoved, this, &ApplicationModels::modelChanged,
80  Qt::UniqueConnection);
81  connect(model, &SessionModel::rowsInserted, this, &ApplicationModels::modelChanged,
82  Qt::UniqueConnection);
83 }
Defines class holding all application models.
Defines class DeserializationException.
Defines class JobModel.
Defines class RealDataModel.
Defines class SimulationOptionsItem.
JobModel * jobModel() const
QVector< SessionItem * > nonXMLItems() const
Returns all non-XML items.
void readFrom(class QXmlStreamReader *reader, MessageService *messageService)
RealDataModel * m_realDataModel
RealDataModel * realDataModel() const
void writeTo(class QXmlStreamWriter *writer)
Writes all model in file one by one.
void connectModel(SessionModel *model) const
void clear() override
Definition: JobModel.cpp:100
void readFrom(QXmlStreamReader *reader, MessageService *messageService=nullptr) override
Definition: JobModel.cpp:127
QVector< SessionItem * > nonXMLItems() const override
Definition: JobModel.cpp:108
The service to collect messages from different senders.
The RealDataModel class is a model to store all imported RealDataItem's.
Definition: RealDataModel.h:24
void readFrom(QXmlStreamReader *reader, MessageService *messageService=nullptr) override
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
virtual void clear()
QString getModelTag() const
Definition: SessionModel.h:202
virtual void writeTo(QXmlStreamWriter *writer)