BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ScientificDoublePropertyEditor Class Reference

Editor for ScientificDoubleProperty variant. More...

Inheritance diagram for ScientificDoublePropertyEditor:
[legend]
Collaboration diagram for ScientificDoublePropertyEditor:
[legend]

Public Slots

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

Signals

void dataChanged (const QVariant &data)
 Signal emit then user changed the data through the editor. More...
 

Public Member Functions

 ScientificDoublePropertyEditor (QWidget *parent=nullptr)
 
QVariant editorData ()
 
void setLimits (const RealLimits &limits)
 

Protected Member Functions

void initEditor ()
 Inits editor widgets from m_data. More...
 
void setDataIntern (const QVariant &data)
 Saves the data from the editor and informs external delegates. More...
 

Protected Attributes

QVariant m_data
 

Private Slots

void onEditingFinished ()
 

Private Attributes

class QLineEdit * m_lineEdit
 
class QDoubleValidator * m_validator
 

Detailed Description

Editor for ScientificDoubleProperty variant.

Definition at line 95 of file CustomEditors.h.

Constructor & Destructor Documentation

◆ ScientificDoublePropertyEditor()

ScientificDoublePropertyEditor::ScientificDoublePropertyEditor ( QWidget *  parent = nullptr)

Definition at line 216 of file CustomEditors.cpp.

217  : CustomEditor(parent), m_lineEdit(new QLineEdit), m_validator(nullptr)
218 {
219  setAutoFillBackground(true);
220 
221  auto layout = new QVBoxLayout;
222  layout->setMargin(0);
223  layout->setSpacing(0);
224 
225  layout->addWidget(m_lineEdit);
226 
227  m_validator = new QDoubleValidator(0.0, 1e+200, 1000, this);
228  m_validator->setNotation(QDoubleValidator::ScientificNotation);
229  m_lineEdit->setValidator(m_validator);
230 
231  connect(m_lineEdit, &QLineEdit::editingFinished, this,
233 
234  setLayout(layout);
235 }
CustomEditor(QWidget *parent=nullptr)
Definition: CustomEditors.h:31
class QDoubleValidator * m_validator

References m_lineEdit, m_validator, and onEditingFinished().

Here is the call graph for this function:

Member Function Documentation

◆ dataChanged

void CustomEditor::dataChanged ( const QVariant &  data)
signalinherited

Signal emit then user changed the data through the editor.

Referenced by PropertyWidgetItem::connectEditor(), SessionModelDelegate::createEditor(), and CustomEditor::setDataIntern().

◆ editorData()

QVariant CustomEditor::editorData ( )
inlineinherited

Definition at line 33 of file CustomEditors.h.

33 { return m_data; }
QVariant m_data
Definition: CustomEditors.h:45

References CustomEditor::m_data.

◆ initEditor()

void ScientificDoublePropertyEditor::initEditor ( )
protectedvirtual

Inits editor widgets from m_data.

Reimplemented from CustomEditor.

Definition at line 252 of file CustomEditors.cpp.

253 {
254  ASSERT(m_data.type() == QVariant::Double);
255  m_lineEdit->setText(QString::number(m_data.toDouble(), 'g'));
256 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, CustomEditor::m_data, and m_lineEdit.

◆ onEditingFinished

void ScientificDoublePropertyEditor::onEditingFinished ( )
privateslot

Definition at line 244 of file CustomEditors.cpp.

245 {
246  double new_value = m_lineEdit->text().toDouble();
247 
248  if (new_value != m_data.toDouble())
249  setDataIntern(QVariant::fromValue(new_value));
250 }
void setDataIntern(const QVariant &data)
Saves the data from the editor and informs external delegates.

References CustomEditor::m_data, m_lineEdit, and CustomEditor::setDataIntern().

Referenced by ScientificDoublePropertyEditor().

Here is the call graph for this function:

◆ setData

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

Sets the data from the model to editor.

Definition at line 48 of file CustomEditors.cpp.

49 {
50  m_data = data;
51  initEditor();
52 }
virtual void initEditor()
Inits editor widgets from m_data.

References CustomEditor::initEditor(), and CustomEditor::m_data.

Here is the call graph for this function:

◆ setDataIntern()

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

Saves the data from the editor and informs external delegates.

Definition at line 60 of file CustomEditors.cpp.

61 {
62  m_data = data;
64 }
void dataChanged(const QVariant &data)
Signal emit then user changed the data through the editor.

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

Referenced by ExternalPropertyEditor::buttonClicked(), BoolEditor::onCheckBoxChange(), onEditingFinished(), DoubleEditor::onEditingFinished(), ScientificSpinBoxEditor::onEditingFinished(), IntEditor::onEditingFinished(), ComboPropertyEditor::onIndexChanged(), and MultiComboPropertyEditor::onModelDataChanged().

◆ setLimits()

void ScientificDoublePropertyEditor::setLimits ( const RealLimits limits)

Definition at line 237 of file CustomEditors.cpp.

238 {
239  double minimum = limits.hasLowerLimit() ? std::max(limits.lowerLimit(), -1e+200) : -1e+200;
240  double maximum = limits.hasUpperLimit() ? std::min(limits.upperLimit(), +1e+200) : +1e+200;
241  m_validator->setRange(minimum, maximum, 1000);
242 }
bool hasUpperLimit() const
if has upper limit
Definition: RealLimits.cpp:57
double upperLimit() const
Returns upper limit.
Definition: RealLimits.cpp:62
double lowerLimit() const
Returns lower limit.
Definition: RealLimits.cpp:40
bool hasLowerLimit() const
if has lower limit
Definition: RealLimits.cpp:35

References RealLimits::hasLowerLimit(), RealLimits::hasUpperLimit(), RealLimits::lowerLimit(), m_validator, and RealLimits::upperLimit().

Here is the call graph for this function:

Member Data Documentation

◆ m_data

◆ m_lineEdit

class QLineEdit* ScientificDoublePropertyEditor::m_lineEdit
private

Definition at line 109 of file CustomEditors.h.

Referenced by ScientificDoublePropertyEditor(), initEditor(), and onEditingFinished().

◆ m_validator

class QDoubleValidator* ScientificDoublePropertyEditor::m_validator
private

Definition at line 110 of file CustomEditors.h.

Referenced by ScientificDoublePropertyEditor(), and setLimits().


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