BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
AutomaticDataLoader1D Class Reference

Implements the legacy importer from BornAgain with no user interaction. More...

Inheritance diagram for AutomaticDataLoader1D:
[legend]
Collaboration diagram for AutomaticDataLoader1D:
[legend]

Signals

void contentsProcessed ()
 Emitted whenever contents have been processed. More...
 
void importSettingsChanged ()
 Emitted whenever an import setting changed. More...
 

Public Member Functions

virtual void applyImportSettings ()
 Read all values from the properties UI into the internal variables. More...
 
virtual AbstractDataLoaderclone () const override
 Create a complete clone, including all internal states. More...
 
virtual AbstractDataLoaderResultModelcreateResultModel () const override
 Create a table model which contains the import information like original file content, raw content, processed content The returned pointer will be owned by the caller. More...
 
virtual QByteArray defaultImportSettings () const
 Return the default import settings. More...
 
virtual void deserialize (const QByteArray &data) override
 Initialize from serialization data. More...
 
virtual QByteArray fileContent () const override
 Returns the original file content. More...
 
virtual void guessSettings ()
 Guess appropriate settings (for example the separator in a CSV file). More...
 
virtual void initWithDefaultImportSettings ()
 Set import settings to defaults. More...
 
virtual QStringList lineUnrelatedErrors () const override
 Errors not related to a particular line. More...
 
virtual QString name () const override
 The name shown in the format selection combo. More...
 
virtual int numErrors () const override
 Number of errors found while processing the content. More...
 
virtual int numLineRelatedErrors () const
 Number of errors related to a specific line. More...
 
virtual QString persistentClassName () const override
 A name which can be used for save/load purposes (which will not change ever more) More...
 
virtual void populateImportSettingsWidget (QWidget *parent)
 Fills the widget on the import dialog pane. More...
 
virtual void processContents () override
 Process the file contents. More...
 
RealDataItemrealDataItem ()
 The real data item on which the import shall work. More...
 
const RealDataItemrealDataItem () const
 The real data item on which the import shall work. More...
 
virtual QByteArray serialize () const override
 Returns every internal setting so it can be restored completely. More...
 
virtual void setFileContents (const QByteArray &fileContent) override
 Sets the file contents to be imported. More...
 
void setRealDataItem (RealDataItem *item)
 Define the real data item on which the import shall work. More...
 

Protected Types

enum class  Error { DifferendNumberOfColumns }
 

Protected Attributes

RealDataItemm_item
 

Private Attributes

QString m_error
 
QByteArray m_fileContent
 

Detailed Description

Implements the legacy importer from BornAgain with no user interaction.

Definition at line 22 of file AutomaticDataLoader1D.h.

Member Enumeration Documentation

◆ Error

enum AbstractDataLoader::Error
strongprotectedinherited
Enumerator
DifferendNumberOfColumns 

Definition at line 119 of file AbstractDataLoader.h.

119 { DifferendNumberOfColumns };

Member Function Documentation

◆ applyImportSettings()

void AbstractDataLoader::applyImportSettings ( )
virtualinherited

Read all values from the properties UI into the internal variables.

Reimplemented in QREDataLoader.

Definition at line 20 of file AbstractDataLoader.cpp.

20 {}

Referenced by DataLoaders1D::cloneAsUserDefinedLoader(), and SpecularDataImportWidget::onPropertiesChanged().

◆ clone()

AbstractDataLoader * AutomaticDataLoader1D::clone ( ) const
overridevirtual

Create a complete clone, including all internal states.

Implements AbstractDataLoader.

Definition at line 35 of file AutomaticDataLoader1D.cpp.

36 {
37  auto loader = new AutomaticDataLoader1D();
38  loader->deserialize(serialize());
39  return loader;
40 }
Implements the legacy importer from BornAgain with no user interaction.
virtual QByteArray serialize() const override
Returns every internal setting so it can be restored completely.

References serialize().

Here is the call graph for this function:

◆ contentsProcessed

void AbstractDataLoader::contentsProcessed ( )
signalinherited

Emitted whenever contents have been processed.

Referenced by processContents(), QREDataLoader::processContents(), and RealDataItem::setDataLoader().

◆ createResultModel()

AbstractDataLoaderResultModel * AutomaticDataLoader1D::createResultModel ( ) const
overridevirtual

Create a table model which contains the import information like original file content, raw content, processed content The returned pointer will be owned by the caller.

This base class' implementation does nothing (return nullptr).

Reimplemented from AbstractDataLoader.

Definition at line 109 of file AutomaticDataLoader1D.cpp.

110 {
112 }
The result model of a AutomaticDataLoader1D (for showing the import results in a table view).

References AbstractDataLoader::m_item.

◆ defaultImportSettings()

QByteArray AbstractDataLoader::defaultImportSettings ( ) const
virtualinherited

