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

The SessionModelDelegate class presents the content of SessionModel items in standard QTreeView. More...

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

Public Slots

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

Public Member Functions

 SessionModelDelegate (QObject *parent)
 
QWidget * createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
void setEditorData (QWidget *editor, const QModelIndex &index) const
 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
 Propagates changed data from the editor to the model. More...
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
 Increases height of the row by 20% wrt the default. More...
 
void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Makes an editor occupying whole available space in a cell. More...
 

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...
 

Detailed Description

The SessionModelDelegate 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 SessionModelDelegate.h.

Constructor & Destructor Documentation

◆ SessionModelDelegate()

SessionModelDelegate::SessionModelDelegate ( QObject *  parent)

Definition at line 26 of file SessionModelDelegate.cpp.

26 : QStyledItemDelegate(parent) {}

Member Function Documentation

◆ createEditor()

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

Definition at line 38 of file SessionModelDelegate.cpp.

40 {
41  auto result = createEditorFromIndex(index, parent);
42 
43  if (auto customEditor = dynamic_cast<CustomEditor*>(result)) {
44  new TabFromFocusProxy(customEditor);
45  connect(customEditor, &CustomEditor::dataChanged, this,
47  }
48 
49  if (!result) // falling back to default behaviour
50  result = QStyledItemDelegate::createEditor(parent, option, index);
51 
52  return result;
53 }
Base class for all custom variants editors.
Definition: CustomEditors.h:28
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.
Propagate tab events from focusProxy to parent.

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

Here is the call graph for this function:

◆ onCustomEditorDataChanged

void SessionModelDelegate::onCustomEditorDataChanged ( const QVariant &  )
slot

Notifies everyone that the editor has completed editing the data.

Definition at line 105 of file SessionModelDelegate.cpp.

106 {
107  CustomEditor* editor = qobject_cast<CustomEditor*>(sender());
108  ASSERT(editor);
109  emit commitData(editor);
110 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT.

Referenced by PropertyWidgetItem::connectEditor(), and createEditor().

◆ paint()

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

Definition at line 28 of file SessionModelDelegate.cpp.

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

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

Here is the call graph for this function:

◆ paintCustomLabel()

void SessionModelDelegate::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 114 of file SessionModelDelegate.cpp.

116 {
117  QStyleOptionViewItem opt = option;
118  initStyleOption(&opt, index); // calling original method to take into accounts colors etc
119  opt.text = displayText(text, option.locale); // by overriding text with ours
120  const QWidget* widget = opt.widget;
121  QStyle* style = widget ? widget->style() : QApplication::style();
122  style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
123 }

Referenced by paint().

◆ setEditorData()

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

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

Definition at line 71 of file SessionModelDelegate.cpp.

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

Referenced by PropertyWidgetItem::setItemEditor().

◆ setModelData()

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

Propagates changed data from the editor to the model.

Definition at line 57 of file SessionModelDelegate.cpp.

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

◆ sizeHint()

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

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

Definition at line 84 of file SessionModelDelegate.cpp.

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

◆ updateEditorGeometry()

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

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 96 of file SessionModelDelegate.cpp.

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

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