BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ItemComboWidget Class Reference

Description

The ItemComboWidget class combines stack of widgets with QComboBox controller to switch between widgets. It is used in the case when one SessionItem can be presented with different widgets.

For example, in JobDatafieldWidget the results of the job can be presented with either IntensityDataWidget or FitDataWidget, depending from the JobView's activity type. For the presentation the special value of an empty string can be used which results in an empty widget being shown (with the toolbar hidden). In this case the current item can also be nullptr and this presentation needs not to be listed in the (active)PresentationList functions.

Definition at line 38 of file ItemComboWidget.h.

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

Public Types

using factory_function_t = std::function< SessionItemWidget *()>
 

Public Member Functions

 ItemComboWidget (QWidget *parent=nullptr)
 
virtual QList< QAction * > actionList ()
 
SessionItemcurrentItem ()
 
const SessionItemcurrentItem () const
 
void registerWidget (const QString &presentationType, factory_function_t)
 
void setItem (SessionItem *item) override
 
virtual void setPresentation (const QString &presentationType)
 Sets stack to show widget corresponding to given presentation. More...
 
void setToolbarVisible (bool value)
 

Protected Member Functions

virtual QStringList activePresentationList (SessionItem *item)
 Returns list of active presentations for given item. Active presentation is the one which is present in QComboBox selector and can be selected. For example, if JobItem is fittable, the list will contain "FitComparisonWidgetName". More...
 
void hideEvent (QHideEvent *) override
 
virtual QString itemPresentation () const
 Presentation which should be shown for current item. More...
 
virtual QStringList presentationList (SessionItem *item)
 Returns full list of presentations available for given item. More...
 
QString selectedPresentation () const
 Presentation selected in combo selector. More...
 
void showEvent (QShowEvent *) override
 
void subscribeToItem () override
 
virtual void unsubscribeFromItem ()
 

Private Slots

void onComboChanged (const QString &name)
 

Private Member Functions

void setSizeToCurrentWidget ()
 Resizes QStackedWidget to currently active page. More...
 

Private Attributes

QWidget * m_blankWidget
 
SessionItemControllerm_itemController
 
QMap< QString, SessionItemWidget * > m_presentationTypeToWidget
 
QStackedWidget * m_stackedWidget
 
ItemComboToolbarm_toolbar
 
IFactory< QString, SessionItemWidgetm_widgetFactory
 

Member Typedef Documentation

◆ factory_function_t

Definition at line 42 of file ItemComboWidget.h.

Constructor & Destructor Documentation

◆ ItemComboWidget()

ItemComboWidget::ItemComboWidget ( QWidget *  parent = nullptr)
explicit

Definition at line 21 of file ItemComboWidget.cpp.

22  : SessionItemWidget(parent)
24  , m_stackedWidget(new QStackedWidget)
25 {
26  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
27  m_stackedWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
28  m_blankWidget = new QWidget;
29  m_stackedWidget->addWidget(m_blankWidget);
30 
31  auto* layout = new QVBoxLayout;
32  layout->setMargin(0);
33  layout->setSpacing(0);
34  layout->setContentsMargins(0, 0, 0, 0);
35  layout->addWidget(m_toolbar);
36  layout->addWidget(m_stackedWidget);
37  setLayout(layout);
38 
40 
41  setToolbarVisible(false);
42 }
The ItemComboToolbar class is a styled toolbar on top of ItemComboWidget. Contains ComboBox to switch...
void comboChanged(const QString &presentation)
QWidget * m_blankWidget
QStackedWidget * m_stackedWidget
ItemComboToolbar * m_toolbar
void onComboChanged(const QString &name)
void setToolbarVisible(bool value)
SessionItemWidget(QWidget *parent=nullptr)

References ItemComboToolbar::comboChanged(), m_blankWidget, m_stackedWidget, m_toolbar, onComboChanged(), and setToolbarVisible().

Here is the call graph for this function:

Member Function Documentation

◆ actionList()

QList< QAction * > SessionItemWidget::actionList ( )
virtualinherited

◆ activePresentationList()

QStringList ItemComboWidget::activePresentationList ( SessionItem item)
protectedvirtual

Returns list of active presentations for given item. Active presentation is the one which is present in QComboBox selector and can be selected. For example, if JobItem is fittable, the list will contain "FitComparisonWidgetName".

Reimplemented in JobResultsPresenter, and RealDataPresenter.

Definition at line 100 of file ItemComboWidget.cpp.

101 {
102  Q_UNUSED(item);
103  return QStringList();
104 }

