File: VectorProperty.h

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (70 lines) | stat: -rw-r--r-- 2,383 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/Model/Descriptor/VectorProperty.h
//! @brief     Defines class VectorProperty.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORPROPERTY_H
#define BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORPROPERTY_H

#include "GUI/Model/Descriptor/DoubleProperty.h"
#include <heinz/Vectors3D.h>

//! Holds a 3D vector of type R3 as well as additional info like label, tooltip.
//!
//! Use this as a member in your class to hold a 3D vector if you want to have support for
//! serialization, and if this vector is editable on the UI.
//!
//! For a more complete documentation about property classes, please refer to DoubleProperty.
//!
//! \sa DoubleProperty
//!
class VectorProperty {
public:
    void init(const QString& label, const QString& units, const QString& tooltip,
              const QString& uidPrefix);
    void init(const QString& label, const QString& units, const QString& tooltip, const R3& value,
              uint decimals, bool useFixedStep, double step, const RealLimits& limits,
              const QString& uidPrefix);

    operator R3() const { return R3(m_x.dVal(), m_y.dVal(), m_z.dVal()); }
    bool operator==(const VectorProperty& other) const;

    void setX(double _x) { m_x.setDVal(_x); }
    void setY(double _y) { m_y.setDVal(_y); }
    void setZ(double _z) { m_z.setDVal(_z); }
    void setR3(const R3& d)
    {
        setX(d.x());
        setY(d.y());
        setZ(d.z());
    }
    R3 r3() const { return *this; }

    QString label() const;

    DoubleProperty& x() { return m_x; }
    DoubleProperty& y() { return m_y; }
    DoubleProperty& z() { return m_z; }

    void writeTo(QXmlStreamWriter* w) const;
    void readFrom(QXmlStreamReader* r);

private:
    QString m_label;
    QString m_units;

    DoubleProperty m_x;
    DoubleProperty m_y;
    DoubleProperty m_z;
};

#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORPROPERTY_H