BornAgain  1.19.0
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/coregui/DataLoaders/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_COREGUI_DATALOADERS_ABSTRACTDATALOADER_H
16 #define BORNAGAIN_GUI_COREGUI_DATALOADERS_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 //! Base class for all data loaders (classes which can import real data)
29 
30 class AbstractDataLoader : public QObject {
31  Q_OBJECT
32 public:
33  virtual ~AbstractDataLoader() = 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. This base class' implementation does nothing
51  //! (meaning "no editable properties")
52  virtual void populateImportSettingsWidget(QWidget* parent);
53 
54  //! Read all values from the properties UI into the internal variables
55  virtual void applyImportSettings();
56 
57  //! Set import settings to defaults
58  virtual void initWithDefaultImportSettings();
59 
60  //! Return the default import settings
61  virtual QByteArray defaultImportSettings() const;
62 
63  //! Create a complete clone, including all internal states
64  virtual AbstractDataLoader* clone() const = 0;
65 
66  //! Returns every internal setting so it can be restored completely
67  virtual QByteArray serialize() const;
68 
69  //! Initialize from serialization data. If any error occurred, then a DeserializationException
70  //! has to be thrown.
71  //! The complete state has to be restored. Therefore if e.g. errors occurred in the former
72  //! serialization, but errors are not serialized, then they have to be regenerated/recalculated
73  //! in here.
74  virtual void deserialize(const QByteArray& data);
75 
76  //! Sets the file contents to be imported. If the file was a compressed file, here already the
77  //! decompressed content will be overhanded.
78  virtual void setFileContents(const QByteArray& fileContent) = 0;
79 
80  //! Returns the original file content. If not available any more (like for legacy project file
81  //! import), then an empty array will be returned.
82  virtual QByteArray fileContent() const;
83 
84  //! Guess appropriate settings (for example the separator in a CSV file). Is called only once,
85  //! directly after setting the file content.
86  virtual void guessSettings();
87 
88  //! Process the file contents. Can be called more than once, e.g. if the import settings have
89  //! changed.
90  //! Any error has to be stored in the loader (see numErrors()).
91  virtual void processContents() = 0;
92 
93  //! Number of errors found while processing the content. An error means that either a particular
94  //! content (line) can't be used or may be suspicious (line related error), or that the whole
95  //! content can't be used (e.g. only 1 line present).
96  virtual int numErrors() const;
97 
98  //! Number of errors related to a specific line. Such an error means that a particular
99  //! content (line) can't be used or may be suspicious.
100  virtual int numLineRelatedErrors() const;
101 
102  //! Errors not related to a particular line.
103  virtual QStringList lineUnrelatedErrors() const;
104 
105  //! Create a table model which contains the import information like original file content, raw
106  //! content, processed content
107  //! The returned pointer will be owned by the caller.
108  //! This base class' implementation does nothing (return nullptr).
110 
111 signals:
112  //! Emitted whenever an import setting changed
114 
115  //! Emitted whenever contents have been processed
117 
118 protected:
120 
121 protected:
122  RealDataItem* m_item; //< The real-data-item which owns this loader. Never delete this!
123 };
124 
125 QDataStream& operator<<(QDataStream& stream, const AbstractDataLoader& s);
126 QDataStream& operator>>(QDataStream& stream, AbstractDataLoader& s);
127 
128 #endif // BORNAGAIN_GUI_COREGUI_DATALOADERS_ABSTRACTDATALOADER_H
QDataStream & operator>>(QDataStream &stream, AbstractDataLoader &s)
Base class for result tables of data loaders.
Base class for all data loaders (classes which can 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.
virtual void populateImportSettingsWidget(QWidget *parent)
Fills the widget on the import dialog pane.
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).
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.
virtual void deserialize(const QByteArray &data)
Initialize from serialization data.
virtual int numErrors() const
Number of errors found while processing the content.
virtual void processContents()=0
Process the file contents.
virtual ~AbstractDataLoader()=default
virtual void initWithDefaultImportSettings()
Set import settings to defaults.
virtual QByteArray fileContent() const
Returns the original file content.
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 * 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.
std::ostream & operator<<(std::ostream &os, const BasicVector3D< T > &a)
Output to stream.
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35