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

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

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

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

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

QDoubleSpinBox * m_doubleEditor
 

Detailed Description

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

Definition at line 26 of file doubleeditor.h.

Constructor & Destructor Documentation

◆ DoubleEditor()

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

Definition at line 23 of file doubleeditor.cpp.

24  : CustomEditor(parent), m_doubleEditor(new QDoubleSpinBox)
25 {
26  setFocusPolicy(Qt::StrongFocus);
27  m_doubleEditor->setFocusPolicy(Qt::StrongFocus);
28  m_doubleEditor->setKeyboardTracking(false);
29 
30  auto layout = new QVBoxLayout;
31  layout->setMargin(0);
32  layout->setSpacing(0);
33 
34  layout->addWidget(m_doubleEditor);
35 
36  connect(m_doubleEditor,
37  static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
38  [=] { this->onEditingFinished(); });
39 
40  setLayout(layout);
41 
42  setFocusProxy(m_doubleEditor);
43 }
CustomEditor(QWidget *parent=nullptr)
QDoubleSpinBox * m_doubleEditor
Definition: doubleeditor.h:43

References m_doubleEditor, 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 DoubleEditor::onEditingFinished ( )
privateslot

Definition at line 60 of file doubleeditor.cpp.

61 {
62  double new_value = m_doubleEditor->value();
63 
64  if (!Utils::AreAlmostEqual(new_value, m_data.value<double>()))
65  setDataIntern(QVariant::fromValue(new_value));
66 }
void setDataIntern(const QVariant &data)
Saves the data as given by editor's internal components and notifies the model.
MVVM_MODEL_EXPORT bool AreAlmostEqual(double a, double b, double tolerance_factor=1.0)
Returns true if two doubles agree within epsilon*tolerance.

References ModelView::Utils::AreAlmostEqual(), ModelView::CustomEditor::m_data, m_doubleEditor, and ModelView::CustomEditor::setDataIntern().

Referenced by DoubleEditor().

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(), 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:

◆ setDecimals()

void DoubleEditor::setDecimals ( int  decimals)

Definition at line 50 of file doubleeditor.cpp.

51 {
52  m_doubleEditor->setDecimals(decimals);
53 }

References m_doubleEditor.

◆ setRange()

void DoubleEditor::setRange ( double  minimum,
double  maximum 
)

Definition at line 45 of file doubleeditor.cpp.

46 {
47  m_doubleEditor->setRange(minimum, maximum);
48 }

References m_doubleEditor.

◆ setSingleStep()

void DoubleEditor::setSingleStep ( double  value)

Definition at line 55 of file doubleeditor.cpp.

56 {
57  m_doubleEditor->setSingleStep(value);
58 }

References m_doubleEditor, and ModelView::CustomEditor::value.

◆ update_components()

void DoubleEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 68 of file doubleeditor.cpp.

69 {
70  if (m_data.type() != QVariant::Double)
71  throw std::runtime_error("DoubleEditor::update_components() -> Error. Wrong variant type");
72 
73  m_doubleEditor->setValue(m_data.value<double>());
74 }

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

Member Data Documentation

◆ m_data

◆ m_doubleEditor

QDoubleSpinBox* ModelView::DoubleEditor::m_doubleEditor
private

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

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