Referenced by presentationList(), setPresentation(), and subscribeToItem().

◆ currentItem() [1/2]

◆ currentItem() [2/2]

const SessionItem * SessionItemWidget::currentItem ( ) const
inherited

Definition at line 46 of file SessionItemWidget.cpp.

47 {
48  return m_itemController->currentItem();
49 }
SessionItemController * m_itemController

References SessionItemController::currentItem(), and SessionItemWidget::m_itemController.

Here is the call graph for this function:

◆ hideEvent()

void SessionItemWidget::hideEvent ( QHideEvent *  )
overrideprotectedinherited

Definition at line 56 of file SessionItemWidget.cpp.

57 {
59 }
void unsubscribe()
Fully unsubscribes the parent from listening item's signals. Controller stays active to track item de...

References SessionItemWidget::m_itemController, and SessionItemController::unsubscribe().

Here is the call graph for this function:

◆ itemPresentation()

QString ItemComboWidget::itemPresentation ( ) const
protectedvirtual

Presentation which should be shown for current item.

Reimplemented in JobResultsPresenter.

Definition at line 115 of file ItemComboWidget.cpp.

116 {
117  return selectedPresentation();
118 }
QString selectedPresentation() const
Presentation selected in combo selector.

References selectedPresentation().

Referenced by setItem(), and subscribeToItem().

Here is the call graph for this function:

◆ onComboChanged

void ItemComboWidget::onComboChanged ( const QString &  name)
privateslot

Definition at line 134 of file ItemComboWidget.cpp.

135 {
137 }
virtual void setPresentation(const QString &presentationType)
Sets stack to show widget corresponding to given presentation.

References selectedPresentation(), and setPresentation().

Referenced by ItemComboWidget().

Here is the call graph for this function:

◆ presentationList()

QStringList ItemComboWidget::presentationList ( SessionItem item)
protectedvirtual

Returns full list of presentations available for given item.

Reimplemented in JobResultsPresenter.

Definition at line 108 of file ItemComboWidget.cpp.

109 {
110  return activePresentationList(item);
111 }
virtual QStringList activePresentationList(SessionItem *item)
Returns list of active presentations for given item. Active presentation is the one which is present ...

References activePresentationList().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ registerWidget()

void ItemComboWidget::registerWidget ( const QString &  presentationType,
factory_function_t  f 
)

Definition at line 44 of file ItemComboWidget.cpp.

45 {
46  m_widgetFactory.registerItem(presentationType, f);
47 }
IFactory< QString, SessionItemWidget > m_widgetFactory

References m_widgetFactory.

Referenced by JobResultsPresenter::JobResultsPresenter(), and RealDataPresenter::RealDataPresenter().

◆ selectedPresentation()

QString ItemComboWidget::selectedPresentation ( ) const
protected

Presentation selected in combo selector.

Definition at line 122 of file ItemComboWidget.cpp.

123 {
124  return m_toolbar->currentPresentation();
125 }
QString currentPresentation() const

References ItemComboToolbar::currentPresentation(), and m_toolbar.

Referenced by itemPresentation(), JobResultsPresenter::itemPresentation(), and onComboChanged().

Here is the call graph for this function:

◆ setItem()

void ItemComboWidget::setItem ( SessionItem item)
overridevirtual

Reimplemented from SessionItemWidget.

Reimplemented in JobResultsPresenter.

Definition at line 88 of file ItemComboWidget.cpp.

89 {
90  if (!item)
91  m_stackedWidget->setCurrentWidget(m_blankWidget);
93  setToolbarVisible(item && !itemPresentation().isEmpty());
94 }
virtual QString itemPresentation() const
Presentation which should be shown for current item.
virtual void setItem(SessionItem *item)

References itemPresentation(), m_blankWidget, m_stackedWidget, SessionItemWidget::setItem(), and setToolbarVisible().

Referenced by JobResultsPresenter::setItem().

Here is the call graph for this function:

◆ setPresentation()

void ItemComboWidget::setPresentation ( const QString &  presentationType)
virtual

Sets stack to show widget corresponding to given presentation.

Reimplemented in JobResultsPresenter.

Definition at line 50 of file ItemComboWidget.cpp.

