BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
VectorItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/VectorItem.cpp
6 //! @brief Implements class VectorItem
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 
16 
17 const QString VectorItem::P_X = "X";
18 const QString VectorItem::P_Y = "Y";
19 const QString VectorItem::P_Z = "Z";
20 
22 {
23  addProperty(P_X, 0.0)->setLimits(RealLimits::limitless()).setToolTip("x-coordinate");
24  addProperty(P_Y, 0.0)->setLimits(RealLimits::limitless()).setToolTip("y-coordinate");
25  addProperty(P_Z, 0.0)->setLimits(RealLimits::limitless()).setToolTip("z-coordinate");
26 
27  mapper()->setOnPropertyChange([this](const QString&) { updateLabel(); });
28 
29  updateLabel();
30  setEditable(false);
31 }
32 
33 double VectorItem::x() const
34 {
35  return getItemValue(P_X).toDouble();
36 }
37 
38 void VectorItem::setX(double value)
39 {
41 }
42 
43 double VectorItem::y() const
44 {
45  return getItemValue(P_Y).toDouble();
46 }
47 
48 void VectorItem::setY(double value)
49 {
51 }
52 
53 double VectorItem::z() const
54 {
55  return getItemValue(P_Z).toDouble();
56 }
57 
58 void VectorItem::setZ(double value)
59 {
61 }
62 
63 void VectorItem::setXYZ(double x_value, double y_value, double z_value)
64 {
65  setX(x_value);
66  setY(y_value);
67  setZ(z_value);
68 }
69 
71 {
72  return kvector_t(x(), y(), z());
73 }
74 
76 {
77  setXYZ(vec.x(), vec.y(), vec.z());
78 }
79 
81 {
82  QString label = QString("(%1, %2, %3)").arg(x()).arg(y()).arg(z());
83 
84  setValue(label);
85 }
Defines class VectorItem.
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:67
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:65
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:63
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=0)
Definition: ModelMapper.cpp:35
static RealLimits limitless()
Creates an object withoud bounds (default)
Definition: RealLimits.cpp:130
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag.
QVariant value() const
Get value.
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.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
void setEditable(bool enabled)
SessionItem & setToolTip(const QString &tooltip)
SessionItem & setLimits(const RealLimits &value)
void setXYZ(double x_value, double y_value, double z_value)
Definition: VectorItem.cpp:63
void setY(double value)
Definition: VectorItem.cpp:48
static const QString P_Z
Definition: VectorItem.h:26
void setZ(double value)
Definition: VectorItem.cpp:58
void updateLabel()
Definition: VectorItem.cpp:80
double y() const
Definition: VectorItem.cpp:43
double z() const
Definition: VectorItem.cpp:53
static const QString P_Y
Definition: VectorItem.h:25
kvector_t getVector() const
Definition: VectorItem.cpp:70
void setX(double value)
Definition: VectorItem.cpp:38
double x() const
Definition: VectorItem.cpp:33
void setVector(const kvector_t &vec)
Definition: VectorItem.cpp:75
static const QString P_X
Definition: VectorItem.h:24