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

Editor for ComboProperty variant. More...

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
 
QSize sizeHint () const
 

Protected Slots

virtual void onIndexChanged (int index)
 

Protected Member Functions

void initEditor ()
 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
 

Detailed Description

Editor for ComboProperty variant.

Definition at line 72 of file CustomEditors.h.

Constructor & Destructor Documentation

◆ ComboPropertyEditor()

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

Definition at line 136 of file CustomEditors.cpp.

137  : CustomEditor(parent), m_box(new QComboBox), m_wheel_event_filter(new WheelEventEater(this))
138 {
139  setAutoFillBackground(true);
140  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
141 
142  auto layout = new QVBoxLayout;
143  layout->setMargin(0);
144  layout->setSpacing(0);
145  layout->addWidget(m_box);
146 
147  m_box->installEventFilter(m_wheel_event_filter);
148 
149  setLayout(layout);
150  setConnected(true);
151 }
void setConnected(bool isConnected)
class WheelEventEater * m_wheel_event_filter
Definition: CustomEditors.h:90
CustomEditor(QWidget *parent=nullptr)
Definition: CustomEditors.h:31
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 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 ComboPropertyEditor::initEditor ( )
protectedvirtual

Inits editor widgets from m_data.

Reimplemented from CustomEditor.

Definition at line 173 of file CustomEditors.cpp.

174 {
175  setConnected(false);
176 
177  m_box->clear();
178  m_box->insertItems(0, internLabels());
179  m_box->setCurrentIndex(internIndex());
180 
181  setConnected(true);
182 }
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 196 of file CustomEditors.cpp.

197 {
198  if (!m_data.canConvert<ComboProperty>())
199  return 0;
200  ComboProperty comboProperty = m_data.value<ComboProperty>();
201  return comboProperty.currentIndex();
202 }
Custom property to define list of string values with multiple selections.
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 186 of file CustomEditors.cpp.

187 {
188  if (!m_data.canConvert<ComboProperty>())
189  return {};
190  ComboProperty comboProperty = m_data.value<ComboProperty>();
191  return comboProperty.getValues();
192 }
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

Definition at line 158 of file CustomEditors.cpp.

159 {
160  return m_box->minimumSizeHint();
161 }

References m_box.

◆ onIndexChanged

void ComboPropertyEditor::onIndexChanged ( int  index)
protectedvirtualslot

Definition at line 163 of file CustomEditors.cpp.

164 {
165  ComboProperty comboProperty = m_data.value<ComboProperty>();
166 
167  if (comboProperty.currentIndex() != index) {
168  comboProperty.setCurrentIndex(index);
169  setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty));
170  }
171 }
void setCurrentIndex(int index)
void setDataIntern(const QVariant &data)
Saves the data from the editor and informs external delegates.

References ComboProperty::currentIndex(), 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 204 of file CustomEditors.cpp.

205 {
206  if (isConnected)
207  connect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
208  &ComboPropertyEditor::onIndexChanged, Qt::UniqueConnection);
209  else
210  disconnect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
212 }
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 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(), IntEditor::onEditingFinished(), onIndexChanged(), and MultiComboPropertyEditor::onModelDataChanged().

◆ sizeHint()

QSize ComboPropertyEditor::sizeHint ( ) const

Definition at line 153 of file CustomEditors.cpp.

154 {
155  return m_box->sizeHint();
156 }

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 90 of file CustomEditors.h.

Referenced by ComboPropertyEditor().


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