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

Editor for Int variant. More...

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

 IntEditor (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 QSpinBox * m_intEditor
 

Detailed Description

Editor for Int variant.

Definition at line 156 of file CustomEditors.h.

Constructor & Destructor Documentation

◆ IntEditor()

IntEditor::IntEditor ( QWidget *  parent = nullptr)

Definition at line 372 of file CustomEditors.cpp.

372  : CustomEditor(parent), m_intEditor(new QSpinBox)
373 {
374  setAutoFillBackground(true);
375  m_intEditor->setFocusPolicy(Qt::StrongFocus);
376  m_intEditor->setKeyboardTracking(false);
377 
378  auto layout = new QVBoxLayout;
379  layout->setMargin(0);
380  layout->setSpacing(0);
381 
382  layout->addWidget(m_intEditor);
383 
384  connect(m_intEditor, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
385  [=] { this->onEditingFinished(); });
386 
387  setLayout(layout);
388 
389  setFocusProxy(m_intEditor);
390 }
CustomEditor(QWidget *parent=nullptr)
Definition: CustomEditors.h:31
class QSpinBox * m_intEditor
void onEditingFinished()

References m_intEditor, 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 IntEditor::initEditor ( )
protectedvirtual

Inits editor widgets from m_data.

Reimplemented from CustomEditor.

Definition at line 410 of file CustomEditors.cpp.

411 {
412  if (!m_data.isValid() || m_data.type() != QVariant::Int)
413  return;
414  m_intEditor->setValue(m_data.toInt());
415 }

References CustomEditor::m_data, and m_intEditor.

◆ onEditingFinished

void IntEditor::onEditingFinished ( )
privateslot

Definition at line 402 of file CustomEditors.cpp.

403 {
404  int new_value = m_intEditor->value();
405 
406  if (new_value != m_data.toInt())
407  setDataIntern(QVariant::fromValue(new_value));
408 }
void setDataIntern(const QVariant &data)
Saves the data from the editor and informs external delegates.

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

Referenced by IntEditor().

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(), DoubleEditor::onEditingFinished(), ScientificSpinBoxEditor::onEditingFinished(), onEditingFinished(), ComboPropertyEditor::onIndexChanged(), and MultiComboPropertyEditor::onModelDataChanged().

◆ setLimits()

void IntEditor::setLimits ( const RealLimits limits)

Definition at line 392 of file CustomEditors.cpp.

393 {
394  m_intEditor->setMaximum(std::numeric_limits<int>::max());
395 
396  if (limits.hasLowerLimit())
397  m_intEditor->setMinimum(static_cast<int>(limits.lowerLimit()));
398  if (limits.hasUpperLimit())
399  m_intEditor->setMaximum(static_cast<int>(limits.upperLimit()));
400 }
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_intEditor, and RealLimits::upperLimit().

Referenced by PropertyEditorFactory::CreateEditor().

Here is the call graph for this function:

Member Data Documentation

◆ m_data

◆ m_intEditor

class QSpinBox* IntEditor::m_intEditor
private

Definition at line 170 of file CustomEditors.h.

Referenced by IntEditor(), initEditor(), onEditingFinished(), and setLimits().


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