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

Custom editor for QVariant based on integer with possibility to set limits. More...

Inheritance diagram for ModelView::IntegerEditor:
[legend]
Collaboration diagram for ModelView::IntegerEditor:
[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

 IntegerEditor (QWidget *parent=nullptr)
 
QVariant data () const
 
virtual bool is_persistent () const
 Returns true if editor should remains alive after editing finished. More...
 
void setRange (int minimum, int maximum)
 

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 onEditingFinished ()
 

Private Member Functions

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

Private Attributes

QSpinBox * m_intEditor
 

Detailed Description

Custom editor for QVariant based on integer with possibility to set limits.

Definition at line 26 of file integereditor.h.

Constructor & Destructor Documentation

◆ IntegerEditor()

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

Definition at line 28 of file integereditor.cpp.

28  : 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 }
CustomEditor(QWidget *parent=nullptr)

References m_intEditor, and onEditingFinished().

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 CustomEditor::is_persistent ( ) const
virtualinherited

Returns true if editor should remains alive after editing finished.

Reimplemented in ModelView::SelectableComboBoxEditor, ModelView::ScientificSpinBoxEditor, ModelView::ComboPropertyEditor, and ModelView::BoolEditor.

Definition at line 28 of file customeditor.cpp.

29 {
30  return false;
31 }

◆ onEditingFinished

void IntegerEditor::onEditingFinished ( )
privateslot

Definition at line 54 of file integereditor.cpp.

55 {
56  int new_value = m_intEditor->value();
57  if (new_value != m_data.value<int>())
58  setDataIntern(QVariant::fromValue(new_value));
59 }
void setDataIntern(const QVariant &data)
Saves the data as given by editor's internal components and notifies the model.

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

Referenced by IntegerEditor().

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(), ModelView::BoolEditor::onCheckBoxChange(), ModelView::DoubleEditor::onEditingFinished(), 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:

◆ setRange()

void IntegerEditor::setRange ( int  minimum,
int  maximum 
)

Definition at line 49 of file integereditor.cpp.

50 {
51  m_intEditor->setRange(minimum, maximum);
52 }

References m_intEditor.

◆ update_components()

void IntegerEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 61 of file integereditor.cpp.

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 }

References ModelView::CustomEditor::m_data, and m_intEditor.

Member Data Documentation

◆ m_data

◆ m_intEditor

QSpinBox* ModelView::IntegerEditor::m_intEditor
private

Definition at line 39 of file integereditor.h.

Referenced by IntegerEditor(), onEditingFinished(), setRange(), and update_components().

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

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