BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::BoolEditor Class Reference

Custom editor for QVariant based on bool values. More...

Inheritance diagram for ModelView::BoolEditor:
[legend]
Collaboration diagram for ModelView::BoolEditor:
[legend]

Public Slots

void setData (const QVariant &data)
 Sets the data from model to editor. More...
 

Signals

void dataChanged (QVariant value)
 Emmits signal when data was changed in an editor. More...
 

Public Member Functions

 BoolEditor (QWidget *parent=nullptr)
 
QVariant data () const
 
bool is_persistent () const override
 Returns true if editor should remains alive after editing finished. More...
 

Protected Member Functions

void setDataIntern (const QVariant &data)
 Saves the data as given by editor's internal components and notifies the model. More...
 

Protected Attributes

QVariant m_data
 

Properties

QVariant value
 

Private Slots

void onCheckBoxChange (bool value)
 

Private Member Functions

void update_components () override
 Should update widget components from m_data, if necessary. More...
 

Private Attributes

QCheckBox * m_checkBox
 

Detailed Description

Custom editor for QVariant based on bool values.

Definition at line 26 of file booleditor.h.

Constructor & Destructor Documentation

◆ BoolEditor()

BoolEditor::BoolEditor ( QWidget *  parent = nullptr)
explicit

Definition at line 27 of file booleditor.cpp.

27  : 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 }
QCheckBox * m_checkBox
Definition: booleditor.h:39
void onCheckBoxChange(bool value)
Definition: booleditor.cpp:46
CustomEditor(QWidget *parent=nullptr)

References m_checkBox, and onCheckBoxChange().

Here is the call graph for this function:

Member Function Documentation

◆ data()

QVariant CustomEditor::data ( ) const
inherited

Definition at line 21 of file customeditor.cpp.

22 {
23  return m_data;
24 }

References ModelView::CustomEditor::m_data.

Referenced by ModelView::CustomEditor::setData(), and ModelView::CustomEditor::setDataIntern().

◆ dataChanged

void ModelView::CustomEditor::dataChanged ( QVariant  value)
signalinherited

◆ is_persistent()

bool BoolEditor::is_persistent ( ) const
overridevirtual

Returns true if editor should remains alive after editing finished.

Reimplemented from ModelView::CustomEditor.

Definition at line 41 of file booleditor.cpp.

42 {
43  return true;
44 }

◆ onCheckBoxChange

void BoolEditor::onCheckBoxChange ( bool  value)
privateslot

Definition at line 46 of file booleditor.cpp.

47 {
48  if (value != m_data.value<bool>())
49  setDataIntern(QVariant(value));
50 }
void setDataIntern(const QVariant &data)
Saves the data as given by editor's internal components and notifies the model.

References ModelView::CustomEditor::m_data, ModelView::CustomEditor::setDataIntern(), and ModelView::CustomEditor::value.

Referenced by BoolEditor().

Here is the call graph for this function:

◆ setData

void CustomEditor::setData ( const QVariant &  data)
slotinherited

Sets the data from model to editor.

Definition at line 35 of file customeditor.cpp.

36 {
37  m_data = data;
39 }
QVariant data() const
virtual void update_components()=0
Should update widget components from m_data, if necessary.

References ModelView::CustomEditor::data(), ModelView::CustomEditor::m_data, and ModelView::CustomEditor::update_components().

Here is the call graph for this function:

◆ setDataIntern()

void CustomEditor::setDataIntern ( const QVariant &  data)
protectedinherited

Saves the data as given by editor's internal components and notifies the model.

Definition at line 43 of file customeditor.cpp.

44 {
45  m_data = data;
47 }
void dataChanged(QVariant value)
Emmits signal when data was changed in an editor.

References ModelView::CustomEditor::data(), ModelView::CustomEditor::dataChanged(), and ModelView::CustomEditor::m_data.

Referenced by ModelView::ColorEditor::mousePressEvent(), onCheckBoxChange(), ModelView::DoubleEditor::onEditingFinished(), ModelView::IntegerEditor::onEditingFinished(), ModelView::ScientificDoubleEditor::onEditingFinished(), ModelView::ScientificSpinBoxEditor::onEditingFinished(), ModelView::ComboPropertyEditor::onIndexChanged(), ModelView::ExternalPropertyComboEditor::onIndexChanged(), and ModelView::SelectableComboBoxEditor::onModelDataChanged().

Here is the call graph for this function:

◆ update_components()

void BoolEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 52 of file booleditor.cpp.

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 }

References m_checkBox, ModelView::CustomEditor::m_data, and ModelView::CustomEditor::value.

Member Data Documentation

◆ m_checkBox

QCheckBox* ModelView::BoolEditor::m_checkBox
private

Definition at line 39 of file booleditor.h.

Referenced by BoolEditor(), and update_components().

◆ m_data

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

The documentation for this class was generated from the following files: