BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
toyitems.cpp
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/tests/libtestmachinery/toyitems.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 Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "toyitems.h"
17 #include "mvvm/model/taginfo.h"
20 #include <QColor>
21 #include <stdexcept>
22 
23 using namespace ToyItems;
24 
26 {
28  /*set_as_default*/ true);
29 }
30 
32 {
33  addProperty(P_THICKNESS, 42.0);
34  addProperty(P_COLOR, QColor(Qt::green));
36  /*set_as_default*/ true);
37 }
38 
39 // ----------------------------------------------------------------------------
40 
42 {
43  addProperty<ModelView::VectorItem>(P_POSITION);
44  addProperty<ShapeGroupItem>(P_SHAPES);
45 }
46 
47 // ----------------------------------------------------------------------------
48 
50 {
53 
54  auto combo = ModelView::ComboProperty::createFrom({"Default", "Square", "Hexagonal"});
56 
58 }
59 
61 {
62  auto onIntegrationFlagChange = [this](SessionItem*, std::string property) {
63  if (property == P_INTEGRATION)
65  };
66  mapper()->setOnPropertyChange(onIntegrationFlagChange, this);
67 }
68 
70 {
71  auto angle_item = getItem(P_ROTATION_ANLE);
72  angle_item->setEnabled(!property<bool>(P_INTEGRATION));
73 }
74 
75 // ----------------------------------------------------------------------------
76 
78 {
79  addProperty(P_RADIUS, 8.0);
80  addProperty(P_HEIGHT, 10.0);
81 }
82 
83 // ----------------------------------------------------------------------------
84 
86 {
87  addProperty(P_RADIUS, 8.0);
88 }
89 
90 // ----------------------------------------------------------------------------
91 
93 {
94  addProperty(P_LENGTH, 8.0);
95  addProperty(P_WIDTH, 8.0);
96  addProperty(P_HEIGHT, 8.0);
97  addProperty(P_ALPHA, 8.0);
98 }
99 
101 {
102  registerItem<CylinderItem>("Cylinder");
103  registerItem<SphereItem>("Full sphere", /*make_selected*/ true);
104  registerItem<AnysoPyramidItem>("Anysotropical pyramid");
105  init_group();
106 }
static ComboProperty createFrom(const std::vector< std::string > &values, const std::string &current_value={})
T * addProperty(const std::string &name)
Adds property item of given type.
Definition: compounditem.h:43
void init_group()
Inits group item by creating all registered items and constructing combo property for switching betwe...
Definition: groupitem.cpp:84
void setOnPropertyChange(Callbacks::item_str_t f, Callbacks::slot_t owner) override
Sets callback to be notified on item's property change.
Definition: itemmapper.cpp:189
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
ItemMapper * mapper()
Returns item mapper. Allows subscribing to various events happening to the item.
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
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
static const std::string P_HEIGHT
Definition: toyitems.h:111
static const std::string P_LENGTH
Definition: toyitems.h:109
static const std::string P_ALPHA
Definition: toyitems.h:112
static const std::string P_WIDTH
Definition: toyitems.h:110
static const std::string P_HEIGHT
Definition: toyitems.h:91
static const std::string P_RADIUS
Definition: toyitems.h:90
static const std::string P_ROTATION_ANLE
Definition: toyitems.h:74
void activate() override
Definition: toyitems.cpp:60
static const std::string P_LATTICE_TYPE
Definition: toyitems.h:76
static const std::string P_INTEGRATION
Definition: toyitems.h:75
static const std::string T_PARTICLES
Definition: toyitems.h:56
static const std::string P_COLOR
Definition: toyitems.h:55
static const std::string P_THICKNESS
Definition: toyitems.h:54
static const std::string T_LAYERS
Definition: toyitems.h:46
static const std::string P_SHAPES
Definition: toyitems.h:65
static const std::string P_POSITION
Definition: toyitems.h:64
static const std::string P_RADIUS
Definition: toyitems.h:100
Defines class CLASS?
Defines class CLASS?
const ModelView::model_type LayerItemType
Definition: toyitems.h:31
const ModelView::model_type SphereItemType
Definition: toyitems.h:36
const ModelView::model_type CylinderItemType
Definition: toyitems.h:35
const ModelView::model_type LatticeItemType
Definition: toyitems.h:33
const ModelView::model_type ShapeGroupItemType
Definition: toyitems.h:39
const ModelView::model_type ParticleItemType
Definition: toyitems.h:32
const ModelView::model_type AnysoPyramidItemType
Definition: toyitems.h:37
Collection of toy items and models for testing purposes.
Definition: toyitems.h:26
const std::string MultiLayerItemType
const std::string LayerItemType
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?