BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ParameterTreeItems.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Job/ParameterTreeItems.h
6 //! @brief Defines classes for ParameterTreeItems
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_JOB_PARAMETERTREEITEMS_H
16 #define BORNAGAIN_GUI_MODEL_JOB_PARAMETERTREEITEMS_H
17 
20 #include <QObject>
21 
22 //! ParameterTreeItems is a collection of items necessary to form a tuning tree for
23 //! real time widget.
24 
25 //! The ParameterLabelItem class represents a label (string without value, like 'Layer',
26 //! 'MultiLayer') in a parameter tuning tree.
27 
28 class ParameterLabelItem : public QObject {
29 public:
30  ParameterLabelItem(QObject* parent);
31  ParameterLabelItem(const QString& title, QObject* parent);
32 
33  QString title() const;
34  void setTitle(const QString& title);
35 
36 private:
37  QString m_title;
38 };
39 
40 //! The ParameterItem class represent a tuning value in a parameter tuning tree.
41 
42 class ParameterItem : public QObject {
43 public:
44  ParameterItem(QObject* parent);
45 
46  QString title() const;
47  void setTitle(const QString& title);
48 
49  double valueOfLink() const;
50  void propagateValueToLink(double newValue);
51 
52  //! Unique string to identify this ParameterItem.
53  //!
54  //! The link is arbitrary. It can't be used for finding the linked item (therefore it does
55  //! not have to be a model path). However, it is used for comparison, also across project
56  //! load/save. Therefore the link is always the same, not e.g. an always generated UUID.
57  //! This link is used for setting backup values and for finding this ParameterItem when
58  //! referring from fit parameters.
59  QString link() const;
60 
61  QString titleForFitItem() const;
62 
63  //! Links this item to the given value defined by a descriptor.
65 
66  //! Links this item to the given session item.
67  void linkToSessionItem(SessionItem* item);
68 
69  RealLimits limitsOfLink() const;
70  int decimalsOfLink() const;
71 
72 private:
73  QString m_title;
74  QString m_link; //!< See docu of link()
75  DoubleDescriptor m_d; //!< The linked double value
76 };
77 
78 //! The ParameterContainerItem is a top item to hold all ParameterItem, represents an entry
79 //! point to parameter tuning tree. Part of JobItem.
80 
82 public:
84 
85  void writeContentTo(QXmlStreamWriter* writer) const;
86  void readContentFrom(QXmlStreamReader* reader);
87 
88  void setBackupValue(const QString& link, double d);
89  void restoreBackupValues();
90 
91  ParameterItem* findParameterItem(const QString& link) const;
92 
93  QObject* parameterTreeRoot();
94 
95 private:
96  void restoreBackupValue(QObject* item);
97 
98  QMap<QString, double> m_backupValues;
99  std::unique_ptr<QObject> m_parameterTreeRoot;
100 };
101 
102 #endif // BORNAGAIN_GUI_MODEL_JOB_PARAMETERTREEITEMS_H
Defines class DoubleDescriptor.
Defines class SessionItem.
Describes properties of a double value which are necessary to allow GUI representation,...
The ParameterContainerItem is a top item to hold all ParameterItem, represents an entry point to para...
void setBackupValue(const QString &link, double d)
ParameterItem * findParameterItem(const QString &link) const
std::unique_ptr< QObject > m_parameterTreeRoot
QMap< QString, double > m_backupValues
void restoreBackupValue(QObject *item)
void readContentFrom(QXmlStreamReader *reader)
void writeContentTo(QXmlStreamWriter *writer) const
The ParameterItem class represent a tuning value in a parameter tuning tree.
QString titleForFitItem() const
void linkToSessionItem(SessionItem *item)
Links this item to the given session item.
double valueOfLink() const
void propagateValueToLink(double newValue)
Sets current value to the original PropertyItem of MultiLayerItem/InstrumentItem.
QString m_link
See docu of link()
int decimalsOfLink() const
ParameterItem(QObject *parent)
QString link() const
Unique string to identify this ParameterItem.
RealLimits limitsOfLink() const
QString title() const
void setTitle(const QString &title)
void linkToDescriptor(DoubleDescriptor d)
Links this item to the given value defined by a descriptor.
DoubleDescriptor m_d
The linked double value.
ParameterTreeItems is a collection of items necessary to form a tuning tree for real time widget.
ParameterLabelItem(QObject *parent)
void setTitle(const QString &title)
Base class for a GUI data item.
Definition: SessionItem.h:204