BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ComboPropertyEditor Class Reference

Description

Editor for ComboProperty variant.

Definition at line 54 of file CustomEditors.h.

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

 ComboPropertyEditor (QWidget *parent=nullptr)
 
QVariant editorData ()
 
QSize minimumSizeHint () const override
 
QSize sizeHint () const override
 

Protected Slots

virtual void onIndexChanged (int index)
 

Protected Member Functions

void initEditor () override
 Inits editor widgets from m_data. More...
 
virtual int internIndex ()
 Returns index for QComboBox. More...
 
virtual QStringList internLabels ()
 Returns list of labels for QComboBox. More...
 
void setConnected (bool isConnected)
 
void setDataIntern (const QVariant &data)
 Saves the data from the editor and informs external delegates. More...
 

Protected Attributes

QComboBox * m_box
 
QVariant m_data
 
class WheelEventEaterm_wheel_event_filter
 

Constructor & Destructor Documentation

◆ ComboPropertyEditor()

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

Definition at line 60 of file CustomEditors.cpp.

61  : CustomEditor(parent)
62  , m_box(new QComboBox)
64 {
65  setAutoFillBackground(true);
66  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
67 
68  auto* layout = new QVBoxLayout;
69  layout->setMargin(0);
70  layout->setSpacing(0);
71  layout->addWidget(m_box);
72 
73  m_box->installEventFilter(m_wheel_event_filter);
74 
75  setLayout(layout);
76  setConnected(true);
77 }
void setConnected(bool isConnected)
class WheelEventEater * m_wheel_event_filter
Definition: CustomEditors.h:72
CustomEditor(QWidget *parent=nullptr)
Definition: CustomEditors.h:32
Event filter to install on combo boxes and spin boxes to not to react on wheel events during scrollin...

References m_box, m_wheel_event_filter, and setConnected().

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 FitParameterDelegate::createEditor(), and CustomEditor::setDataIntern().

◆ editorData()

QVariant CustomEditor::editorData ( )
inlineinherited

Definition at line 37 of file CustomEditors.h.

37 { return m_data; }
QVariant m_data
Definition: CustomEditors.h:49

References CustomEditor::m_data.

◆ initEditor()

void ComboPropertyEditor::initEditor ( )
overrideprotectedvirtual

Inits editor widgets from m_data.

Reimplemented from CustomEditor.

Definition at line 99 of file CustomEditors.cpp.

100 {
101  setConnected(false);
102 
103  m_box->clear();
104  m_box->insertItems(0, internLabels());
105  m_box->setCurrentIndex(internIndex());
106 
107  setConnected(true);
108 }
virtual int internIndex()
Returns index for QComboBox.
virtual QStringList internLabels()
Returns list of labels for QComboBox.

References internIndex(), internLabels(), m_box, and setConnected().

Here is the call graph for this function:

◆ internIndex()

int ComboPropertyEditor::internIndex ( )
protectedvirtual

Returns index for QComboBox.

Definition at line 122 of file CustomEditors.cpp.

123 {
124  if (!m_data.canConvert<ComboProperty>())
125  return 0;
126  auto comboProperty = m_data.value<ComboProperty>();
127  return comboProperty.currentIndex();
128 }
Custom property to define list of string values with multiple selections. Intended for QVariant.
Definition: ComboProperty.h:25
int currentIndex() const

References ComboProperty::currentIndex(), and CustomEditor::m_data.

Referenced by initEditor().

Here is the call graph for this function:

◆ internLabels()

QStringList ComboPropertyEditor::internLabels ( )
protectedvirtual

Returns list of labels for QComboBox.

Definition at line 112 of file CustomEditors.cpp.

113 {
114  if (!m_data.canConvert<ComboProperty>())
115  return {};
116  auto comboProperty = m_data.value<ComboProperty>();
117  return comboProperty.getValues();
118 }
QStringList getValues() const

References ComboProperty::getValues(), and CustomEditor::m_data.

Referenced by initEditor().

Here is the call graph for this function:

◆ minimumSizeHint()

QSize ComboPropertyEditor::minimumSizeHint ( ) const
override

Definition at line 84 of file CustomEditors.cpp.

85 {
86  return m_box->minimumSizeHint();
87 }

References m_box.

◆ onIndexChanged

void ComboPropertyEditor::onIndexChanged ( int  index)
protectedvirtualslot

Definition at line 89 of file CustomEditors.cpp.

90 {
91  auto comboProperty = m_data.value<ComboProperty>();
92 
93  if (comboProperty.currentIndex() != index) {
94  comboProperty.setCurrentIndex(index);
95  setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty));
96  }
97 }
void setCurrentIndex(int index)
void setDataIntern(const QVariant &data)
Saves the data from the editor and informs external delegates.

References CustomEditor::m_data, ComboProperty::setCurrentIndex(), and CustomEditor::setDataIntern().

Referenced by setConnected().

Here is the call graph for this function:

◆ setConnected()

void ComboPropertyEditor::setConnected ( bool  isConnected)
protected

Definition at line 130 of file CustomEditors.cpp.

131 {
132  if (isConnected)
133  connect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
134  &ComboPropertyEditor::onIndexChanged, Qt::UniqueConnection);
135  else
136  disconnect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
138 }
virtual void onIndexChanged(int index)

References m_box, and onIndexChanged().

Referenced by ComboPropertyEditor(), and initEditor().

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 40 of file CustomEditors.cpp.

41 {
42  m_data = data;
43  initEditor();
44 }
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 52 of file CustomEditors.cpp.

53 {
54  m_data = data;
56 }
void dataChanged(const QVariant &data)
Signal emit then user changed the data through the editor.

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

Referenced by ScientificSpinBoxEditor::onEditingFinished(), and onIndexChanged().

◆ sizeHint()

QSize ComboPropertyEditor::sizeHint ( ) const
override

Definition at line 79 of file CustomEditors.cpp.

80 {
81  return m_box->sizeHint();
82 }

References m_box.

Member Data Documentation

◆ m_box

QComboBox* ComboPropertyEditor::m_box
protected

◆ m_data

◆ m_wheel_event_filter

class WheelEventEater* ComboPropertyEditor::m_wheel_event_filter
protected

Definition at line 72 of file CustomEditors.h.

Referenced by ComboPropertyEditor().


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