BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DataItem.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Data/DataItem.h
6 //! @brief Declares class DataItem
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_MODEL_DATA_DATAITEM_H
16 #define BORNAGAIN_GUI_MODEL_DATA_DATAITEM_H
17 
18 #include "Device/Data/Datafield.h"
22 #include <QDateTime>
23 #include <mutex>
24 
25 class ComboProperty;
26 class ImportDataInfo;
27 class InstrumentItem;
28 
29 //! Abstract base class for IntensityDataItem and SpecularDataItem.
30 //! Owns one simulated data set of type Datafield.
31 
32 //! For experimental data, use RealDataItem.
33 
34 class BA_CORE_API_ DataItem : public QObject, public SessionItem, public SaveLoadInterface {
35  Q_OBJECT
36 private:
37  static constexpr auto P_FILE_NAME{"FileName"};
38  static constexpr auto P_AXES_UNITS{"Axes Units"};
39 
40 public:
41  Datafield* getDatafield() { return m_data.get(); }
42  const Datafield* getDatafield() const { return m_data.get(); }
43 
44  //! The given pointer becomes owned by this class!!
45  virtual void setDatafield(Datafield* data) = 0;
46 
47  //! Sets the raw data vector from external source.
48  //! Checks only the equality of data size; no dimension checks are applied.
49  void setRawDataVector(const std::vector<double>& data);
50 
52  QString fileName() const override;
53  void setFileName(const QString& filename);
54  QDateTime lastModified() const override;
55  bool containsNonXMLData() const override;
56  bool loadData(const QString& projectDir) override;
57  bool saveData(const QString& projectDir) override;
58 
59  void setLastModified(const QDateTime& dtime);
60 
61  QString selectedCoords() const;
62 
63  void setAxesUnits(const ComboProperty& units);
64  SessionItem* getAxesUnitsItem() const;
65  SelectionDescriptor<QString> axesUnits() const;
66  static bool isAxesUnitsPropertyName(const QString& name);
67  static void updateAxesUnits(SessionItem* item, const QString& name,
68  InstrumentItem* instrumentItem);
69 
70  virtual void setXaxisTitle(const QString& title) = 0;
71  virtual void setYaxisTitle(const QString& title) = 0;
72  virtual void setAxesRangeToData() = 0;
73  virtual void updateCoords(const InstrumentItem* instrument) = 0;
74  virtual std::vector<int> shape() const = 0;
75 
76  //! Resets data to the state defined by user (imported) data.
77  virtual void reset(ImportDataInfo data) = 0;
78 
79 signals:
80  void datafieldChanged(Datafield* data);
81  void rawDataVectorChanged(const std::vector<double>& data);
82  void fileNameChanged(const QString& filename);
83  void axesUnitsChanged(const ComboProperty& units);
84 
85 protected:
86  explicit DataItem(const QString& modelType);
87 
88  std::unique_ptr<Datafield> m_data; //!< simulation results
89  QDateTime m_last_modified;
90  std::mutex m_update_data_mutex;
91 };
92 
93 #endif // BORNAGAIN_GUI_MODEL_DATA_DATAITEM_H
Defines save/load interface.
Defines class SelectionDescriptor.
Defines class SessionItem.
Custom property to define list of string values with multiple selections. Intended for QVariant.
Definition: ComboProperty.h:25
Abstract base class for IntensityDataItem and SpecularDataItem. Owns one simulated data set of type D...
Definition: DataItem.h:34
virtual void setAxesRangeToData()=0
const Datafield * getDatafield() const
Definition: DataItem.h:42
QDateTime m_last_modified
Definition: DataItem.h:89
virtual void setXaxisTitle(const QString &title)=0
void datafieldChanged(Datafield *data)
Datafield * getDatafield()
Definition: DataItem.h:41
virtual std::vector< int > shape() const =0
virtual void updateCoords(const InstrumentItem *instrument)=0
std::mutex m_update_data_mutex
Definition: DataItem.h:90
void rawDataVectorChanged(const std::vector< double > &data)
void fileNameChanged(const QString &filename)
void axesUnitsChanged(const ComboProperty &units)
std::unique_ptr< Datafield > m_data
simulation results
Definition: DataItem.h:88
virtual void setYaxisTitle(const QString &title)=0
virtual void reset(ImportDataInfo data)=0
Resets data to the state defined by user (imported) data.
Carries information about loaded data.
Abstract base class for instrument-specific item classes.
Abstract base class to handle non-XML data save and load.
virtual QString fileName() const =0
Reports file name to save/load non-XML data.
virtual bool containsNonXMLData() const =0
Checks if object owns non-XML data.
virtual bool loadData(const QString &projectDir)=0
Loads non-XML data from projectDir and returns success flag.
virtual QDateTime lastModified() const =0
Indicates last modification timepoint.
virtual bool saveData(const QString &projectDir)=0
Saves non-XML data in projectDir and returns success flag.
Describes a selection (various possibilities and the current one).
Base class for a GUI data item.
Definition: SessionItem.h:204
QString projectDir(const QString &projectFileName)
Returns project directory deduced from project file name.
QString const & name(EShape k)
Definition: particles.cpp:20