BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
scientificspinboxeditor.cpp
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/scientificspinboxeditor.cpp
6 //! @brief Implements 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 
18 #include <QVBoxLayout>
19 #include <stdexcept>
20 
21 using namespace ModelView;
22 
24  : CustomEditor(parent), m_doubleEditor(new ScientificSpinBox)
25 {
26  setAutoFillBackground(true);
27  setFocusPolicy(Qt::StrongFocus);
28  m_doubleEditor->setFocusPolicy(Qt::StrongFocus);
29  m_doubleEditor->setKeyboardTracking(false);
30 
31  auto layout = new QVBoxLayout;
32  layout->setMargin(0);
33  layout->setSpacing(0);
34 
35  layout->addWidget(m_doubleEditor);
36 
38 
39  setLayout(layout);
40 
41  setFocusProxy(m_doubleEditor);
42 }
43 
44 void ScientificSpinBoxEditor::setRange(double minimum, double maximum)
45 {
46  m_doubleEditor->setMinimum(minimum);
47  m_doubleEditor->setMaximum(maximum);
48 }
49 
51 {
52  m_doubleEditor->setDecimals(decimals);
53 }
54 
56 {
58 }
59 
61 {
62  return true;
63 }
64 
66 {
67  double new_value = m_doubleEditor->value();
68 
69  if (!Utils::AreAlmostEqual(new_value, m_data.value<double>()))
70  setDataIntern(QVariant::fromValue(new_value));
71 }
72 
74 {
75  if (m_data.type() != QVariant::Double)
76  throw std::runtime_error(
77  "ScientificSpinBoxEditor::update_components() -> Error. Wrong variant type");
78 
79  m_doubleEditor->setValue(m_data.value<double>());
80 }
Base class for all custom variant editors.
Definition: customeditor.h:26
void setDataIntern(const QVariant &data)
Saves the data as given by editor's internal components and notifies the model.
void setRange(double minimum, double maximum)
bool is_persistent() const override
Returns true if editor should remains alive after editing finished.
ScientificSpinBoxEditor(QWidget *parent=nullptr)
void update_components() override
Should update widget components from m_data, if necessary.
void valueChanged(double value)
MVVM_MODEL_EXPORT bool AreAlmostEqual(double a, double b, double tolerance_factor=1.0)
Returns true if two doubles agree within epsilon*tolerance.
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?