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

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

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

 ExternalPropertyEditor (QWidget *parent=nullptr)
 
QVariant data () const
 
virtual bool is_persistent () const
 Returns true if editor should remains alive after editing finished. More...
 
void setCallback (std::function< void(const QVariant &)> callback)
 

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 Slots

void buttonClicked ()
 

Private Member Functions

void update_components () override
 Should update widget components from m_data, if necessary. More...
 

Private Attributes

std::function< void(const QVariant &)> m_callback
 
LostFocusFilterm_focusFilter
 
QLabel * m_pixmapLabel
 
QLabel * m_textLabel
 

Detailed Description

Custom editor for QVariant based on ExternalProperty.

Contains icon, label and button to call external dialog via callback mechanism.

Definition at line 30 of file externalpropertyeditor.h.

Constructor & Destructor Documentation

◆ ExternalPropertyEditor()

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

Definition at line 28 of file externalpropertyeditor.cpp.

29  : CustomEditor(parent)
30  , m_textLabel(new QLabel)
31  , m_pixmapLabel(new QLabel)
32  , m_focusFilter(new LostFocusFilter(this))
33 
34 {
35  setMouseTracking(true);
36  setAutoFillBackground(true);
37 
38  auto layout = new QHBoxLayout;
39  layout->setContentsMargins(4, 0, 0, 0);
40 
41  auto button = new QToolButton;
42  button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
43  button->setText(QLatin1String(" . . . "));
44  button->setToolTip("Open selector");
45  layout->addWidget(m_pixmapLabel);
46  layout->addWidget(m_textLabel);
47  layout->addStretch(1);
48  layout->addWidget(button);
49  setFocusPolicy(Qt::StrongFocus);
50  setAttribute(Qt::WA_InputMethodEnabled);
51  connect(button, &QToolButton::clicked, this, &ExternalPropertyEditor::buttonClicked);
52 
53  setLayout(layout);
54 }
CustomEditor(QWidget *parent=nullptr)
Event filter to prevent loss of the focus.

References buttonClicked(), m_pixmapLabel, and m_textLabel.

Here is the call graph for this function:

Member Function Documentation

◆ buttonClicked

void ExternalPropertyEditor::buttonClicked ( )
privateslot

Definition at line 61 of file externalpropertyeditor.cpp.

62 {
63  if (m_callback)
65  else
66  QMessageBox::warning(nullptr, "Not configured", "No external dialog configured.");
67 }
std::function< void(const QVariant &)> m_callback
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: GUIHelpers.cpp:74

References m_callback, ModelView::CustomEditor::m_data, and GUIHelpers::warning().

Referenced by ExternalPropertyEditor().

Here is the call graph for this function:

◆ 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

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

◆ setCallback()

void ExternalPropertyEditor::setCallback ( std::function< void(const QVariant &)>  callback)

Definition at line 56 of file externalpropertyeditor.cpp.

57 {
58  m_callback = std::move(callback);
59 }

References m_callback.

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

Here is the call graph for this function:

◆ update_components()

void ExternalPropertyEditor::update_components ( )
overrideprivatevirtual

Should update widget components from m_data, if necessary.

Implements ModelView::CustomEditor.

Definition at line 69 of file externalpropertyeditor.cpp.

70 {
72  throw std::runtime_error("Error. Wrong variant type (ExternalProperty is required).");
73 
74  auto prop = m_data.value<ExternalProperty>();
76  pixmap.fill(prop.color());
77  m_textLabel->setText(QString::fromStdString(prop.text()));
78  m_pixmapLabel->setPixmap(pixmap);
79 }
Property to carry text, color and identifier.
MVVM_VIEWMODEL_EXPORT int DefaultPixmapSize()
Returns int value corresponding to pixmap in standard Qt table/tree decorations.
Definition: styleutils.cpp:17
MVVM_MODEL_EXPORT bool IsExtPropertyVariant(const Variant &variant)
Returns true in the case of ExternalProperty based variant.

References ModelView::Style::DefaultPixmapSize(), ModelView::Utils::IsExtPropertyVariant(), ModelView::CustomEditor::m_data, m_pixmapLabel, and m_textLabel.

Here is the call graph for this function:

Member Data Documentation

◆ m_callback

std::function<void(const QVariant&)> ModelView::ExternalPropertyEditor::m_callback
private

Definition at line 46 of file externalpropertyeditor.h.

Referenced by buttonClicked(), and setCallback().

◆ m_data

◆ m_focusFilter

LostFocusFilter* ModelView::ExternalPropertyEditor::m_focusFilter
private

Definition at line 45 of file externalpropertyeditor.h.

◆ m_pixmapLabel

QLabel* ModelView::ExternalPropertyEditor::m_pixmapLabel
private

Definition at line 44 of file externalpropertyeditor.h.

Referenced by ExternalPropertyEditor(), and update_components().

◆ m_textLabel

QLabel* ModelView::ExternalPropertyEditor::m_textLabel
private

Definition at line 43 of file externalpropertyeditor.h.

Referenced by ExternalPropertyEditor(), and update_components().

Property Documentation

◆ value

QVariant ModelView::CustomEditor::value
readwriteinherited

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