BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParameterTreeItems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ParameterTreeItems.cpp
6 //! @brief Implements 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 
19 
20 // ----------------------------------------------------------------------------
21 
23 {
24  const QString T_CHILDREN = "children tag";
25  registerTag(T_CHILDREN, 0, -1,
26  QStringList() << "Parameter Label"
27  << "Parameter");
28  setDefaultTag(T_CHILDREN);
29 }
30 
31 const QString ParameterItem::P_LINK = "Link";
32 const QString ParameterItem::P_BACKUP = "Backup";
33 const QString ParameterItem::P_DOMAIN = "Domain";
35 {
36  // Link to original PropertyItem in one of components of MultiLayerItem or InstrumentItem
37  addProperty(P_LINK, "");
38  // The back up value of PropertyItem to be able to reset parameter tuning tree to initial state
39  addProperty(P_BACKUP, 0.0);
40  // The domain name of corresponding ISampleNode's registered parameter
41  addProperty(P_DOMAIN, "");
42 }
43 
44 // ----------------------------------------------------------------------------
45 
46 //! Sets current value to the original PropertyItem of MultiLayerItem/InstrumentItem.
47 
49 {
50  setValue(newValue);
51 
52  if (SessionItem* item = linkedItem())
53  item->setValue(newValue);
54 }
55 
56 //! Returns corresponding linked item in MultiLayerItem/IsntrumentItem
57 
59 {
60  const SessionItem* jobItem = ModelPath::ancestor(this, "JobItem");
61  ASSERT(jobItem);
62  QString link = jobItem->itemName() + "/" + getItemValue(P_LINK).toString();
64 }
65 
66 //! Restore the value from backup and propagate it to the linked item.
67 
69 {
70  double newValue = getItemValue(P_BACKUP).toDouble();
71  propagateValueToLink(newValue);
72 }
73 
74 // ----------------------------------------------------------------------------
75 
77 {
78  const QString T_CHILDREN = "children tag";
79  registerTag(T_CHILDREN, 0, -1, QStringList() << "Parameter Label");
80  setDefaultTag(T_CHILDREN);
81 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines class FitParameterHelper.
Defines ModelPath namespace.
Defines classes for ParameterTreeItems.
Defines class SessionModel.
SessionItem * linkedItem()
Returns corresponding linked item in MultiLayerItem/IsntrumentItem.
static const QString P_DOMAIN
static const QString P_LINK
void propagateValueToLink(double newValue)
Sets current value to the original PropertyItem of MultiLayerItem/InstrumentItem.
void restoreFromBackup()
Restore the value from backup and propagate it to the linked item.
static const QString P_BACKUP
QString itemName() const
Get item name, return display name if no name is set.
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag.
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types.
bool setValue(QVariant value)
Set value, ensure that variant types match.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
void setDefaultTag(const QString &tag)
Set default tag.
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:66
T * item(const QString &tag) const
Definition: SessionItem.h:151
SessionItem * itemForIndex(const QModelIndex &index) const
QModelIndex getIndexFromPath(const SessionModel *model, const QString &path)
Definition: ModelPath.cpp:36
const SessionItem * ancestor(const SessionItem *item, const QString &requiredModelType)
Returns ancestor of given modelType for given item.
Definition: ModelPath.cpp:87