BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DataLoaders1D.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/DataLoaders/DataLoaders1D.cpp
6 //! @brief Implements class DataLoaders1D
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 
19 
20 namespace {
21 
22 // the one and only instance of DataLoaders1D
23 DataLoaders1D dataLoaders1D;
24 
25 } // namespace
26 
28 
30 {
31  m_instance = this;
32 }
33 
35 {
36  qDeleteAll(m_builtInLoaders);
37  qDeleteAll(m_userDefinedLoaders);
38 }
39 
41 {
42  return *m_instance;
43 }
44 
46 {
47  // the ordering in here defines the ordering in the selection combo box in the open file dialog
48  // and also in the selection combo box on the format configuration page. Furthermore the first
49  // returned loader will be used as default in the open file dialog if it is started for the
50  // first time
53 }
54 
55 QVector<AbstractDataLoader*> DataLoaders1D::loaders() const
56 {
57  if (m_builtInLoaders.isEmpty())
58  const_cast<DataLoaders1D*>(this)->initBuiltInLoaders();
60 }
61 
62 QVector<AbstractDataLoader*> DataLoaders1D::recentlyUsedLoaders() const
63 {
64  return m_recentlyUsedLoaders;
65 }
66 
68 {
69  loader->applyImportSettings();
70  auto clonedLoader = dynamic_cast<AbstractDataLoader1D*>(loader->clone());
71  const auto defaultProperties = loader->serialize();
72 
73  m_userDefinedLoaders << new UserDefinedDataLoader1D(clonedLoader, name, defaultProperties);
74 }
75 
77 {
78  if (persistentClassName == AutomaticDataLoader1D().persistentClassName())
79  return new AutomaticDataLoader1D();
80 
81  if (persistentClassName == QREDataLoader().persistentClassName())
82  return new QREDataLoader();
83 
84  return nullptr;
85 }
Defines class AutomaticDataLoader1D.
Defines class DataLoaders1D.
Defines class QREDataLoader.
Defines class UserDefinedDataLoader1D.
Base class for data loaders for 1D import.
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 AbstractDataLoader * clone() const =0
Create a complete clone, including all internal states.
Implements the legacy importer from BornAgain with no user interaction.
Collection of all available data loaders for 1D files.
Definition: DataLoaders1D.h:25
QVector< AbstractDataLoader * > recentlyUsedLoaders() const
The last 10 recently used loaders.
void cloneAsUserDefinedLoader(AbstractDataLoader *loader, const QString &name)
Clone the loader and create a user defined loader with its current settings and the given name.
QVector< AbstractDataLoader * > m_userDefinedLoaders
Definition: DataLoaders1D.h:59
void initBuiltInLoaders()
create all default built in loaders
static DataLoaders1D & instance()
The one and only instance.
AbstractDataLoader1D * createFromPersistentName(const QString &persistentClassName)
Create loader from the given persistent name.
static DataLoaders1D * m_instance
Definition: DataLoaders1D.h:56
QVector< AbstractDataLoader * > m_recentlyUsedLoaders
Definition: DataLoaders1D.h:58
QVector< AbstractDataLoader * > m_builtInLoaders
Definition: DataLoaders1D.h:57
QVector< AbstractDataLoader * > loaders() const
all defined loaders.
Real data loader for Q/R/E reflectometry CSV files.
Definition: QREDataLoader.h:27
A user defined data loader.
QString const & name(EShape k)
Definition: particles.cpp:21