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

Description

The legacy importer for reflectometry, with no user interaction.

Definition at line 23 of file AutomaticDataLoader1D.h.

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...
 
AbstractDataLoaderclone () const override
 Create a complete clone, including all internal states. More...
 
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. This base class' implementation does nothing (return nullptr). More...
 
virtual QByteArray defaultImportSettings () const
 Return the default import settings. More...
 
void deserialize (const QByteArray &data) override
 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. More...
 
QByteArray fileContent () const override
 Returns the original file content. If not available any more (like for legacy project file import), then an empty array will be returned. More...
 
virtual void guessSettings ()
 Guess appropriate settings (for example the separator in a CSV file). Is called only once, directly after setting the file content. More...
 
virtual void initWithDefaultImportSettings ()
 Set import settings to defaults. More...
 
QStringList lineUnrelatedErrors () const override
 Errors not related to a particular line. More...
 
QString name () const override
 The name shown in the format selection combo. More...
 
int numErrors () const override
 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). More...
 
virtual int numLineRelatedErrors () const
 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. More...
 
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. The implementation here in the base class does nothing (meaning "no editable properties"). More...
 
void processContents () override
 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()). 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...
 
QByteArray serialize () const override
 Returns every internal setting so it can be restored completely. More...
 
void setFileContents (const QByteArray &fileContent) override
 Sets the file contents to be imported. If the file was a compressed file, then the decompressed content will be handed over already here. More...
 
void setRealDataItem (RealDataItem *item)
 Define the real data item on which the import shall work. More...
 

Protected Attributes

RealDataItemm_item
 The real-data-item which owns this loader. Never delete this! More...
 

Private Attributes

QString m_error
 
QByteArray m_fileContent
 

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 cloneAsUserDefinedLoader(), and SpecularDataImportWidget::onPropertiesChanged().

◆ clone()

AbstractDataLoader * AutomaticDataLoader1D::clone ( ) const
overridevirtual

Create a complete clone, including all internal states.

Implements AbstractDataLoader.

Definition at line 33 of file AutomaticDataLoader1D.cpp.

34 {
35  auto* loader = new AutomaticDataLoader1D();
36  loader->deserialize(serialize());
37  return loader;
38 }
The legacy importer for reflectometry, with no user interaction.
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 107 of file AutomaticDataLoader1D.cpp.

108 {
110 }
RealDataItem * m_item
The real-data-item which owns this loader. Never delete this!
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 53 of file AutomaticDataLoader1D.cpp.

54 {
55  m_fileContent.clear();
56  m_error.clear();
57 
58  QDataStream s(data);
59  s.setVersion(QDataStream::Qt_5_12);
60 
61  quint8 version;
62  s >> version;
63 
64  if (version == 1) {
65  s >> m_fileContent;
66  s >> m_error;
67  } else
69 
70  if (s.status() != QDataStream::Ok)
72 }
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 79 of file AutomaticDataLoader1D.cpp.

80 {
81  return m_fileContent;
82 }

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(), GUI::View::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 GUI::View::ImportDataUtils::Import1dData(), and SpecularDataImportWidget::onFormatSelectionChanged().

◆ lineUnrelatedErrors()

QStringList AutomaticDataLoader1D::lineUnrelatedErrors ( ) const
overridevirtual

Errors not related to a particular line.

Reimplemented from AbstractDataLoader.

Definition at line 117 of file AutomaticDataLoader1D.cpp.

118 {
119  if (!m_error.isEmpty())
120  return {m_error};
121 
122  return {};
123 }

References m_error.

◆ name()

QString AutomaticDataLoader1D::name ( ) const
overridevirtual

The name shown in the format selection combo.

Implements AbstractDataLoader.

Definition at line 23 of file AutomaticDataLoader1D.cpp.

24 {
25  return "Legacy from BornAgain 1.18";
26 }

◆ 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 112 of file AutomaticDataLoader1D.cpp.

113 {
114  return m_error.isEmpty() ? 0 : 1;
115 }

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 28 of file AutomaticDataLoader1D.cpp.

29 {
30  return "AutomaticDataLoader1D";
31 }

◆ populateImportSettingsWidget()

void AbstractDataLoader::populateImportSettingsWidget ( QWidget *  parent)
virtualinherited

Fills the widget on the import dialog pane. The implementation here in the base class 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 84 of file AutomaticDataLoader1D.cpp.

85 {
86  ASSERT(m_item != nullptr);
87  ASSERT(m_item->isSpecularData());
88 
89  try {
90  std::stringstream str(m_fileContent.constData());
91  auto* oData = ReadReflectometry().readDatafield(str);
92 
93  ImportDataInfo importInfo(std::move(*oData), Coords::QSPACE);
94  m_item->setImportData(std::move(importInfo));
95  m_error.clear();
96  } catch (std::runtime_error& ex) {
99  m_error = QString::fromStdString(ex.what());
100  if (m_error.isEmpty())
101  m_error = "Unspecified error";
102  }
103 
104  emit contentsProcessed();
105 }
void contentsProcessed()
Emitted whenever contents have been processed.
Carries information about loaded data.
void removeNativeData()
bool isSpecularData() const
void setImportData(ImportDataInfo info)
Sets imported data to underlying item. Creates it if not existing. This is used for 1D import....
SpecularDataItem * specularDataItem()
void setDatafield(Datafield *data) override
The given pointer becomes owned by this class!!

References AbstractDataLoader::contentsProcessed(), RealDataItem::isSpecularData(), m_error, m_fileContent, AbstractDataLoader::m_item, RealDataItem::removeNativeData(), SpecularDataItem::setDatafield(), RealDataItem::setImportData(), 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 40 of file AutomaticDataLoader1D.cpp.

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

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, then the decompressed content will be handed over already here.

Implements AbstractDataLoader.

Definition at line 74 of file AutomaticDataLoader1D.cpp.

75 {
77 }
QByteArray fileContent() const override
Returns the original file content. If not available any more (like for legacy project file import),...

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 GUI::View::ImportDataUtils::Import1dData(), and SpecularDataImportWidget::onFormatSelectionChanged().

Member Data Documentation

◆ m_error

QString AutomaticDataLoader1D::m_error
private

◆ m_fileContent

QByteArray AutomaticDataLoader1D::m_fileContent
private

◆ m_item

RealDataItem* AbstractDataLoader::m_item
protectedinherited

The real-data-item which owns this loader. Never delete this!

Definition at line 124 of file AbstractDataLoader.h.

Referenced by createResultModel(), processContents(), QREDataLoader::processContents(), AbstractDataLoader::realDataItem(), and AbstractDataLoader::setRealDataItem().


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