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

Custom editor for QVariant based on ComboProperty. More...

Inheritance diagram for ModelView::ComboPropertyEditor:
[legend]
Collaboration diagram for ModelView::ComboPropertyEditor:
[legend]

Public Slots

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

Signals

void dataChanged (QVariant value)
 Emmits signal when data was changed in an editor. More...
 

Public Member Functions

 ComboPropertyEditor (QWidget *parent=nullptr)
 
QVariant data () const
 
bool is_persistent () const override
 Returns true if editor should remains alive after editing finished. More...
 
QSize minimumSizeHint () const override
 
QSize sizeHint () const override
 

Protected Slots

virtual void onIndexChanged (int index)
 

Protected Member Functions

void setDataIntern (const QVariant &data)
 Saves the data as given by editor's internal components and notifies the model. More...
 

Protected Attributes

QVariant m_data
 

Properties

QVariant value
 

Private Member Functions

int internIndex ()
 Returns index for QComboBox. More...
 
std::vector< std::string > internLabels ()
 Returns list of labels for QComboBox. More...
 
void setConnected (bool isConnected)
 
void update_components () override
 Should update widget components from m_data, if necessary. More...
 

Private Attributes

QComboBox * m_box
 

Detailed Description

Custom editor for QVariant based on ComboProperty.

Definition at line 26 of file combopropertyeditor.h.

Constructor & Destructor Documentation

◆ ComboPropertyEditor()

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

Definition at line 32 of file combopropertyeditor.cpp.

33  : CustomEditor(parent), m_box(new QComboBox)
34 {
35  setAutoFillBackground(true);
36  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
37 
38  auto layout = new QVBoxLayout;
39  layout->setMargin(0);
40  layout->setSpacing(0);
41  layout->addWidget(m_box);
42  setLayout(layout);
43 
44  setConnected(true);
45 }
CustomEditor(QWidget *parent=nullptr)

References m_box, and setConnected().

Here is the call graph for this function:

Member Function Documentation

◆ data()

QVariant CustomEditor::data ( ) const
inherited

Definition at line 21 of file customeditor.cpp.

22 {
23  return m_data;
24 }

References ModelView::CustomEditor::m_data.

Referenced by ModelView::CustomEditor::setData(), and ModelView::CustomEditor::setDataIntern().

◆ dataChanged

void ModelView::CustomEditor::dataChanged ( QVariant  value)
signalinherited

◆ internIndex()

int ComboPropertyEditor::internIndex ( )
private

Returns index for QComboBox.

Definition at line 95 of file combopropertyeditor.cpp.

96 {
97  if (!m_data.canConvert<ComboProperty>())
98  return 0;
99  auto comboProperty = m_data.value<ComboProperty>();
100  return comboProperty.currentIndex();
101 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27

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

Referenced by update_components().

Here is the call graph for this function:

◆ internLabels()

std::vector< std::string > ComboPropertyEditor::internLabels ( )
private

Returns list of labels for QComboBox.

Definition at line 85 of file combopropertyeditor.cpp.

86 {
87  if (!m_data.canConvert<ComboProperty>())
88  return {};
89  auto comboProperty = m_data.value<ComboProperty>();
90  return comboProperty.values();
91 }
std::vector< std::string > values() const

References ModelView::CustomEditor::m_data, and ModelView::ComboProperty::values().

Referenced by update_components().

Here is the call graph for this function:

◆ is_persistent()

bool ComboPropertyEditor::is_persistent ( ) const
overridevirtual

Returns true if editor should remains alive after editing finished.

Reimplemented from ModelView::CustomEditor.

Definition at line 57 of file combopropertyeditor.cpp.

58 {
59  return true;
60 }

◆ minimumSizeHint()

QSize ComboPropertyEditor::minimumSizeHint ( ) const
override

Definition at line 52 of file combopropertyeditor.cpp.

53 {
54  return m_box->minimumSizeHint();
55 }

References m_box.

◆ onIndexChanged

void ComboPropertyEditor::onIndexChanged ( int  index)
protectedvirtualslot

Definition at line 62 of file combopropertyeditor.cpp.

63 {
64  auto comboProperty = m_data.value<ComboProperty>();
65 
66  if (comboProperty.currentIndex() != index) {
67  comboProperty.setCurrentIndex(index);
68  setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty));
69  }
70 }
void setCurrentIndex(int index)
void setDataIntern(const QVariant &data)
Saves the data as given by editor's internal components and notifies the model.

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

Referenced by setConnected().

Here is the call graph for this function:

◆ setConnected()

void ComboPropertyEditor::setConnected ( bool  isConnected)
private

Definition at line 103 of file combopropertyeditor.cpp.

104 {
105  if (isConnected)
106  connect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
107  &ComboPropertyEditor::onIndexChanged, Qt::UniqueConnection);
108  else
109  disconnect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
111 }
virtual void onIndexChanged(int index)

References m_box, and onIndexChanged().

Referenced by ComboPropertyEditor(), and update_components().

Here is the call graph for this function:

◆ setData

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

Sets the data from model to editor.

Definition at line 35 of file customeditor.cpp.

36 {
37  m_data = data;
39 }
QVariant data() const
virtual void update_components()=0
Should update widget components from m_data, if necessary.

References ModelView::CustomEditor::data(), ModelView::CustomEditor::m_data, and ModelView::CustomEditor::update_components().

Here is the call graph for this function:

◆ setDataIntern()

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

Saves the data as given by editor's internal components and notifies the model.

Definition at line 43 of file customeditor.cpp.

44 {
45  m_data = data;
47 }
void dataChanged(QVariant value)
Emmits signal when data was changed in an editor.

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

Referenced by ModelView::ColorEditor::mousePressEvent(), ModelView::BoolEditor::onCheckBoxChange(), ModelView::DoubleEditor::onEditingFinished(), ModelView::IntegerEditor::onEditingFinished(), ModelView::ScientificDoubleEditor::onEditingFinished(), ModelView::ScientificSpinBoxEditor::onEditingFinished(), onIndexChanged(), ModelView::ExternalPropertyComboEditor::onIndexChanged(), and ModelView::SelectableComboBoxEditor::onModelDataChanged().

Here is the call graph for this function:

◆ sizeHint()

QSize ComboPropertyEditor::sizeHint ( ) const
override

Definition at line 47 of file combopropertyeditor.cpp.

48 {
49  return m_box->sizeHint();
50 }

References m_box.

◆ update_components()

void ComboPropertyEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 72 of file combopropertyeditor.cpp.

73 {
74  setConnected(false);
75 
76  m_box->clear();
77  m_box->insertItems(0, toList(internLabels()));
78  m_box->setCurrentIndex(internIndex());
79 
80  setConnected(true);
81 }
int internIndex()
Returns index for QComboBox.
std::vector< std::string > internLabels()
Returns list of labels for QComboBox.

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

Here is the call graph for this function:

Member Data Documentation

◆ m_box

QComboBox* ModelView::ComboPropertyEditor::m_box
private

◆ m_data

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

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