BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
AxisProperty.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/AxisProperty.h
6 //! @brief Defines class AxisProperty
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2022
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_AXISPROPERTY_H
16 #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_AXISPROPERTY_H
17 
18 #include "Base/Axis/FixedBinAxis.h"
21 #include <memory>
22 
23 class Streamer;
24 
25 //! Holds values which can be used to describe a FixedBinAxis.
26 //!
27 //! Use this as a member in your class to
28 //! * reduce dependency to axis items and axis classes
29 //! * simplify serialization
30 //! * easily have a UI supporting solution.
31 //!
32 //! This class is designed to work seamlessly with the serialization methods; just call it's
33 //! serialize for both reading and writing.
34 //! For UI integration just use AxisPropertyEditor.
35 //!
36 //! Do not forget to call all three init functions from within the containing class's constructor!
37 
38 class AxisProperty {
39 public:
40  UINT_PROPERTY(nbins, Nbins);
41  DOUBLE_PROPERTY(min, Min);
42  DOUBLE_PROPERTY(max, Max);
43 
44  void initNbins(const QString& label, const QString& tooltip, uint n = 100,
45  const variant<QString, Unit>& unit = "nbins");
46 
47  void initMin(const QString& label, const QString& tooltip, double value,
48  const variant<QString, Unit>& unit,
49  const RealLimits& limits = RealLimits::nonnegative(), uint decimals = 3);
50  void initMax(const QString& label, const QString& tooltip, double value,
51  const variant<QString, Unit>& unit,
52  const RealLimits& limits = RealLimits::nonnegative(), uint decimals = 3);
53 
54  void serialize(Streamer& s);
55 
56  //! Creates an axis with empty title
57  std::unique_ptr<FixedBinAxis> createAxis(double scaleFactor) const;
58 
59  void rwAxisProperty(Streamer& s, const QString& tag);
60 };
61 
62 //! Add a member and a getter for an axis property
63 #define AXIS_PROPERTY(nameLower) \
64 protected: \
65  AxisProperty m_##nameLower; \
66  \
67 public: \
68  AxisProperty& nameLower() const { return *const_cast<AxisProperty*>(&m_##nameLower); }
69 
70 #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_AXISPROPERTY_H
Defines class DoubleProperty.
Defines class UIntProperty.
Holds values which can be used to describe a FixedBinAxis.
Definition: AxisProperty.h:38
void rwAxisProperty(Streamer &s, const QString &tag)
DOUBLE_PROPERTY(min, Min)
void serialize(Streamer &s)
UINT_PROPERTY(nbins, Nbins)
void initNbins(const QString &label, const QString &tooltip, uint n=100, const variant< QString, Unit > &unit="nbins")
DOUBLE_PROPERTY(max, Max)
void initMin(const QString &label, const QString &tooltip, double value, const variant< QString, Unit > &unit, const RealLimits &limits=RealLimits::nonnegative(), uint decimals=3)
std::unique_ptr< FixedBinAxis > createAxis(double scaleFactor) const
Creates an axis with empty title.
void initMax(const QString &label, const QString &tooltip, double value, const variant< QString, Unit > &unit, const RealLimits &limits=RealLimits::nonnegative(), uint decimals=3)
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36