BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
materialitems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/model/materialitems.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 
18 #include "mvvm/model/itemutils.h"
19 #include <QColor>
20 
21 using namespace ModelView;
22 
23 namespace gui2 {
24 
25 MaterialContainerItem::MaterialContainerItem()
27 {
29  /*set_as_default*/ true);
30 }
31 
32 // ----------------------------------------------------------------------------
33 
36 {
37  addProperty(P_COLOR, QColor(Qt::green))->setDisplayName("Color");
38  addProperty(P_NAME, "Unnamed")->setDisplayName("Name");
39 }
40 
41 //! Returns ExternalProperty representing this material.
42 
44 {
45  QColor color = Utils::HasTag(*this, P_COLOR) ? property<QColor>(P_COLOR) : QColor(Qt::red);
46  std::string name = Utils::HasTag(*this, P_NAME) ? property<std::string>(P_NAME) : std::string();
48 }
49 
50 /*! Creates mag. field-related properties.
51  * Should be called from descendants' constructors in order
52  * to preserve view-oriented property sequence.
53  * The same can be achieved with a proper
54  * ModelView::RowStrategyInterface::constructRow
55  * implementation.
56  */
58 {
59  addProperty(P_H_X, 0.0)->setDisplayName("H, x");
60  addProperty(P_H_Y, 0.0)->setDisplayName("H, y");
61  addProperty(P_H_Z, 0.0)->setDisplayName("H, z");
62 }
63 
64 // ----------------------------------------------------------------------------
65 
67 {
68  addProperty(P_SLD_REAL, 1e-06)->setDisplayName("Re(SLD)")->setLimits(RealLimits::limitless());
69  addProperty(P_SLD_IMAG, 1e-08)->setDisplayName("Im(SLD)")->setLimits(RealLimits::limitless());
71 }
72 
73 void SLDMaterialItem::set_properties(const std::string& name, const QColor& color, double real,
74  double imag)
75 {
77  setProperty(P_COLOR, color);
78  setProperty(P_SLD_REAL, real);
79  setProperty(P_SLD_IMAG, imag);
80 }
81 
82 } // 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
Property to carry text, color and identifier.
static RealLimits limitless()
Creates an object withoud bounds (default)
Definition: reallimits.cpp:66
std::string identifier() const
Returns unique identifier.
Definition: sessionitem.cpp:87
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190
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
Base class with all materials with name and color defined.
Definition: materialitems.h:40
static const std::string P_COLOR
Definition: materialitems.h:42
ModelView::ExternalProperty external_property() const
Returns ExternalProperty representing this material.
static const std::string P_H_X
Definition: materialitems.h:44
static const std::string P_H_Z
Definition: materialitems.h:46
static const std::string P_NAME
Definition: materialitems.h:43
static const std::string P_H_Y
Definition: materialitems.h:45
MaterialBaseItem(const std::string &model_type)
static const std::string T_MATERIALS
Definition: materialitems.h:34
static const std::string P_SLD_REAL
Definition: materialitems.h:59
void set_properties(const std::string &name, const QColor &color, double real, double imag)
static const std::string P_SLD_IMAG
Definition: materialitems.h:60
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
MVVM_MODEL_EXPORT bool HasTag(const SessionItem &item, const std::string &tag)
Returns true if given item has registered tag.
Definition: itemutils.cpp:86
materialitems.h Collection of materials to populate MaterialModel.
std::string model_type
Definition: types.h:23
QString const & name(EShape k)
Definition: particles.cpp:21
const std::string MaterialContainerItemType
const std::string SLDMaterialItemType
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20