BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DoubleLineEdit.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Common/DoubleLineEdit.cpp
6 //! @brief Implements class DoubleLineEdit
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 
16 #include <QDoubleValidator>
17 
19  : QLineEdit(parent)
20  , m_valueDescriptor(d)
21 {
22  m_validator = new QDoubleValidator(0.0, 1e+200, 1000, this);
23  m_validator->setNotation(QDoubleValidator::ScientificNotation);
24  const double minimum =
25  d.limits.hasLowerLimit() ? std::max(d.limits.lowerLimit(), -1e+200) : -1e+200;
26  const double maximum =
27  d.limits.hasUpperLimit() ? std::min(d.limits.upperLimit(), +1e+200) : +1e+200;
28  m_validator->setRange(minimum, maximum, 1000);
29  setValidator(m_validator);
30 
32 
33  connect(this, &QLineEdit::editingFinished, this, &DoubleLineEdit::onEditingFinished);
34 }
35 
36 void DoubleLineEdit::setBaseValue(double baseValue)
37 {
38  setText(QString::number(baseValue, 'g'));
39 }
40 
42 {
43  return m_valueDescriptor;
44 }
45 
47 {
48  const double new_value = text().toDouble();
49  if (new_value != m_valueDescriptor.get())
50  emit baseValueChanged(new_value);
51 }
Defines class DoubleLineEdit.
Describes properties of a double value which are necessary to allow GUI representation,...
RealLimits limits
Limits of the value.
function< double()> get
function to get the current value
const DoubleDescriptor & valueDescriptor() const
The descriptor on which this line edit operates.
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
DoubleLineEdit(QWidget *parent, const DoubleDescriptor &d)
void setBaseValue(double baseValue)
Set the base value (unit is the one of the contained descriptor).
QDoubleValidator * m_validator
void onEditingFinished()
DoubleDescriptor m_valueDescriptor