51 {
52  if (presentationType.isEmpty()) {
53  m_stackedWidget->setCurrentWidget(m_blankWidget);
54  setToolbarVisible(false);
55  return;
56  }
57 
58  if (!activePresentationList(currentItem()).contains(presentationType))
59  return;
60 
61  setToolbarVisible(true);
62  m_toolbar->setPresentation(presentationType);
63 
64  ASSERT(currentItem());
65 
66  SessionItemWidget* widget = m_presentationTypeToWidget[presentationType];
67 
68  if (!widget) {
69  widget = m_widgetFactory.createItemPtr(presentationType).release();
70  m_stackedWidget->addWidget(widget);
71  m_presentationTypeToWidget[presentationType] = widget;
72  }
73  ASSERT(widget);
74  widget->setItem(currentItem());
76  m_stackedWidget->setCurrentWidget(widget);
77  if (widget->isHidden())
78  widget->show();
79 
81 }
void setPresentation(const QString &name)
void setActionList(const QList< QAction * > &actionList)
Sets external actions to tool bar (previous actions will be removed).
QMap< QString, SessionItemWidget * > m_presentationTypeToWidget
void setSizeToCurrentWidget()
Resizes QStackedWidget to currently active page.
virtual QList< QAction * > actionList()

References SessionItemWidget::actionList(), activePresentationList(), SessionItemWidget::currentItem(), m_blankWidget, m_presentationTypeToWidget, m_stackedWidget, m_toolbar, m_widgetFactory, ItemComboToolbar::setActionList(), SessionItemWidget::setItem(), ItemComboToolbar::setPresentation(), setSizeToCurrentWidget(), and setToolbarVisible().

Referenced by onComboChanged(), JobResultsPresenter::setPresentation(), and subscribeToItem().

Here is the call graph for this function:

◆ setSizeToCurrentWidget()

void ItemComboWidget::setSizeToCurrentWidget ( )
private

Resizes QStackedWidget to currently active page.

Definition at line 141 of file ItemComboWidget.cpp.

142 {
143  for (int i = 0; i < m_stackedWidget->count(); ++i) {
144  // determine the vertical size policy
145  QSizePolicy::Policy policy = QSizePolicy::Ignored;
146  if (i == m_stackedWidget->currentIndex())
147  policy = QSizePolicy::Expanding;
148 
149  // update the size policy
150  auto* page = m_stackedWidget->widget(i);
151  page->setSizePolicy(policy, policy);
152  }
153 }

References m_stackedWidget.

Referenced by setPresentation().

◆ setToolbarVisible()

void ItemComboWidget::setToolbarVisible ( bool  value)

Definition at line 83 of file ItemComboWidget.cpp.

84 {
85  m_toolbar->setVisible(value);
86 }

References m_toolbar.

Referenced by ItemComboWidget(), setItem(), and setPresentation().

◆ showEvent()

void SessionItemWidget::showEvent ( QShowEvent *  )
overrideprotectedinherited

Definition at line 51 of file SessionItemWidget.cpp.

52 {
54 }
void subscribe()
Subscribe parent to item's signals.

References SessionItemWidget::m_itemController, and SessionItemController::subscribe().

Here is the call graph for this function:

◆ subscribeToItem()

void ItemComboWidget::subscribeToItem ( )
overrideprotectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 127 of file ItemComboWidget.cpp.

128 {
132 }
void setPresentationList(const QStringList &presentationList, const QStringList &activeList={})
virtual QStringList presentationList(SessionItem *item)
Returns full list of presentations available for given item.

References activePresentationList(), SessionItemWidget::currentItem(), itemPresentation(), m_toolbar, presentationList(), setPresentation(), and ItemComboToolbar::setPresentationList().

Here is the call graph for this function:

◆ unsubscribeFromItem()

virtual void SessionItemWidget::unsubscribeFromItem ( )
inlineprotectedvirtualinherited

Member Data Documentation

◆ m_blankWidget

QWidget* ItemComboWidget::m_blankWidget
private

Definition at line 70 of file ItemComboWidget.h.

Referenced by ItemComboWidget(), setItem(), and setPresentation().

◆ m_itemController

◆ m_presentationTypeToWidget

QMap<QString, SessionItemWidget*> ItemComboWidget::m_presentationTypeToWidget
private

Definition at line 69 of file ItemComboWidget.h.

Referenced by setPresentation().

◆ m_stackedWidget

QStackedWidget* ItemComboWidget::m_stackedWidget
private

◆ m_toolbar

ItemComboToolbar* ItemComboWidget::m_toolbar
private

◆ m_widgetFactory

IFactory<QString, SessionItemWidget> ItemComboWidget::m_widgetFactory
private

Definition at line 68 of file ItemComboWidget.h.

Referenced by registerWidget(), and setPresentation().


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