BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ItemSelectorWidget.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/CommonWidgets/ItemSelectorWidget.h
6 //! @brief Defines class ItemSelectorWidget
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_VIEWS_COMMONWIDGETS_ITEMSELECTORWIDGET_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_COMMONWIDGETS_ITEMSELECTORWIDGET_H
17 
18 #include <QItemSelectionModel>
19 #include <QWidget>
20 #include <memory>
21 
22 class SessionModel;
23 class SessionItem;
24 class QItemSelection;
25 class QModelIndex;
26 class QAbstractItemDelegate;
27 class QListView;
29 
30 //! The ItemSelectorWidget class holds QListView to show top level items of SessionModel.
31 //! Used in InstrumentView and JobSelectorView to switch between items.
32 
33 class ItemSelectorWidget : public QWidget {
34  Q_OBJECT
35 
36 public:
37  ItemSelectorWidget(QWidget* parent = 0);
39 
40  QSize sizeHint() const;
41  QSize minimumSizeHint() const;
42 
43  void setModel(SessionModel* model);
44  void setItemDelegate(QAbstractItemDelegate* delegate);
45 
46  QItemSelectionModel* selectionModel();
47  QListView* listView();
48 
49 public slots:
50  void select(const QModelIndex& index, QItemSelectionModel::SelectionFlags command);
51  void updateSelection();
52  void selectLast();
53 
54 signals:
56  void contextMenuRequest(const QPoint& point, const QModelIndex& index);
57 
58 private slots:
59  void onSelectionChanged(const QItemSelection& selected, const QItemSelection&);
60  void onCustomContextMenuRequested(const QPoint& point);
61 
62 protected:
63  void connectModel();
64  void disconnectModel();
65  void showEvent(class QShowEvent*);
66 
67  QListView* m_listView;
69  std::unique_ptr<SessionDecorationModel> m_decorationModel;
70 };
71 
72 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_COMMONWIDGETS_ITEMSELECTORWIDGET_H
The ItemSelectorWidget class holds QListView to show top level items of SessionModel.
QSize minimumSizeHint() const
void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
ItemSelectorWidget(QWidget *parent=0)
QItemSelectionModel * selectionModel()
void setItemDelegate(QAbstractItemDelegate *delegate)
void contextMenuRequest(const QPoint &point, const QModelIndex &index)
void showEvent(class QShowEvent *)
provide default selection when widget is shown
std::unique_ptr< SessionDecorationModel > m_decorationModel
void onCustomContextMenuRequested(const QPoint &point)
void updateSelection()
select last item if no selection exists
void setModel(SessionModel *model)
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &)
void selectionChanged(SessionItem *item)
SessionModel * m_model
Provides decorations (text color, icons, etc) for SessionModel in SessionModelView context.