BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ItemComboWidget.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Common/ItemComboWidget.h
6 //! @brief Defines class ItemComboWidget
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_VIEW_COMMON_ITEMCOMBOWIDGET_H
16 #define BORNAGAIN_GUI_VIEW_COMMON_ITEMCOMBOWIDGET_H
17 
18 #include "Base/Util/IFactory.h"
20 #include <QMap>
21 
22 class SessionItem;
23 class SessionItemWidget;
24 class ItemComboToolbar;
25 class QStackedWidget;
26 
27 //! The ItemComboWidget class combines stack of widgets with QComboBox controller to switch between
28 //! widgets. It is used in the case when one SessionItem can be presented with different widgets.
29 
30 //! For example, in JobDatafieldWidget the results of the job can be presented with either
31 //! IntensityDataWidget or FitDataWidget, depending from the JobView's activity type.
32 
33 //! For the presentation the special value of an empty string can be used which results in an
34 //! empty widget being shown (with the toolbar hidden). In this case the current item can also
35 //! be \c nullptr and this presentation needs not to be listed in the (active)PresentationList
36 //! functions.
37 
39  Q_OBJECT
40 
41 public:
42  using factory_function_t = std::function<SessionItemWidget*()>;
43 
44  explicit ItemComboWidget(QWidget* parent = nullptr);
45 
46  void registerWidget(const QString& presentationType, factory_function_t);
47 
48  virtual void setPresentation(const QString& presentationType);
49 
50  void setToolbarVisible(bool value);
51  void setItem(SessionItem* item) override;
52 
53 protected:
54  virtual QStringList activePresentationList(SessionItem* item);
55  virtual QStringList presentationList(SessionItem* item);
56  virtual QString itemPresentation() const;
57  QString selectedPresentation() const;
58  void subscribeToItem() override;
59 
60 private slots:
61  void onComboChanged(const QString& name);
62 
63 private:
65 
67  QStackedWidget* m_stackedWidget;
68  IFactory<QString, SessionItemWidget> m_widgetFactory;
69  QMap<QString, SessionItemWidget*> m_presentationTypeToWidget;
70  QWidget* m_blankWidget;
71 };
72 
73 #endif // BORNAGAIN_GUI_VIEW_COMMON_ITEMCOMBOWIDGET_H
Defines class ItemComboWidget.
The ItemComboToolbar class is a styled toolbar on top of ItemComboWidget. Contains ComboBox to switch...
The ItemComboWidget class combines stack of widgets with QComboBox controller to switch between widge...
QMap< QString, SessionItemWidget * > m_presentationTypeToWidget
QWidget * m_blankWidget
QStackedWidget * m_stackedWidget
ItemComboWidget(QWidget *parent=nullptr)
ItemComboToolbar * m_toolbar
std::function< SessionItemWidget *()> factory_function_t
void setItem(SessionItem *item) override
QString selectedPresentation() const
Presentation selected in combo selector.
virtual void setPresentation(const QString &presentationType)
Sets stack to show widget corresponding to given presentation.
void onComboChanged(const QString &name)
virtual QStringList activePresentationList(SessionItem *item)
Returns list of active presentations for given item. Active presentation is the one which is present ...
virtual QStringList presentationList(SessionItem *item)
Returns full list of presentations available for given item.
void subscribeToItem() override
IFactory< QString, SessionItemWidget > m_widgetFactory
virtual QString itemPresentation() const
Presentation which should be shown for current item.
void registerWidget(const QString &presentationType, factory_function_t)
void setSizeToCurrentWidget()
Resizes QStackedWidget to currently active page.
void setToolbarVisible(bool value)
The SessionItemWidget class is a base for all widgets representing the content of SessionItem....
Base class for a GUI data item.
Definition: SessionItem.h:204
QString const & name(EShape k)
Definition: particles.cpp:20