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

Editor for ExternalProperty variant. More...

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

 ExternalPropertyEditor (QWidget *parent=nullptr)
 
QVariant editorData ()
 
void setExternalDialogType (const QString &dialogType)
 

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 buttonClicked ()
 

Private Attributes

QString m_extDialogType
 Type of the dialog which will be created on button click. More...
 
LostFocusFilterm_focusFilter
 
QLabel * m_pixmapLabel
 
QLabel * m_textLabel
 

Detailed Description

Editor for ExternalProperty variant.

Definition at line 50 of file CustomEditors.h.

Constructor & Destructor Documentation

◆ ExternalPropertyEditor()

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

Definition at line 68 of file CustomEditors.cpp.

69  : CustomEditor(parent)
70  , m_textLabel(new QLabel)
71  , m_pixmapLabel(new QLabel)
72  , m_focusFilter(new LostFocusFilter(this))
73  , m_extDialogType("ExtMaterialEditor")
74 {
75  setMouseTracking(true);
76  setAutoFillBackground(true);
77 
78  auto layout = new QHBoxLayout;
79  layout->setContentsMargins(4, 0, 0, 0);
80 
81  ExternalProperty defProperty; // to get label and pixmap of undefined material
82  m_textLabel->setText(defProperty.text());
83  m_pixmapLabel->setPixmap(defProperty.pixmap());
84 
85  auto button = new QToolButton;
86  button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
87  button->setText(QLatin1String(" . . . "));
88  button->setToolTip("Material selector");
89  layout->addWidget(m_pixmapLabel);
90  layout->addWidget(m_textLabel);
91  layout->addStretch(1);
92  layout->addWidget(button);
93  setFocusPolicy(Qt::StrongFocus);
94  setAttribute(Qt::WA_InputMethodEnabled);
95  connect(button, &QToolButton::clicked, this, &ExternalPropertyEditor::buttonClicked);
96 
97  setLayout(layout);
98 }
CustomEditor(QWidget *parent=nullptr)
Definition: CustomEditors.h:31
LostFocusFilter * m_focusFilter
Definition: CustomEditors.h:66
QString m_extDialogType
Type of the dialog which will be created on button click.
Definition: CustomEditors.h:67
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
QString text() const
QPixmap pixmap() const
Event filter to prevent lost of focus by custom material editor.

References buttonClicked(), m_pixmapLabel, m_textLabel, ExternalProperty::pixmap(), and ExternalProperty::text().

Here is the call graph for this function:

Member Function Documentation

◆ buttonClicked

void ExternalPropertyEditor::buttonClicked ( )
privateslot

Definition at line 105 of file CustomEditors.cpp.

106 {
107  // temporarily installing filter to prevent loss of focus caused by too insistent dialog
108  installEventFilter(m_focusFilter);
109  ExternalProperty property = m_data.value<ExternalProperty>();
110 
111  ExternalProperty newProperty;
112  if (m_extDialogType == "ExtMaterialEditor") {
113  newProperty = MaterialItemUtils::selectMaterialProperty(property);
114  } else if (m_extDialogType == "ExtColorEditor") {
115  newProperty = MaterialItemUtils::selectColorProperty(property);
116  } else {
117  throw GUIHelpers::Error("ExternalPropertyEditor::buttonClicked() -> Unexpected dialog");
118  }
119 
120  removeEventFilter(m_focusFilter);
121 
122  if (newProperty.isValid() && newProperty != property)
123  setDataIntern(newProperty.variant());
124 }
QVariant m_data
Definition: CustomEditors.h:45
void setDataIntern(const QVariant &data)
Saves the data from the editor and informs external delegates.
ExternalProperty selectMaterialProperty(const ExternalProperty &previous=ExternalProperty())
Calls material selector dialog.
ExternalProperty selectColorProperty(const ExternalProperty &previous=ExternalProperty())
Calls color selector dialog.

References CustomEditor::m_data, m_extDialogType, m_focusFilter, MaterialItemUtils::selectColorProperty(), MaterialItemUtils::selectMaterialProperty(), and CustomEditor::setDataIntern().

Referenced by ExternalPropertyEditor().

Here is the call graph for this function:

◆ 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; }

References CustomEditor::m_data.

◆ initEditor()

void ExternalPropertyEditor::initEditor ( )
protectedvirtual

Inits editor widgets from m_data.

Reimplemented from CustomEditor.

Definition at line 126 of file CustomEditors.cpp.

127 {
128  ASSERT(m_data.canConvert<ExternalProperty>());
130  m_textLabel->setText(materialProperty.text());
131  m_pixmapLabel->setPixmap(materialProperty.pixmap());
132 }
#define ASSERT(condition)
Definition: Assert.h:31
ExternalProperty materialProperty(const SessionItem &materialItem)
Constructs material property corresponding to given material.

References ASSERT, CustomEditor::m_data, m_pixmapLabel, m_textLabel, MaterialItemUtils::materialProperty(), ExternalProperty::pixmap(), and ExternalProperty::text().

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

◆ setExternalDialogType()

void ExternalPropertyEditor::setExternalDialogType ( const QString &  dialogType)

Definition at line 100 of file CustomEditors.cpp.

101 {
102  m_extDialogType = editorType;
103 }

References m_extDialogType.

Referenced by PropertyEditorFactory::CreateEditor().

Member Data Documentation

◆ m_data

◆ m_extDialogType

QString ExternalPropertyEditor::m_extDialogType
private

Type of the dialog which will be created on button click.

Definition at line 67 of file CustomEditors.h.

Referenced by buttonClicked(), and setExternalDialogType().

◆ m_focusFilter

LostFocusFilter* ExternalPropertyEditor::m_focusFilter
private

Definition at line 66 of file CustomEditors.h.

Referenced by buttonClicked().

◆ m_pixmapLabel

QLabel* ExternalPropertyEditor::m_pixmapLabel
private

Definition at line 65 of file CustomEditors.h.

Referenced by ExternalPropertyEditor(), and initEditor().

◆ m_textLabel

QLabel* ExternalPropertyEditor::m_textLabel
private

Definition at line 64 of file CustomEditors.h.

Referenced by ExternalPropertyEditor(), and initEditor().


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