BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
EditUtil.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Tool/EditUtil.cpp
6 //! @brief Implements GUIHelpers functions
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 #include "GUI/View/Tool/EditUtil.h"
16 #include "Fit/Param/RealLimits.h"
17 #include <QDoubleSpinBox>
18 #include <QLineEdit>
19 #include <cmath>
20 
21 namespace {
22 
23 //! Single step for QDoubleSpinBox.
24 double singleStep(int decimals)
25 {
26  // For item with decimals=3 (i.e. 0.001) single step will be 0.1
27  return 1. / std::pow(10., decimals - 1);
28 }
29 
30 } // namespace
31 
32 
33 void GUI::View::EditUtil::configScientificDoubleEdit(QLineEdit* edit, const RealLimits& limits)
34 {
35  auto* validator = new QDoubleValidator(0.0, 1e+200, 1000, edit);
36  validator->setNotation(QDoubleValidator::ScientificNotation);
37 
38  const double minimum =
39  limits.hasLowerLimit() ? std::max(limits.lowerLimit(), -1e+200) : -1e+200;
40  const double maximum =
41  limits.hasUpperLimit() ? std::min(limits.upperLimit(), +1e+200) : +1e+200;
42  validator->setRange(minimum, maximum, 1000);
43 
44  edit->setValidator(validator);
45 }
46 
47 void GUI::View::EditUtil::configSpinbox(QDoubleSpinBox* spinBox, int decimals,
48  const RealLimits& limits)
49 {
50  spinBox->setMaximum(std::numeric_limits<double>::max());
51  spinBox->setMinimum(std::numeric_limits<double>::lowest());
52 
53  if (limits.hasLowerLimit())
54  spinBox->setMinimum(limits.lowerLimit());
55  if (limits.hasUpperLimit())
56  spinBox->setMaximum(limits.upperLimit());
57 
58  spinBox->setDecimals(decimals);
59  spinBox->setSingleStep(singleStep(decimals));
60 }
Defines class GUIHelpers functions.
void configSpinbox(QDoubleSpinBox *spinBox, int decimals, const RealLimits &limits)
Definition: EditUtil.cpp:47
void configScientificDoubleEdit(QLineEdit *edit, const RealLimits &limits)
Definition: EditUtil.cpp:33