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 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/viewmodel/mvvm/editors/scientificspinbox.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_VIEWMODEL_MVVM_EDITORS_SCIENTIFICSPINBOX_H
16 #define BORNAGAIN_MVVM_VIEWMODEL_MVVM_EDITORS_SCIENTIFICSPINBOX_H
17 
18 #include "mvvm/viewmodel_export.h"
19 #include <QAbstractSpinBox>
20 
21 namespace ModelView {
22 
23 class MVVM_VIEWMODEL_EXPORT ScientificSpinBox : public QAbstractSpinBox {
24  Q_OBJECT
25  Q_PROPERTY(double value MEMBER m_value READ value WRITE setValue NOTIFY valueChanged USER true)
26 
27 public:
28  ScientificSpinBox(QWidget* parent = nullptr);
29  ~ScientificSpinBox() override;
30 
31  double value() const;
32  void setValue(double val);
33 
34  double singleStep() const;
35  void setSingleStep(double step);
36 
37  double minimum() const;
38  void setMinimum(double min);
39 
40  double maximum() const;
41  void setMaximum(double max);
42 
43  void setDecimals(int);
44  int decimals() const;
45 
46  void stepBy(int steps) override;
47  QValidator::State validate(QString&, int&) const override { return QValidator::Acceptable; }
48  void fixup(QString&) const override {}
49 
50  static QString toString(double val, int decimal_points);
51  static double toDouble(QString text, const QDoubleValidator& validator, double min, double max,
52  double default_value);
53  static double round(double val, int decimals);
54 
55 signals:
56  void valueChanged(double value);
57 
58 protected:
59  QAbstractSpinBox::StepEnabled stepEnabled() const override;
60 
61 private:
62  void updateValue();
63  void updateText();
64  bool inRange(double val) const;
65 
66  double m_value, m_min, m_max;
67  double m_step;
69  QDoubleValidator m_validator;
70 };
71 
72 } // namespace ModelView
73 
74 #endif // BORNAGAIN_MVVM_VIEWMODEL_MVVM_EDITORS_SCIENTIFICSPINBOX_H
QValidator::State validate(QString &, int &) const override
void fixup(QString &) const override
void valueChanged(double value)
materialitems.h Collection of materials to populate MaterialModel.
std::string toString(PyObject *obj)
Converts PyObject into string, if possible, or throws exception.
Definition: PyUtils.cpp:24