BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DoubleSpinBox.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Common/DoubleSpinBox.h
6 //! @brief Defines class DoubleSpinBox
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_VIEW_COMMON_DOUBLESPINBOX_H
16 #define BORNAGAIN_GUI_VIEW_COMMON_DOUBLESPINBOX_H
17 
19 #include <QDoubleSpinBox>
20 
21 //! SpinBox for DoubleDescriptors, supporting units.
22 class DoubleSpinBox : public QDoubleSpinBox {
23  Q_OBJECT
24 public:
25  //! Create a DoubleSpinBox with the information found in a DoubleDescriptor.
26  //!
27  //! The spin box will be fully initialized (tooltip, limits, unit, current value, size policy).
28  //! Furthermore, the spin box will prohibit accidental changes by the mouse wheel. Otherwise it
29  //! would be dangerous if the spin box is on a scrollable form - unintended and unnoticed
30  //! changes would take place when just scrolling through the form.
31  DoubleSpinBox(QWidget* parent, const DoubleDescriptor& d);
32 
33  //! Set a display unit.
34  //!
35  //! The caller has to make sure that the new display unit has a conversion to/from the contained
36  //! base value unit.
37  void setDisplayUnit(Unit displayUnit);
38 
39  //! Set the base value (unit is the one of the contained descriptor).
40  void setBaseValue(double baseValue);
41 
42  //! The display unit as human readable string.
43  QString displayUnitAsString() const;
44 
45  //! The descriptor on which this spinbox operates.
46  const DoubleDescriptor& valueDescriptor() const;
47 
48  //! Returns the unit of the contained DoubleDescriptor.
49  //!
50  //! If the unit is defined as a string, this method returns Unit::other. To get the string, use
51  //! valueDescriptor().unit
52  Unit baseUnit() const;
53 
54  //! Update the shown value to the one contained in the value descriptor.
55  //!
56  //! No signal will be emitted if the new value has changed.
57  void updateValue();
58 
59 signals:
60  //! Emitted whenever the value changes.
61  //!
62  //! newBaseValue is in the unit of the valueDescriptor.
63  void baseValueChanged(double newBaseValue);
64 
65 protected:
66  void wheelEvent(QWheelEvent* event) override;
67 
68 private:
69  void onDisplayValueChanged(double newDisplayValue);
70 
71  double toDisplayValue(double baseValue) const;
72  double toBaseValue(double displayValue) const;
73 
74  using QDoubleSpinBox::setValue; // To hide from usage
75 
76 private:
78 
80 
81  //! it was decided to not show the unit as a suffix. However, this may be user
82  //! selectable once, therefore the code is kept and controlled by this flag
83  bool m_showUnitAsSuffix = false;
84 };
85 
86 
87 #endif // BORNAGAIN_GUI_VIEW_COMMON_DOUBLESPINBOX_H
Defines class DoubleDescriptor.
Unit
Defines units, mainly to be able to convert between units.
Definition: Unit.h:26
@ unitless
Describes properties of a double value which are necessary to allow GUI representation,...
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
Unit baseUnit() const
Returns the unit of the contained DoubleDescriptor.
DoubleDescriptor m_valueDescriptor
Definition: DoubleSpinBox.h:79
double toBaseValue(double displayValue) const
void updateValue()
Update the shown value to the one contained in the value descriptor.
void wheelEvent(QWheelEvent *event) override
const DoubleDescriptor & valueDescriptor() const
The descriptor on which this spinbox operates.
void setDisplayUnit(Unit displayUnit)
Set a display unit.
void setBaseValue(double baseValue)
Set the base value (unit is the one of the contained descriptor).
bool m_showUnitAsSuffix
it was decided to not show the unit as a suffix. However, this may be user selectable once,...
Definition: DoubleSpinBox.h:83
DoubleSpinBox(QWidget *parent, const DoubleDescriptor &d)
Create a DoubleSpinBox with the information found in a DoubleDescriptor.
QString displayUnitAsString() const
The display unit as human readable string.
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
void onDisplayValueChanged(double newDisplayValue)
double toDisplayValue(double baseValue) const