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

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

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

 ScientificDoubleEditor (QWidget *parent=nullptr)
 
QVariant data () const
 
virtual bool is_persistent () const
 Returns true if editor should remains alive after editing finished. More...
 
void setRange (double minimum, double 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

QLineEdit * m_lineEdit
 
QDoubleValidator * m_validator {nullptr}
 

Detailed Description

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

Definition at line 27 of file scientificdoubleeditor.h.

Constructor & Destructor Documentation

◆ ScientificDoubleEditor()

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

Definition at line 28 of file scientificdoubleeditor.cpp.

29  : CustomEditor(parent), m_lineEdit(new QLineEdit)
30 
31 {
32  setAutoFillBackground(true);
33 
34  auto layout = new QVBoxLayout;
35  layout->setMargin(0);
36  layout->setSpacing(0);
37 
38  layout->addWidget(m_lineEdit);
39 
40  m_validator = new QDoubleValidator(0.0, std::numeric_limits<double>::max(), max_digits, this);
41  m_validator->setNotation(QDoubleValidator::ScientificNotation);
42  m_lineEdit->setValidator(m_validator);
43 
44  connect(m_lineEdit, &QLineEdit::editingFinished, this,
46 
47  setLayout(layout);
48 }
CustomEditor(QWidget *parent=nullptr)

References m_lineEdit, m_validator, 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 ScientificDoubleEditor::onEditingFinished ( )
privateslot

Definition at line 55 of file scientificdoubleeditor.cpp.

56 {
57  double new_value = m_lineEdit->text().toDouble();
58 
59  if (!Utils::AreAlmostEqual(new_value, m_data.value<double>()))
60  setDataIntern(QVariant::fromValue(new_value));
61 }
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_lineEdit, and ModelView::CustomEditor::setDataIntern().

Referenced by ScientificDoubleEditor().

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

Here is the call graph for this function:

◆ setRange()

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

Definition at line 50 of file scientificdoubleeditor.cpp.

51 {
52  m_validator->setRange(minimum, maximum, max_digits);
53 }

References m_validator.

◆ update_components()

void ScientificDoubleEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 63 of file scientificdoubleeditor.cpp.

64 {
65  if (m_data.type() != QVariant::Double)
66  throw std::runtime_error(
67  "ScientificDoubleEditor::update_components() -> Error. Wrong variant type");
68 
69  m_lineEdit->setText(QString::number(m_data.value<double>(), 'g'));
70 }

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

Member Data Documentation

◆ m_data

◆ m_lineEdit

QLineEdit* ModelView::ScientificDoubleEditor::m_lineEdit
private

◆ m_validator

QDoubleValidator* ModelView::ScientificDoubleEditor::m_validator {nullptr}
private

Definition at line 41 of file scientificdoubleeditor.h.

Referenced by ScientificDoubleEditor(), and setRange().

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

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