BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
sampleitems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/model/sampleitems.cpp
6 //! @brief Implements 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 Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "gui2/model/sampleitems.h"
21 #include <QVariant>
22 
23 namespace gui2 {
24 
26 {
27  addProperty(P_SIGMA, 0.0)->setDisplayName("Sigma");
28  addProperty(P_HURST, 0.5)->setDisplayName("Hurst");
29  addProperty(P_LATERAL_CORR_LENGTH, 0.0)->setDisplayName("Correlation length");
30 }
31 
32 //! ---------------------------------------------------------------------------
33 
35 {
36  addProperty(P_NAME, "Unnamed")->setDisplayName("Name");
37  addProperty(P_MATERIAL, ModelView::ExternalProperty::undefined())->setDisplayName("Material");
39  ->setDisplayName("Thickness")
40  ->setToolTip("Layer thickness in [nm]");
41  addProperty<RoughnessItem>(P_ROUGHNESS);
42 }
43 
44 //! ---------------------------------------------------------------------------
45 
47 {
48  addProperty(P_NAME, "Unnamed")->setDisplayName("Name");
49  addProperty(P_NREPETITIONS, 1)->setDisplayName("Nr.");
50  std::vector<std::string> allowed_child = {Constants::MultiLayerItemType,
52  registerTag(ModelView::TagInfo::universalTag(T_LAYERS, allowed_child), /*set_default*/ true);
53 
55 }
56 
58 {
59  auto on_item_inserted = [this](ModelView::SessionItem*, ModelView::TagRow) {
61  };
62  mapper()->setOnItemInserted(on_item_inserted, this);
63 
64  auto on_item_removed = [this](ModelView::SessionItem*, ModelView::TagRow) {
66  };
67  mapper()->setOnItemRemoved(on_item_removed, this);
68 }
69 
70 //! Sets thickness property of top and bottom layers to disabled state.
71 //! Reset thickness of top and bottom layer to 0.
72 
74 {
75  // FIXME restore correct enabling/disabling of thickness and roughness of top and bottom layers
76  // FIXME together with tests in layeritems.test.cpp
77  if (parent() != model()->rootItem())
78  return;
79 
80  auto layers = items<LayerItem>(T_LAYERS);
81  for (auto it = layers.begin(); it != layers.end(); ++it) {
82  if (it == layers.begin()) {
83  (*it)->getItem(LayerItem::P_THICKNESS)->setEnabled(false);
84  (*it)
85  ->getItem(LayerItem::P_ROUGHNESS)
86  ->getItem(RoughnessItem::P_SIGMA)
87  ->setEnabled(false);
88  (*it)->setProperty(LayerItem::P_THICKNESS, 0.0);
89  } else if (std::next(it) == layers.end()) {
90  (*it)->getItem(LayerItem::P_THICKNESS)->setEnabled(false);
91  (*it)->setProperty(LayerItem::P_THICKNESS, 0.0);
92  } else {
93  (*it)->getItem(LayerItem::P_THICKNESS)->setEnabled(true);
94  }
95  }
96 }
97 
98 } // namespace gui2
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
T * addProperty(const std::string &name)
Adds property item of given type.
Definition: compounditem.h:43
static ExternalProperty undefined()
void setOnItemRemoved(Callbacks::item_tagrow_t f, Callbacks::slot_t owner) override
Sets callback to be notified on child removal.
Definition: itemmapper.cpp:204
void setOnItemInserted(Callbacks::item_tagrow_t f, Callbacks::slot_t owner) override
Sets callback to be notified on child insertion.
Definition: itemmapper.cpp:199
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
SessionItem * parent() const
Returns parent item. Will return nullptr if item doesn't have a parent.
SessionModel * model() const
Returns the model to which given item belongs to.
ItemMapper * mapper()
Returns item mapper. Allows subscribing to various events happening to the item.
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
Definition: taginfo.cpp:34
Aggregate to hold (tag, row) information for SessionModel.
Definition: tagrow.h:25
static const std::string P_MATERIAL
Definition: sampleitems.h:42
static const std::string P_THICKNESS
Definition: sampleitems.h:43
static const std::string P_NAME
Definition: sampleitems.h:41
static const std::string P_ROUGHNESS
Definition: sampleitems.h:44
static const std::string P_NAME
Definition: sampleitems.h:53
void update_layer_appearance()
Sets thickness property of top and bottom layers to disabled state.
Definition: sampleitems.cpp:73
void activate() override
Definition: sampleitems.cpp:57
static const std::string T_LAYERS
Definition: sampleitems.h:54
static const std::string P_NREPETITIONS
Definition: sampleitems.h:55
static const std::string P_HURST
Definition: sampleitems.h:31
static const std::string P_SIGMA
Definition: sampleitems.h:30
static const std::string P_LATERAL_CORR_LENGTH
Definition: sampleitems.h:32
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
const std::string MultiLayerItemType
const std::string RoughnessItemType
const std::string LayerItemType
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?