BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
integereditor.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/integereditor.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 
16 #include <QSpinBox>
17 #include <QVBoxLayout>
18 #include <cmath>
19 #include <stdexcept>
20 
21 namespace {
22 const int max_val = 65536;
23 const int min_val = -max_val;
24 } // namespace
25 
26 using namespace ModelView;
27 
28 IntegerEditor::IntegerEditor(QWidget* parent) : CustomEditor(parent), m_intEditor(new QSpinBox)
29 {
30  setAutoFillBackground(true);
31  m_intEditor->setFocusPolicy(Qt::StrongFocus);
32  m_intEditor->setKeyboardTracking(false);
33  m_intEditor->setRange(min_val, max_val);
34 
35  auto layout = new QVBoxLayout;
36  layout->setMargin(0);
37  layout->setSpacing(0);
38 
39  layout->addWidget(m_intEditor);
40 
41  connect(m_intEditor, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
42  [=] { this->onEditingFinished(); });
43 
44  setLayout(layout);
45 
46  setFocusProxy(m_intEditor);
47 }
48 
49 void IntegerEditor::setRange(int minimum, int maximum)
50 {
51  m_intEditor->setRange(minimum, maximum);
52 }
53 
55 {
56  int new_value = m_intEditor->value();
57  if (new_value != m_data.value<int>())
58  setDataIntern(QVariant::fromValue(new_value));
59 }
60 
62 {
63  if (m_data.type() != QVariant::Int)
64  throw std::runtime_error("IntegerEditor::update_components() -> Error. Wrong variant type");
65 
66  m_intEditor->setValue(m_data.value<int>());
67 }
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 update_components() override
Should update widget components from m_data, if necessary.
IntegerEditor(QWidget *parent=nullptr)
void setRange(int minimum, int maximum)
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.