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

Custom editor for table/tree cells to select ExternalProperty from the list of external properties. More...

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

Public Types

using callback_t = std::function< std::vector< ModelView::ExternalProperty >()>
 

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

 ExternalPropertyComboEditor (callback_t callback, QWidget *parent=nullptr)
 
QVariant data () const
 
virtual bool is_persistent () const
 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...
 
void setConnected (bool isConnected)
 
void update_components () override
 Should update widget components from m_data, if necessary. More...
 

Private Attributes

QComboBox * m_box {nullptr}
 
QStandardItemModel * m_comboModel {nullptr}
 
callback_t m_getPropertiesCallback
 

Detailed Description

Custom editor for table/tree cells to select ExternalProperty from the list of external properties.

Uses callbacks to retrieve vector of possible properties.

Definition at line 32 of file externalpropertycomboeditor.h.

Member Typedef Documentation

◆ callback_t

Constructor & Destructor Documentation

◆ ExternalPropertyComboEditor()

ExternalPropertyComboEditor::ExternalPropertyComboEditor ( callback_t  callback,
QWidget *  parent = nullptr 
)

Definition at line 24 of file externalpropertycomboeditor.cpp.

25  : CustomEditor(parent)
26  , m_getPropertiesCallback(std::move(callback))
27  , m_box(new QComboBox)
28  , m_comboModel(new QStandardItemModel(this))
29 {
30  setAutoFillBackground(true);
31  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
32 
33  auto layout = new QVBoxLayout;
34  layout->setMargin(0);
35  layout->setSpacing(0);
36  layout->addWidget(m_box);
37  setLayout(layout);
38 
39  m_box->setModel(m_comboModel);
40 
41  setConnected(true);
42 }
CustomEditor(QWidget *parent=nullptr)

References m_box, m_comboModel, 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 ExternalPropertyComboEditor::internIndex ( )
private

Returns index for QComboBox.

Definition at line 85 of file externalpropertycomboeditor.cpp.

86 {
87  if (!m_data.canConvert<ModelView::ExternalProperty>())
88  return 0;
89 
90  auto property = m_data.value<ModelView::ExternalProperty>();
91  int result(-1);
92  for (auto prop : m_getPropertiesCallback()) {
93  ++result;
94  if (property.identifier() == prop.identifier())
95  return result;
96  }
97 
98  return result;
99 }
Property to carry text, color and identifier.

References ModelView::CustomEditor::m_data, and m_getPropertiesCallback.

Referenced by update_components().

◆ is_persistent()

bool CustomEditor::is_persistent ( ) const
virtualinherited

Returns true if editor should remains alive after editing finished.

Reimplemented in ModelView::SelectableComboBoxEditor, ModelView::ScientificSpinBoxEditor, ModelView::ComboPropertyEditor, and ModelView::BoolEditor.

Definition at line 28 of file customeditor.cpp.

29 {
30  return false;
31 }

◆ minimumSizeHint()

QSize ExternalPropertyComboEditor::minimumSizeHint ( ) const
override

Definition at line 49 of file externalpropertycomboeditor.cpp.

50 {
51  return m_box->minimumSizeHint();
52 }

References m_box.

◆ onIndexChanged

void ExternalPropertyComboEditor::onIndexChanged ( int  index)
protectedvirtualslot

Definition at line 54 of file externalpropertycomboeditor.cpp.

55 {
56  auto property = m_data.value<ModelView::ExternalProperty>();
57  auto mdata = m_getPropertiesCallback();
58 
59  if (index >= 0 && index < static_cast<int>(mdata.size())) {
60  if (property != mdata[static_cast<size_t>(index)])
61  setDataIntern(QVariant::fromValue(mdata[static_cast<size_t>(index)]));
62  }
63 }
void setDataIntern(const QVariant &data)
Saves the data as given by editor's internal components and notifies the model.

References ModelView::CustomEditor::m_data, m_getPropertiesCallback, and ModelView::CustomEditor::setDataIntern().

Referenced by setConnected().

Here is the call graph for this function:

◆ setConnected()

void ExternalPropertyComboEditor::setConnected ( bool  isConnected)
private

Definition at line 101 of file externalpropertycomboeditor.cpp.

102 {
103  if (isConnected)
104  connect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
105  &ExternalPropertyComboEditor::onIndexChanged, Qt::UniqueConnection);
106  else
107  disconnect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
109 }

References m_box, and onIndexChanged().

Referenced by ExternalPropertyComboEditor(), 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(), ModelView::ComboPropertyEditor::onIndexChanged(), onIndexChanged(), and ModelView::SelectableComboBoxEditor::onModelDataChanged().

Here is the call graph for this function:

◆ sizeHint()

QSize ExternalPropertyComboEditor::sizeHint ( ) const
override

Definition at line 44 of file externalpropertycomboeditor.cpp.

45 {
46  return m_box->sizeHint();
47 }

References m_box.

◆ update_components()

void ExternalPropertyComboEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 65 of file externalpropertycomboeditor.cpp.

66 {
67  setConnected(false);
68 
69  m_comboModel->clear();
70 
71  QStandardItem* parentItem = m_comboModel->invisibleRootItem();
72  for (auto prop : m_getPropertiesCallback()) {
73  auto item = new QStandardItem(QString::fromStdString(prop.text()));
74  parentItem->appendRow(item);
75  item->setData(prop.color(), Qt::DecorationRole);
76  }
77 
78  m_box->setCurrentIndex(internIndex());
79 
80  setConnected(true);
81 }
int internIndex()
Returns index for QComboBox.
QVariant DecorationRole(const SessionItem &item)
Returns tooltip for given item.

References SessionItemUtils::DecorationRole(), internIndex(), m_box, m_comboModel, m_getPropertiesCallback, and setConnected().

Here is the call graph for this function:

Member Data Documentation

◆ m_box

QComboBox* ModelView::ExternalPropertyComboEditor::m_box {nullptr}
private

◆ m_comboModel

QStandardItemModel* ModelView::ExternalPropertyComboEditor::m_comboModel {nullptr}
private

Definition at line 53 of file externalpropertycomboeditor.h.

Referenced by ExternalPropertyComboEditor(), and update_components().

◆ m_data

◆ m_getPropertiesCallback

callback_t ModelView::ExternalPropertyComboEditor::m_getPropertiesCallback
private

Definition at line 51 of file externalpropertycomboeditor.h.

Referenced by internIndex(), onIndexChanged(), and update_components().

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

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