BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
FitParameterDelegate Class Reference

Description

The FitParameterDelegate class presents the content of SessionModel items in standard QTreeView. Extents base QItemDelegate with possibility to show/edit our custom QVariant's.

Definition at line 24 of file FitParameterDelegate.h.

Inheritance diagram for FitParameterDelegate:
[legend]
Collaboration diagram for FitParameterDelegate:
[legend]

Public Slots

void onCustomEditorDataChanged (const QVariant &)
 Notifies everyone that the editor has completed editing the data. More...
 

Public Member Functions

 FitParameterDelegate (QObject *parent)
 
QWidget * createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void setEditorData (QWidget *editor, const QModelIndex &index) const override
 Propagates the data change from the model to the editor (if it is still opened). More...
 
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
 Propagates changed data from the editor to the model. More...
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const override
 Increases height of the row by 20% wrt the default. More...
 
void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 Makes an editor occupying whole available space in a cell. If cell contains an icon as a decoration (i.e. icon of material property), it will be hidden as soon as editor up and running. More...
 

Protected Member Functions

virtual QWidget * createEditorFromIndex (const QModelIndex &index, QWidget *parent) const
 

Private Member Functions

void paintCustomLabel (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QString &text) const
 Paints custom text in a a place corresponding given index. More...
 

Constructor & Destructor Documentation

◆ FitParameterDelegate()

FitParameterDelegate::FitParameterDelegate ( QObject *  parent)

Definition at line 22 of file FitParameterDelegate.cpp.

23  : QStyledItemDelegate(parent)
24 {
25 }

Member Function Documentation

◆ createEditor()

QWidget * FitParameterDelegate::createEditor ( QWidget *  parent,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Definition at line 37 of file FitParameterDelegate.cpp.

39 {
40  auto* result = createEditorFromIndex(index, parent);
41 
42  if (auto* customEditor = dynamic_cast<CustomEditor*>(result)) {
43  new TabFromFocusProxy(customEditor);
44  connect(customEditor, &CustomEditor::dataChanged, this,
46  }
47 
48  if (!result) // falling back to default behaviour
49  result = QStyledItemDelegate::createEditor(parent, option, index);
50 
51  return result;
52 }
Base class for all custom variants editors.
Definition: CustomEditors.h:29
void dataChanged(const QVariant &data)
Signal emit then user changed the data through the editor.
void onCustomEditorDataChanged(const QVariant &)
Notifies everyone that the editor has completed editing the data.
virtual QWidget * createEditorFromIndex(const QModelIndex &index, QWidget *parent) const
Propagate tab events from focusProxy to parent.

References createEditorFromIndex(), CustomEditor::dataChanged(), and onCustomEditorDataChanged().

Here is the call graph for this function:

◆ createEditorFromIndex()

QWidget * FitParameterDelegate::createEditorFromIndex ( const QModelIndex &  index,
QWidget *  parent 
) const
protectedvirtual

Definition at line 103 of file FitParameterDelegate.cpp.

105 {
106  if (index.internalPointer()) {
107  auto* item = static_cast<SessionItem*>(index.internalPointer());
109  }
110  return nullptr;
111 }
Base class for a GUI data item.
Definition: SessionItem.h:204
QWidget * CreateEditor(const SessionItem &item, QWidget *parent=nullptr)
Creates an editor suitable for editing of item.value()

References GUI::View::PropertyEditorFactory::CreateEditor().

Referenced by createEditor().

Here is the call graph for this function:

◆ onCustomEditorDataChanged

void FitParameterDelegate::onCustomEditorDataChanged ( const QVariant &  )
slot

Notifies everyone that the editor has completed editing the data.

Definition at line 115 of file FitParameterDelegate.cpp.

116 {
117  auto* editor = qobject_cast<CustomEditor*>(sender());
118  ASSERT(editor);
119  emit commitData(editor);
120 }

Referenced by createEditor().

◆ paint()

void FitParameterDelegate::paint ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Definition at line 27 of file FitParameterDelegate.cpp.

29 {
31  QString text = GUI::View::PropertyEditorFactory::toString(index);
32  paintCustomLabel(painter, option, index, text);
33  } else
34  QStyledItemDelegate::paint(painter, option, index);
35 }
void paintCustomLabel(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QString &text) const
Paints custom text in a a place corresponding given index.
QString toString(const QModelIndex &index)
Provides string representation of index data.
bool hasStringRepresentation(const QModelIndex &index)
Returns true if the index data has known (custom) conversion to string.

References GUI::View::PropertyEditorFactory::hasStringRepresentation(), paintCustomLabel(), and GUI::View::PropertyEditorFactory::toString().

Here is the call graph for this function:

◆ paintCustomLabel()

void FitParameterDelegate::paintCustomLabel ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index,
const QString &  text 
) const
private

Paints custom text in a a place corresponding given index.

Definition at line 124 of file FitParameterDelegate.cpp.

126 {
127  QStyleOptionViewItem opt = option;
128  initStyleOption(&opt, index); // calling original method to take into accounts colors etc
129  opt.text = displayText(text, option.locale); // by overriding text with ours
130  const QWidget* widget = opt.widget;
131  QStyle* style = widget ? widget->style() : QApplication::style();
132  style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
133 }

Referenced by paint().

◆ setEditorData()

void FitParameterDelegate::setEditorData ( QWidget *  editor,
const QModelIndex &  index 
) const
override

Propagates the data change from the model to the editor (if it is still opened).

Definition at line 70 of file FitParameterDelegate.cpp.

71 {
72  if (!index.isValid())
73  return;
74 
75  if (auto* customEditor = dynamic_cast<CustomEditor*>(editor))
76  customEditor->setData(index.data());
77  else
78  QStyledItemDelegate::setEditorData(editor, index);
79 }

◆ setModelData()

void FitParameterDelegate::setModelData ( QWidget *  editor,
QAbstractItemModel *  model,
const QModelIndex &  index 
) const
override

Propagates changed data from the editor to the model.

Definition at line 56 of file FitParameterDelegate.cpp.

58 {
59  if (!index.isValid())
60  return;
61 
62  if (auto* customEditor = dynamic_cast<CustomEditor*>(editor))
63  model->setData(index, customEditor->editorData());
64  else
65  QStyledItemDelegate::setModelData(editor, model, index);
66 }

◆ sizeHint()

QSize FitParameterDelegate::sizeHint ( const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Increases height of the row by 20% wrt the default.

Definition at line 83 of file FitParameterDelegate.cpp.

85 {
86  QSize result = QStyledItemDelegate::sizeHint(option, index);
87  result.setHeight(static_cast<int>(result.height() * 1.2));
88  return result;
89 }

◆ updateEditorGeometry()

void FitParameterDelegate::updateEditorGeometry ( QWidget *  editor,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Makes an editor occupying whole available space in a cell. If cell contains an icon as a decoration (i.e. icon of material property), it will be hidden as soon as editor up and running.

Definition at line 95 of file FitParameterDelegate.cpp.

97 {
98  QStyledItemDelegate::updateEditorGeometry(editor, option, index);
99  editor->setGeometry(option.rect);
100 }

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