Return the default import settings.

Definition at line 31 of file AbstractDataLoader.cpp.

32 {
33  std::unique_ptr<AbstractDataLoader> cloned(clone());
34  cloned->initWithDefaultImportSettings();
35  return cloned->serialize();
36 }
virtual AbstractDataLoader * clone() const =0
Create a complete clone, including all internal states.

References AbstractDataLoader::clone().

Here is the call graph for this function:

◆ deserialize()

void AutomaticDataLoader1D::deserialize ( const QByteArray &  data)
overridevirtual

Initialize from serialization data.

If any error occurred, then a DeserializationException has to be thrown. The complete state has to be restored. Therefore if e.g. errors occurred in the former serialization, but errors are not serialized, then they have to be regenerated/recalculated in here.

Reimplemented from AbstractDataLoader.

Definition at line 55 of file AutomaticDataLoader1D.cpp.

56 {
57  m_fileContent.clear();
58  m_error.clear();
59 
60  QDataStream s(data);
61  s.setVersion(QDataStream::Qt_5_12);
62 
63  quint8 version;
64  s >> version;
65 
66  if (version == 1) {
67  s >> m_fileContent;
68  s >> m_error;
69  } else
71 
72  if (s.status() != QDataStream::Ok)
74 }
static DeserializationException streamError()
static DeserializationException tooNew()

References m_error, m_fileContent, DeserializationException::streamError(), and DeserializationException::tooNew().

Here is the call graph for this function:

◆ fileContent()

QByteArray AutomaticDataLoader1D::fileContent ( ) const
overridevirtual

Returns the original file content.

If not available any more (like for legacy project file import), then an empty array will be returned.

Reimplemented from AbstractDataLoader.

Definition at line 81 of file AutomaticDataLoader1D.cpp.

82 {
83  return m_fileContent;
84 }

References m_fileContent.

Referenced by setFileContents().

◆ guessSettings()

void AbstractDataLoader::guessSettings ( )
virtualinherited

Guess appropriate settings (for example the separator in a CSV file).

Is called only once, directly after setting the file content.

Reimplemented in UserDefinedDataLoader1D, and QREDataLoader.

Definition at line 38 of file AbstractDataLoader.cpp.

38 {}

Referenced by UserDefinedDataLoader1D::guessSettings(), ImportDataUtils::Import1dData(), and SpecularDataImportWidget::onFormatSelectionChanged().

◆ importSettingsChanged

void AbstractDataLoader::importSettingsChanged ( )
signalinherited

◆ initWithDefaultImportSettings()

void AbstractDataLoader::initWithDefaultImportSettings ( )
virtualinherited

Set import settings to defaults.

Reimplemented in UserDefinedDataLoader1D, and QREDataLoader.

Definition at line 22 of file AbstractDataLoader.cpp.

22 {}

Referenced by ImportDataUtils::Import1dData(), and SpecularDataImportWidget::onFormatSelectionChanged().

◆ lineUnrelatedErrors()

QStringList AutomaticDataLoader1D::lineUnrelatedErrors ( ) const
overridevirtual

Errors not related to a particular line.

Reimplemented from AbstractDataLoader.

Definition at line 119 of file AutomaticDataLoader1D.cpp.

120 {
121  if (!m_error.isEmpty())
122  return {m_error};
123 
124  return {};
125 }

References m_error.

◆ name()

QString AutomaticDataLoader1D::name ( ) const
overridevirtual

The name shown in the format selection combo.

Implements AbstractDataLoader.

Definition at line 25 of file AutomaticDataLoader1D.cpp.

26 {
27  return "Legacy from BornAgain 1.18";
28 }

◆ numErrors()

int AutomaticDataLoader1D::numErrors ( ) const
overridevirtual

Number of errors found while processing the content.

An error means that either a particular content (line) can't be used or may be suspicious (line related error), or that the whole content can't be used (e.g. only 1 line present).

Reimplemented from AbstractDataLoader.

Definition at line 114 of file AutomaticDataLoader1D.cpp.

115 {
116  return m_error.isEmpty() ? 0 : 1;
117 }

References m_error.

◆ numLineRelatedErrors()

int AbstractDataLoader::numLineRelatedErrors ( ) const
virtualinherited

Number of errors related to a specific line.

Such an error means that a particular content (line) can't be used or may be suspicious.

Reimplemented in QREDataLoader.

Definition at line 45 of file AbstractDataLoader.cpp.

46 {
47  return 0;
48 }

◆ persistentClassName()

QString AutomaticDataLoader1D::persistentClassName ( ) const
overridevirtual

A name which can be used for save/load purposes (which will not change ever more)

Implements AbstractDataLoader.

Definition at line 30 of file AutomaticDataLoader1D.cpp.

