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

Editor for Double variant. More...

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

 DoubleEditor (QWidget *parent=nullptr)
 
QVariant editorData ()
 
void setDecimals (int decimals)
 
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 QDoubleSpinBox * m_doubleEditor
 

Detailed Description

Editor for Double variant.

Definition at line 115 of file CustomEditors.h.

Constructor & Destructor Documentation

◆ DoubleEditor()

DoubleEditor::DoubleEditor ( QWidget *  parent = nullptr)

Definition at line 260 of file CustomEditors.cpp.

261  : CustomEditor(parent), m_doubleEditor(new QDoubleSpinBox)
262 {
263  setAutoFillBackground(true);
264  setFocusPolicy(Qt::StrongFocus);
265  m_doubleEditor->setFocusPolicy(Qt::StrongFocus);
266  m_doubleEditor->setKeyboardTracking(false);
267 
268  auto layout = new QVBoxLayout;
269  layout->setMargin(0);
270  layout->setSpacing(0);
271 
272  layout->addWidget(m_doubleEditor);
273 
274  connect(m_doubleEditor,
275  static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
276  [=] { this->onEditingFinished(); });
277 
278  setLayout(layout);
279 
280  setFocusProxy(m_doubleEditor);
281 }
CustomEditor(QWidget *parent=nullptr)
Definition: CustomEditors.h:31
class QDoubleSpinBox * m_doubleEditor
void onEditingFinished()

References m_doubleEditor, 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 DoubleEditor::initEditor ( )
protectedvirtual

Inits editor widgets from m_data.

Reimplemented from CustomEditor.

Definition at line 308 of file CustomEditors.cpp.

309 {
310  ASSERT(m_data.type() == QVariant::Double);
311  m_doubleEditor->setValue(m_data.toDouble());
312 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, CustomEditor::m_data, and m_doubleEditor.

◆ onEditingFinished

void DoubleEditor::onEditingFinished ( )
privateslot

Definition at line 300 of file CustomEditors.cpp.

301 {
302  double new_value = m_doubleEditor->value();
303 
304  if (new_value != m_data.toDouble())
305  setDataIntern(QVariant::fromValue(new_value));
306 }
void setDataIntern(const QVariant &data)
Saves the data from the editor and informs external delegates.

References CustomEditor::m_data, m_doubleEditor, and 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 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(), ScientificDoublePropertyEditor::onEditingFinished(), onEditingFinished(), ScientificSpinBoxEditor::onEditingFinished(), IntEditor::onEditingFinished(), ComboPropertyEditor::onIndexChanged(), and MultiComboPropertyEditor::onModelDataChanged().

◆ setDecimals()

void DoubleEditor::setDecimals ( int  decimals)

Definition at line 294 of file CustomEditors.cpp.

295 {
296  m_doubleEditor->setDecimals(decimals);
297  m_doubleEditor->setSingleStep(singleStep(decimals));
298 }

References m_doubleEditor.

◆ setLimits()

void DoubleEditor::setLimits ( const RealLimits limits)

Definition at line 283 of file CustomEditors.cpp.

284 {
285  m_doubleEditor->setMaximum(std::numeric_limits<double>::max());
286  m_doubleEditor->setMinimum(std::numeric_limits<double>::lowest());
287 
288  if (limits.hasLowerLimit())
289  m_doubleEditor->setMinimum(limits.lowerLimit());
290  if (limits.hasUpperLimit())
291  m_doubleEditor->setMaximum(static_cast<int>(limits.upperLimit()));
292 }
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_doubleEditor, and RealLimits::upperLimit().

Referenced by PropertyEditorFactory::CreateEditor().

Here is the call graph for this function:

Member Data Documentation

◆ m_data

◆ m_doubleEditor

class QDoubleSpinBox* DoubleEditor::m_doubleEditor
private

Definition at line 130 of file CustomEditors.h.

Referenced by DoubleEditor(), initEditor(), onEditingFinished(), setDecimals(), and setLimits().


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