BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
viewmodeldelegate.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/viewmodel/mvvm/viewmodel/viewmodeldelegate.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_VIEWMODEL_MVVM_VIEWMODEL_VIEWMODELDELEGATE_H
16 #define BORNAGAIN_MVVM_VIEWMODEL_MVVM_VIEWMODEL_VIEWMODELDELEGATE_H
17 
18 #include "mvvm/viewmodel_export.h"
19 #include <QStyledItemDelegate>
20 #include <memory>
21 
22 namespace ModelView {
23 
24 class EditorFactoryInterface;
25 class CellDecoratorInterface;
26 
27 //! Model delegate to provide editing/painting for custom variants.
28 
29 class MVVM_VIEWMODEL_EXPORT ViewModelDelegate : public QStyledItemDelegate {
30  Q_OBJECT
31 
32 public:
33  explicit ViewModelDelegate(QObject* parent = nullptr);
34  ~ViewModelDelegate() override;
35 
36  void setEditorFactory(std::unique_ptr<EditorFactoryInterface> editor_factory);
37  void setCellDecoration(std::unique_ptr<CellDecoratorInterface> cell_decoration);
38 
39  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
40  const QModelIndex& index) const override;
41 
42  void setEditorData(QWidget* editor, const QModelIndex& index) const override;
43  void setModelData(QWidget* editor, QAbstractItemModel* model,
44  const QModelIndex& index) const override;
45 
46  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
47 
48  void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option,
49  const QModelIndex& index) const override;
50 
51 public slots:
52  void onCustomEditorDataChanged();
53 
54 protected:
55  void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const override;
56 
57  std::unique_ptr<EditorFactoryInterface> m_editor_factory;
58  std::unique_ptr<CellDecoratorInterface> m_cell_decoration;
59 };
60 
61 } // namespace ModelView
62 
63 #endif // BORNAGAIN_MVVM_VIEWMODEL_MVVM_VIEWMODEL_VIEWMODELDELEGATE_H
Model delegate to provide editing/painting for custom variants.
std::unique_ptr< EditorFactoryInterface > m_editor_factory
std::unique_ptr< CellDecoratorInterface > m_cell_decoration
materialitems.h Collection of materials to populate MaterialModel.