BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ProjectDocument.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Project/ProjectDocument.h
6 //! @brief Defines class ProjectDocument
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 
15 #ifndef BORNAGAIN_GUI_MODEL_PROJECT_PROJECTDOCUMENT_H
16 #define BORNAGAIN_GUI_MODEL_PROJECT_PROJECTDOCUMENT_H
17 
24 #include <QObject>
25 #include <QVariant>
26 #include <memory>
27 
28 class QIODevice;
29 class MessageService;
30 class DatafieldIOService;
31 class RealDataModel;
32 class JobModel;
33 
34 //! Project document class handles all data related to the opened project
35 //! (sample, job, project specific settings).
36 //!
37 //! It also provides signaling regarding changes in the current document data.
38 //!
39 //! e.g. if project file is /home/users/development/Untitled/Untitled.pro
40 //! projectName() - 'Untitled'
41 //! projectDir() - '/home/users/development/Untitled
42 //! projectFileName() - '/home/users/development/Untitled/Untitled.pro'
43 class ProjectDocument : public QObject {
44  Q_OBJECT
45 
46 public:
47  enum class ReadResult { ok, warning, error };
48 
50  None = 0x0,
51  Gisas = 0x1,
52  Offspec = 0x2,
53  Specular = 0x4,
54  DepthProbe = 0x8,
56  };
57  Q_DECLARE_FLAGS(Functionalities, Functionality)
58  Q_FLAG(Functionalities)
59 
61 
62  QString projectName() const;
63  void setProjectName(const QString& text);
64 
65  QString projectDir() const;
66  QString validProjectDir() const;
67  void setProjectDir(const QString& text);
68  QString userExportDir() const;
69 
70  QString projectFileName() const;
71  void setProjectFileName(const QString& projectFileName);
72 
76  JobModel* jobModel() const;
78 
80 
81  //! The edit controller for the instruments in this project document.
82  //!
83  //! Use this to modify instrument list or instrument data.
84  //! Listen to its signals to get notification about any changes.
85  //! \sa InstrumentsEditController for more information
87 
88  void save(const QString& project_file_name, bool autoSave = false);
89 
90  void saveProjectFile(const QString& project_file_name, bool autoSave = false);
91  void saveProjectData(const QString& project_file_name);
92 
93  ReadResult loadProjectFile(const QString& project_file_name, MessageService& messageService);
94 
95  bool hasValidNameAndPath();
96 
97  bool isModified() const;
98  void setModified();
99  void clearModified();
100 
101  bool hasData() const;
102 
103  QString documentVersion() const;
104 
105  bool singleInstrumentMode() const;
106  void setSingleInstrumentMode(bool b);
107 
108  bool singleSampleMode() const;
109  void setSingleSampleMode(bool b);
110 
111  Functionalities functionalities() const;
112  void setFunctionalities(const Functionalities& f);
113 
114 signals:
115  //! Emitted for _any_ modifications in the document
116  void modified();
117 
118  //! Emitted when functionality has changed
120 
121  //! Emitted when single instrument mode has changed
123 
124  //! Emitted when single sample mode has changed
126 
127 private:
128  ReadResult readProject(QIODevice* device, MessageService& messageService);
129  void writeTo(QIODevice* device);
130 
131  void disconnectModels();
132  void connectModels();
133  void onModelChanged();
134 
135  QString m_project_dir;
136  QString m_project_name;
141  std::unique_ptr<LinkInstrumentManager> m_linkManager;
144  Functionalities m_functionalities;
149 };
150 
151 Q_DECLARE_OPERATORS_FOR_FLAGS(ProjectDocument::Functionalities)
152 
153 inline QVariant toVariant(const ProjectDocument::Functionalities& f)
154 {
155  return QVariant(static_cast<ProjectDocument::Functionalities::Int>(f));
156 }
157 
158 inline ProjectDocument::Functionalities toFunctionalities(const QVariant& v)
159 {
160  return static_cast<ProjectDocument::Functionalities>(
161  v.value<ProjectDocument::Functionalities::Int>());
162 }
163 
164 #endif // BORNAGAIN_GUI_MODEL_PROJECT_PROJECTDOCUMENT_H
Defines class holding all application models.
Defines class InstrumentItem and all its children.
Defines class InstrumentsEditController.
Defines class LinkInstrumentManager.
Defines class MultiLayerItems.
ProjectDocument::Functionalities toFunctionalities(const QVariant &v)
QVariant toVariant(const ProjectDocument::Functionalities &f)
Defines class SimulationOptionsItem.
Provide read/write of heavy data files in a separate thread.
Definition: IOService.h:30
Class to modify the instruments list or a single instrument and provide the necessary signaling withi...
The LinkInstrumentManager class provides communication between InstrumentCollection and RealDataModel...
The service to collect messages from different senders.
Main model to hold sample items.
Project document class handles all data related to the opened project (sample, job,...
void singleSampleModeChanged()
Emitted when single sample mode has changed.
JobModel * jobModel() const
ApplicationModels m_applicationModels
RealDataModel * realDataModel() const
void setSingleInstrumentMode(bool b)
InstrumentCollection m_instruments
QString projectFileName() const
void setProjectDir(const QString &text)
void saveProjectData(const QString &project_file_name)
SimulationOptionsItem m_simulationOptionsItem
void singleInstrumentModeChanged()
Emitted when single instrument mode has changed.
QString documentVersion() const
void functionalitiesChanged()
Emitted when functionality has changed.
void setSingleSampleMode(bool b)
void saveProjectFile(const QString &project_file_name, bool autoSave=false)
QString projectName() const
InstrumentCollection * collectedItems() const
void setFunctionalities(const Functionalities &f)
void setProjectFileName(const QString &projectFileName)
MultiLayerItems m_sampleItems
LinkInstrumentManager * linkInstrumentManager()
ReadResult readProject(QIODevice *device, MessageService &messageService)
void setProjectName(const QString &text)
QString validProjectDir() const
ReadResult loadProjectFile(const QString &project_file_name, MessageService &messageService)
void writeTo(QIODevice *device)
bool isModified() const
bool hasData() const
Functionalities functionalities() const
MultiLayerItems * sampleItems()
InstrumentsEditController m_instrumentEditController
bool singleInstrumentMode() const
std::unique_ptr< LinkInstrumentManager > m_linkManager
DatafieldIOService * m_dataService
QString projectDir() const
void modified()
Emitted for any modifications in the document.
QString userExportDir() const
Returns directory name suitable for saving plots.
Functionalities m_functionalities
SimulationOptionsItem * simulationOptionsItem()
void save(const QString &project_file_name, bool autoSave=false)
QString m_currentVersion
InstrumentsEditController * instrumentsEditController()
The edit controller for the instruments in this project document.
bool singleSampleMode() const
The RealDataModel class is a model to store all imported RealDataItem's.
Definition: RealDataModel.h:24
The SimulationOptionsItem class holds simulation status (run policy, number of threads,...