BornAgain  1.19.0
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/coregui/Views/JobWidgets/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_COREGUI_VIEWS_JOBWIDGETS_SCIENTIFICSPINBOX_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_JOBWIDGETS_SCIENTIFICSPINBOX_H
17 
18 #include <QAbstractSpinBox>
19 
20 class ScientificSpinBox : public QAbstractSpinBox {
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  double value() const;
29  void setValue(double val);
30 
31  double singleStep() const;
32  void setSingleStep(double step);
33 
34  double minimum() const;
35  void setMinimum(double min);
36 
37  double maximum() const;
38  void setMaximum(double max);
39 
40  void setDecimals(int);
41  int decimals() const;
42 
43  void stepBy(int steps) override;
44  QValidator::State validate(QString&, int&) const override { return QValidator::Acceptable; }
45  void fixup(QString&) const override {}
46 
47  static QString toString(double val, int decimal_points);
48  static double toDouble(QString text, const QDoubleValidator& validator, double min, double max,
49  double default_value);
50  static double round(double val, int decimals);
51 
52 signals:
53  void valueChanged(double value);
54 
55 protected:
56  QAbstractSpinBox::StepEnabled stepEnabled() const override;
57 
58 private:
59  void updateValue();
60  void updateText();
61  bool inRange(double val) const;
62 
63  double m_value, m_min, m_max;
64  double m_step;
66  QDoubleValidator m_validator;
67 };
68 
69 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_JOBWIDGETS_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)
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