BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
data1ditem.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/standarditems/data1ditem.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_DATA1DITEM_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_DATA1DITEM_H
17 
20 #include <vector>
21 
22 namespace ModelView {
23 
24 class BinnedAxisItem;
25 
26 //! Represents one-dimensional data (axis and values).
27 //! Values are stored in Data1DItem itself, axis is attached as a child. Corresponding plot
28 //! properties will be served by GraphItem.
29 
30 class MVVM_MODEL_EXPORT Data1DItem : public CompoundItem {
31 public:
32  static inline const std::string P_VALUES = "P_VALUES";
33  static inline const std::string P_ERRORS = "P_ERRORS";
34  static inline const std::string T_AXIS = "T_AXIS";
35 
36  Data1DItem();
37 
38  // void setAxis(std::unique_ptr<BinnedAxisItem> axis);
39 
40  std::vector<double> binCenters() const;
41 
42  void setValues(const std::vector<double>& data);
43  std::vector<double> binValues() const;
44 
45  void setErrors(const std::vector<double>& errors);
46  std::vector<double> binErrors() const;
47 
48  //! Inserts axis of given type.
49  template <typename T, typename... Args> T* setAxis(Args&&... args);
50 };
51 
52 // FIXME Consider redesign of the method below. Should the axis exist from the beginning
53 // or added later? It is not clear how to create axis a) via Data1DItem::setAxis
54 // b) via model directly c) in constructor?
55 
56 template <typename T, typename... Args> T* Data1DItem::setAxis(Args&&... args)
57 {
58  // we disable possibility to re-create axis to facilitate undo/redo
59  if (getItem(T_AXIS, 0))
60  throw std::runtime_error("Axis was already set. Currently we do not support axis change");
61 
62  T* result{nullptr};
63  if (model()) {
64  // acting through the model to enable undo/redo
65  result = model()->insertItem<T>(this);
66  } else {
67  result = new T;
68  insertItem(result, {T_AXIS, 0});
69  }
70  result->setParameters(std::forward<Args>(args)...);
71  setValues(std::vector<double>(result->size(), 0.0));
72  return result;
73 }
74 
75 } // namespace ModelView
76 
77 #endif // BORNAGAIN_MVVM_MODEL_MVVM_STANDARDITEMS_DATA1DITEM_H
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
Represents one-dimensional data (axis and values).
Definition: data1ditem.h:30
static const std::string T_AXIS
Definition: data1ditem.h:34
void setValues(const std::vector< double > &data)
Sets internal data buffer to given data.
Definition: data1ditem.cpp:66
T * setAxis(Args &&... args)
Inserts axis of given type.
Definition: data1ditem.h:56
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
SessionModel * model() const
Returns the model to which given item belongs to.
bool insertItem(SessionItem *item, const TagRow &tagrow)
Insert item into given tag under the given row.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
std::vector< double > binValues(const QCPGraph *graph)
Returns vector representing y-values on QCPgraph.
std::vector< double > binErrors(const QCPGraph *graph)
Returns vector representing bin errors of QCPGraph.
std::vector< double > binCenters(const QCPGraph *graph)
Returns vector representing bin centers on QCPgraph.
Defines class CLASS?