BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
booleditor.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/booleditor.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 <QCheckBox>
17 #include <QHBoxLayout>
18 #include <stdexcept>
19 
20 namespace {
21 const QString true_text = "True";
22 const QString false_text = "False";
23 } // namespace
24 
25 using namespace ModelView;
26 
27 BoolEditor::BoolEditor(QWidget* parent) : CustomEditor(parent), m_checkBox(new QCheckBox)
28 
29 {
30  setAutoFillBackground(true);
31  auto layout = new QHBoxLayout;
32  layout->setContentsMargins(4, 0, 0, 0);
33  layout->addWidget(m_checkBox);
34  setLayout(layout);
35 
36  connect(m_checkBox, &QCheckBox::toggled, this, &BoolEditor::onCheckBoxChange);
37  setFocusProxy(m_checkBox);
38  m_checkBox->setText(true_text);
39 }
40 
42 {
43  return true;
44 }
45 
47 {
48  if (value != m_data.value<bool>())
49  setDataIntern(QVariant(value));
50 }
51 
53 {
54  if (m_data.type() != QVariant::Bool)
55  throw std::runtime_error("BoolEditor::update_components() -> Error. Wrong variant type");
56 
57  bool value = m_data.value<bool>();
58  m_checkBox->blockSignals(true);
59  m_checkBox->setChecked(value);
60  m_checkBox->setText(value ? true_text : false_text);
61  m_checkBox->blockSignals(false);
62 }
Defines class CLASS?
BoolEditor(QWidget *parent=nullptr)
Definition: booleditor.cpp:27
void update_components() override
Should update widget components from m_data, if necessary.
Definition: booleditor.cpp:52
QCheckBox * m_checkBox
Definition: booleditor.h:39
void onCheckBoxChange(bool value)
Definition: booleditor.cpp:46
bool is_persistent() const override
Returns true if editor should remains alive after editing finished.
Definition: booleditor.cpp:41
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.
materialitems.h Collection of materials to populate MaterialModel.