BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
AbstractDataLoader.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Support/IO/AbstractDataLoader.h
6 //! @brief Defines class AbstractDataLoader
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_SUPPORT_IO_ABSTRACTDATALOADER_H
16 #define BORNAGAIN_GUI_SUPPORT_IO_ABSTRACTDATALOADER_H
17 
18 class QString;
19 class QByteArray;
20 class QGroupBox;
21 class QCustomPlot;
22 class QTableWidget;
23 class RealDataItem;
25 
26 #include <QtCore>
27 
28 //! Abstract base class for all data loaders (classes to import real data).
29 
30 class AbstractDataLoader : public QObject {
31  Q_OBJECT
32 public:
33  ~AbstractDataLoader() override = default;
34 
35  //! The name shown in the format selection combo
36  virtual QString name() const = 0;
37 
38  //! A name which can be used for save/load purposes (which will not change ever more)
39  virtual QString persistentClassName() const = 0;
40 
41  //! Define the real data item on which the import shall work.
42  void setRealDataItem(RealDataItem* item);
43 
44  //! The real data item on which the import shall work.
46 
47  //! The real data item on which the import shall work.
48  const RealDataItem* realDataItem() const;
49 
50  //! Fills the widget on the import dialog pane.
51  //! The implementation here in the base class does nothing
52  //! (meaning "no editable properties").
53  virtual void populateImportSettingsWidget(QWidget* parent);
54 
55  //! Read all values from the properties UI into the internal variables
56  virtual void applyImportSettings();
57 
58  //! Set import settings to defaults
59  virtual void initWithDefaultImportSettings();
60 
61  //! Return the default import settings
62  virtual QByteArray defaultImportSettings() const;
63 
64  //! Create a complete clone, including all internal states
65  virtual AbstractDataLoader* clone() const = 0;
66 
67  //! Returns every internal setting so it can be restored completely
68  virtual QByteArray serialize() const;
69 
70  //! Initialize from serialization data. If any error occurred,
71  //! then a DeserializationException has to be thrown.
72  //! The complete state has to be restored.
73  //! Therefore if e.g. errors occurred in the former serialization,
74  //! but errors are not serialized, then they have to be regenerated/
75  //! recalculated in here.
76  virtual void deserialize(const QByteArray& data);
77 
78  //! Sets the file contents to be imported.
79  //! If the file was a compressed file, then the decompressed content
80  //! will be handed over already here.
81  virtual void setFileContents(const QByteArray& fileContent) = 0;
82 
83  //! Returns the original file content.
84  //! If not available any more (like for legacy project file import),
85  //! then an empty array will be returned.
86  virtual QByteArray fileContent() const;
87 
88  //! Guess appropriate settings (for example the separator in a CSV file).
89  //! Is called only once, directly after setting the file content.
90  virtual void guessSettings();
91 
92  //! Process the file contents.
93  //! Can be called more than once, e.g. if the import settings have changed.
94  //! Any error has to be stored in the loader (see numErrors()).
95  virtual void processContents() = 0;
96 
97  //! Number of errors found while processing the content.
98  //! An error means that either a particular content (line) can't be used
99  //! or may be suspicious (line related error), or that the whole content
100  //! can't be used (e.g. only 1 line present).
101  virtual int numErrors() const;
102 
103  //! Number of errors related to a specific line. Such an error means that
104  //! a particular content (line) can't be used or may be suspicious.
105  virtual int numLineRelatedErrors() const;
106 
107  //! Errors not related to a particular line.
108  virtual QStringList lineUnrelatedErrors() const;
109 
110  //! Create a table model which contains the import information like
111  //! original file content, raw content, processed content.
112  //! The returned pointer will be owned by the caller.
113  //! This base class' implementation does nothing (return nullptr).
115 
116 signals:
117  //! Emitted whenever an import setting changed
119 
120  //! Emitted whenever contents have been processed
122 
123 protected:
124  RealDataItem* m_item; //!< The real-data-item which owns this loader. Never delete this!
125 };
126 
127 QDataStream& operator<<(QDataStream& stream, const AbstractDataLoader& s);
128 QDataStream& operator>>(QDataStream& stream, AbstractDataLoader& s);
129 
130 #endif // BORNAGAIN_GUI_SUPPORT_IO_ABSTRACTDATALOADER_H
QDataStream & operator>>(QDataStream &stream, AbstractDataLoader &s)
QDataStream & operator<<(QDataStream &stream, const AbstractDataLoader &s)
Base class for result tables of data loaders. Derive from this class and return an instance in YourDa...
Abstract base class for all data loaders (classes to import real data).
virtual QByteArray serialize() const
Returns every internal setting so it can be restored completely.
virtual void applyImportSettings()
Read all values from the properties UI into the internal variables.
~AbstractDataLoader() override=default
virtual void populateImportSettingsWidget(QWidget *parent)
Fills the widget on the import dialog pane. The implementation here in the base class does nothing (m...
virtual AbstractDataLoaderResultModel * createResultModel() const
Create a table model which contains the import information like original file content,...
virtual void guessSettings()
Guess appropriate settings (for example the separator in a CSV file). Is called only once,...
void contentsProcessed()
Emitted whenever contents have been processed.
void importSettingsChanged()
Emitted whenever an import setting changed.
virtual QString persistentClassName() const =0
A name which can be used for save/load purposes (which will not change ever more)
virtual QString name() const =0
The name shown in the format selection combo.
virtual void setFileContents(const QByteArray &fileContent)=0
Sets the file contents to be imported. If the file was a compressed file, then the decompressed conte...
virtual void deserialize(const QByteArray &data)
Initialize from serialization data. If any error occurred, then a DeserializationException has to be ...
virtual int numErrors() const
Number of errors found while processing the content. An error means that either a particular content ...
virtual void processContents()=0
Process the file contents. Can be called more than once, e.g. if the import settings have changed....
virtual void initWithDefaultImportSettings()
Set import settings to defaults.
virtual QByteArray fileContent() const
Returns the original file content. If not available any more (like for legacy project file import),...
virtual QStringList lineUnrelatedErrors() const
Errors not related to a particular line.
virtual AbstractDataLoader * clone() const =0
Create a complete clone, including all internal states.
RealDataItem * m_item
The real-data-item which owns this loader. Never delete this!
RealDataItem * realDataItem()
The real data item on which the import shall work.
virtual QByteArray defaultImportSettings() const
Return the default import settings.
void setRealDataItem(RealDataItem *item)
Define the real data item on which the import shall work.
virtual int numLineRelatedErrors() const
Number of errors related to a specific line. Such an error means that a particular content (line) can...
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33