BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SessionModelDelegate.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/SessionModelDelegate.h
6 //! @brief Defines class SessionModelDelegate
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_COREGUI_MODELS_SESSIONMODELDELEGATE_H
16 #define BORNAGAIN_GUI_COREGUI_MODELS_SESSIONMODELDELEGATE_H
17 
18 #include <QStyledItemDelegate>
19 
20 //! The SessionModelDelegate class presents the content of SessionModel items in
21 //! standard QTreeView. Extents base QItemDelegate with possibility to show/edit
22 //! our custom QVariant's.
23 
24 class SessionModelDelegate : public QStyledItemDelegate {
25  Q_OBJECT
26 public:
27  SessionModelDelegate(QObject* parent);
28 
29  void paint(QPainter* painter, const QStyleOptionViewItem& option,
30  const QModelIndex& index) const;
31 
32  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
33  const QModelIndex& index) const;
34 
35  void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
36 
37  void setEditorData(QWidget* editor, const QModelIndex& index) const;
38 
39  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
40 
41  void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option,
42  const QModelIndex& index) const;
43 
44 public slots:
45  void onCustomEditorDataChanged(const QVariant&);
46 
47 private:
48  void paintCustomLabel(QPainter* painter, const QStyleOptionViewItem& option,
49  const QModelIndex& index, const QString& text) const;
50 };
51 
52 #endif // BORNAGAIN_GUI_COREGUI_MODELS_SESSIONMODELDELEGATE_H
The SessionModelDelegate class presents the content of SessionModel items in standard QTreeView.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Increases height of the row by 20% wrt the default.
SessionModelDelegate(QObject *parent)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Propagates changed data from the editor to the model.
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Makes an editor occupying whole available space in a cell.
void onCustomEditorDataChanged(const QVariant &)
Notifies everyone that the editor has completed editing the data.
void paintCustomLabel(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QString &text) const
Paints custom text in a a place corresponding given index.
void setEditorData(QWidget *editor, const QModelIndex &index) const
Propagates the data change from the model to the editor (if it is still opened).
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const