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

Custom editor for QVariant based on double with scientific notation support. More...

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

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

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

ScientificSpinBoxm_doubleEditor
 

Detailed Description

Custom editor for QVariant based on double with scientific notation support.

Definition at line 26 of file scientificspinboxeditor.h.

Constructor & Destructor Documentation

◆ ScientificSpinBoxEditor()

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

Definition at line 23 of file scientificspinboxeditor.cpp.

25 {
26  setAutoFillBackground(true);
27  setFocusPolicy(Qt::StrongFocus);
28  m_doubleEditor->setFocusPolicy(Qt::StrongFocus);
29  m_doubleEditor->setKeyboardTracking(false);
30 
31  auto layout = new QVBoxLayout;
32  layout->setMargin(0);
33  layout->setSpacing(0);
34 
35  layout->addWidget(m_doubleEditor);
36 
38 
39  setLayout(layout);
40 
41  setFocusProxy(m_doubleEditor);
42 }
CustomEditor(QWidget *parent=nullptr)
void valueChanged(double value)

References m_doubleEditor, onEditingFinished(), and ModelView::ScientificSpinBox::valueChanged().

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 ScientificSpinBoxEditor::is_persistent ( ) const
overridevirtual

Returns true if editor should remains alive after editing finished.

Reimplemented from ModelView::CustomEditor.

Definition at line 60 of file scientificspinboxeditor.cpp.

61 {
62  return true;
63 }

◆ onEditingFinished

void ScientificSpinBoxEditor::onEditingFinished ( )
privateslot

Definition at line 65 of file scientificspinboxeditor.cpp.

66 {
67  double new_value = m_doubleEditor->value();
68 
69  if (!Utils::AreAlmostEqual(new_value, m_data.value<double>()))
70  setDataIntern(QVariant::fromValue(new_value));
71 }
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, ModelView::CustomEditor::setDataIntern(), and ModelView::ScientificSpinBox::value.

Referenced by ScientificSpinBoxEditor().

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(), ModelView::IntegerEditor::onEditingFinished(), ModelView::ScientificDoubleEditor::onEditingFinished(), onEditingFinished(), ModelView::ComboPropertyEditor::onIndexChanged(), ModelView::ExternalPropertyComboEditor::onIndexChanged(), and ModelView::SelectableComboBoxEditor::onModelDataChanged().

Here is the call graph for this function:

◆ setDecimals()

void ScientificSpinBoxEditor::setDecimals ( int  decimals)

Definition at line 50 of file scientificspinboxeditor.cpp.

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

References m_doubleEditor, and ModelView::ScientificSpinBox::setDecimals().

Here is the call graph for this function:

◆ setRange()

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

Definition at line 44 of file scientificspinboxeditor.cpp.

45 {
46  m_doubleEditor->setMinimum(minimum);
47  m_doubleEditor->setMaximum(maximum);
48 }

References m_doubleEditor, ModelView::ScientificSpinBox::setMaximum(), and ModelView::ScientificSpinBox::setMinimum().

Here is the call graph for this function:

◆ setSingleStep()

void ScientificSpinBoxEditor::setSingleStep ( double  step)

Definition at line 55 of file scientificspinboxeditor.cpp.

56 {
58 }

References m_doubleEditor, and ModelView::ScientificSpinBox::setSingleStep().

Here is the call graph for this function:

◆ update_components()

void ScientificSpinBoxEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 73 of file scientificspinboxeditor.cpp.

74 {
75  if (m_data.type() != QVariant::Double)
76  throw std::runtime_error(
77  "ScientificSpinBoxEditor::update_components() -> Error. Wrong variant type");
78 
79  m_doubleEditor->setValue(m_data.value<double>());
80 }

References ModelView::CustomEditor::m_data, m_doubleEditor, and ModelView::ScientificSpinBox::setValue().

Here is the call graph for this function:

Member Data Documentation

◆ m_data

◆ m_doubleEditor

ScientificSpinBox* ModelView::ScientificSpinBoxEditor::m_doubleEditor
private

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

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