31 {
32  return "AutomaticDataLoader1D";
33 }

◆ populateImportSettingsWidget()

void AbstractDataLoader::populateImportSettingsWidget ( QWidget *  parent)
virtualinherited

Fills the widget on the import dialog pane.

This base class' implementation does nothing (meaning "no editable properties")

Reimplemented in UserDefinedDataLoader1D, and QREDataLoader.

Definition at line 18 of file AbstractDataLoader.cpp.

18 {}

Referenced by UserDefinedDataLoader1D::populateImportSettingsWidget(), and SpecularDataImportWidget::updatePropertiesEdits().

◆ processContents()

void AutomaticDataLoader1D::processContents ( )
overridevirtual

Process the file contents.

Can be called more than once, e.g. if the import settings have changed. Any error has to be stored in the loader (see numErrors()).

Implements AbstractDataLoader.

Definition at line 86 of file AutomaticDataLoader1D.cpp.

87 {
88  ASSERT(m_item != nullptr);
90 
91  try {
92  std::stringstream str(m_fileContent.constData());
93  auto oData = OutputDataReadReflectometry().readOutputData(str);
94 
95  ImportDataInfo importInfo(std::move(*oData), Axes::Units::QSPACE);
96  m_item->setImportData(std::move(importInfo));
97  m_error.clear();
98  } catch (std::runtime_error& ex) {
101  m_error = QString::fromStdString(ex.what());
102  if (m_error.isEmpty())
103  m_error = "Unspecified error";
104  }
105 
106  emit contentsProcessed();
107 }
#define ASSERT(condition)
Definition: Assert.h:31
void contentsProcessed()
Emitted whenever contents have been processed.
Carries information about loaded data.
Class for reading reflectometry data from ASCII file.
OutputData< double > * readOutputData(std::istream &input_stream)
void removeNativeData()
void setImportData(ImportDataInfo data)
Sets imported data to underlying item.
bool isSpecularData() const
SpecularDataItem * specularDataItem()
void setOutputData(OutputData< double > *data) override
The given pointer becomes owned by this class!!

References ASSERT, AbstractDataLoader::contentsProcessed(), RealDataItem::isSpecularData(), m_error, m_fileContent, AbstractDataLoader::m_item, OutputDataReadReflectometry::readOutputData(), RealDataItem::removeNativeData(), RealDataItem::setImportData(), SpecularDataItem::setOutputData(), and RealDataItem::specularDataItem().

Here is the call graph for this function:

◆ realDataItem() [1/2]

RealDataItem * AbstractDataLoader::realDataItem ( )
inherited

The real data item on which the import shall work.

Definition at line 70 of file AbstractDataLoader.cpp.

71 {
72  return m_item;
73 }

References AbstractDataLoader::m_item.

◆ realDataItem() [2/2]

const RealDataItem * AbstractDataLoader::realDataItem ( ) const
inherited

The real data item on which the import shall work.

Definition at line 75 of file AbstractDataLoader.cpp.

76 {
77  return m_item;
78 }

References AbstractDataLoader::m_item.

◆ serialize()

QByteArray AutomaticDataLoader1D::serialize ( ) const
overridevirtual

Returns every internal setting so it can be restored completely.

Reimplemented from AbstractDataLoader.

Definition at line 42 of file AutomaticDataLoader1D.cpp.

43 {
44  QByteArray a;
45  QDataStream s(&a, QIODevice::WriteOnly);
46  s.setVersion(QDataStream::Qt_5_12);
47 
48  s << (quint8)1; // version
49  s << m_fileContent;
50  s << m_error;
51 
52  return a;
53 }

References m_error, and m_fileContent.

Referenced by clone().

◆ setFileContents()

void AutomaticDataLoader1D::setFileContents ( const QByteArray &  fileContent)
overridevirtual

Sets the file contents to be imported.

If the file was a compressed file, here already the decompressed content will be overhanded.

Implements AbstractDataLoader.

Definition at line 76 of file AutomaticDataLoader1D.cpp.

77 {
79 }
virtual QByteArray fileContent() const override
Returns the original file content.

References fileContent(), and m_fileContent.

Here is the call graph for this function:

◆ setRealDataItem()

void AbstractDataLoader::setRealDataItem ( RealDataItem item)
inherited

Define the real data item on which the import shall work.

Definition at line 65 of file AbstractDataLoader.cpp.

66 {
67  m_item = item;
68 }

References AbstractDataLoader::m_item.

Referenced by ImportDataUtils::Import1dData(), and SpecularDataImportWidget::onFormatSelectionChanged().

Member Data Documentation

◆ m_error

QString AutomaticDataLoader1D::m_error
private

◆ m_fileContent

QByteArray AutomaticDataLoader1D::m_fileContent
private

◆ m_item


The documentation for this class was generated from the following files: