BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ScientificSpinBox.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Common/ScientificSpinBox.h
6 //! @brief Defines class ScientificSpinBox
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 
15 #ifndef BORNAGAIN_GUI_VIEW_COMMON_SCIENTIFICSPINBOX_H
16 #define BORNAGAIN_GUI_VIEW_COMMON_SCIENTIFICSPINBOX_H
17 
18 #include <QDoubleSpinBox>
19 
20 class ScientificSpinBox : public QDoubleSpinBox {
21  Q_OBJECT
22 
23  Q_PROPERTY(double value MEMBER m_value READ value WRITE setValue NOTIFY valueChanged USER true)
24 public:
25  ScientificSpinBox(QWidget* parent = nullptr);
26  ~ScientificSpinBox() override;
27 
28  QSize sizeHint() const override;
29 
30  double value() const;
31  void setValue(double val);
32 
33  double singleStep() const;
34  void setSingleStep(double step);
35 
36  double minimum() const;
37  void setMinimum(double min);
38 
39  double maximum() const;
40  void setMaximum(double max);
41 
42  void setDecimals(int);
43  int decimals() const;
44 
45  void stepBy(int steps) override;
46  QValidator::State validate(QString&, int&) const override { return QValidator::Acceptable; }
47  void fixup(QString&) const override {}
48 
49  static QString toString(double val, int decimal_points);
50  static double toDouble(QString text, const QDoubleValidator& validator, double min, double max,
51  double default_value);
52  static double round(double val, int decimals);
53 
54 signals:
55  void valueChanged(double value);
56 
57 protected:
58  QAbstractSpinBox::StepEnabled stepEnabled() const override;
59 
60 private:
61  void updateValue();
62  void updateText();
63  bool inRange(double val) const;
64 
65  double m_value, m_min, m_max;
66  double m_step;
68  QDoubleValidator m_validator;
69 };
70 
71 #endif // BORNAGAIN_GUI_VIEW_COMMON_SCIENTIFICSPINBOX_H
double minimum() const
ScientificSpinBox(QWidget *parent=nullptr)
void stepBy(int steps) override
static double toDouble(QString text, const QDoubleValidator &validator, double min, double max, double default_value)
void fixup(QString &) const override
void setMaximum(double max)
QSize sizeHint() const override
void setMinimum(double min)
~ScientificSpinBox() override
QValidator::State validate(QString &, int &) const override
double maximum() const
void setValue(double val)
void setSingleStep(double step)
QDoubleValidator m_validator
static double round(double val, int decimals)
bool inRange(double val) const
QAbstractSpinBox::StepEnabled stepEnabled() const override
static QString toString(double val, int decimal_points)
void valueChanged(double value)
double singleStep() const