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

The ItemComboWidget class combines stack of widgets with QComboBox controller to switch between widgets. More...

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=0)
 
virtual QList< QAction * > actionList ()
 
SessionItemcurrentItem ()
 
const SessionItemcurrentItem () const
 
void registerWidget (const QString &presentationType, factory_function_t)
 
virtual void setItem (SessionItem *item)
 
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. More...
 
virtual void hideEvent (QHideEvent *)
 
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...
 
virtual void showEvent (QShowEvent *)
 
void subscribeToItem ()
 
virtual void unsubscribeFromItem ()
 

Private Slots

void onComboChanged (const QString &name)
 

Private Member Functions

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

Private Attributes

SessionItemControllerm_itemController
 
QMap< QString, SessionItemWidget * > m_presentationTypeToWidget
 
QStackedWidget * m_stackedWidget
 
ItemComboToolBarm_toolBar
 
IFactory< QString, SessionItemWidgetm_widgetFactory
 

Detailed 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 JobOutputDataWidget the results of the job can be presented with either IntensityDataWidget or FitDataWidget, depending from the JobView's activity type.

Definition at line 35 of file ItemComboWidget.h.

Member Typedef Documentation

◆ factory_function_t

Definition at line 39 of file ItemComboWidget.h.

Constructor & Destructor Documentation

◆ ItemComboWidget()

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

Definition at line 24 of file ItemComboWidget.cpp.

25  : SessionItemWidget(parent)
27  , m_stackedWidget(new QStackedWidget)
28 {
29  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
30  m_stackedWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
31 
32  QVBoxLayout* layout = new QVBoxLayout;
33  layout->setMargin(0);
34  layout->setSpacing(0);
35  layout->setContentsMargins(0, 0, 0, 0);
36  layout->addWidget(m_toolBar);
37  layout->addWidget(m_stackedWidget);
38  setLayout(layout);
39 
41 }
The ItemComboToolBar class is a styled toolbar on top of ItemComboWidget.
void comboChanged(const QString &presentation)
QStackedWidget * m_stackedWidget
ItemComboToolBar * m_toolBar
void onComboChanged(const QString &name)
SessionItemWidget(QWidget *parent=0)

References ItemComboToolBar::comboChanged(), m_stackedWidget, m_toolBar, and onComboChanged().

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, InstrumentPresenter, DetectorPresenter, and RealDataPresenter.

Definition at line 85 of file ItemComboWidget.cpp.

86 {
87  Q_UNUSED(item);
88  return QStringList();
89 }

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

◆ currentItem() [1/2]

SessionItem * SessionItemWidget::currentItem ( )
inherited

Definition at line 41 of file SessionItemWidget.cpp.

42 {
43  return const_cast<SessionItem*>(static_cast<const SessionItemWidget*>(this)->currentItem());
44 }
The SessionItemWidget class is a base for all widgets representing the content of SessionItem.
SessionItem * currentItem()

Referenced by RectangularDetectorEditor::detectorItem(), SphericalDetectorEditor::detectorItem(), FitFlowWidget::fitSuiteItem(), DistributionEditor::groupItem(), DepthProbeInstrumentEditor::instrumentItem(), EnvironmentEditor::instrumentItem(), GISASBeamEditor::instrumentItem(), GISASDetectorEditor::instrumentItem(), GISASInstrumentEditor::instrumentItem(), OffSpecularBeamEditor::instrumentItem(), OffSpecularInstrumentEditor::instrumentItem(), PolarizationAnalysisEditor::instrumentItem(), SpecularBeamEditor::instrumentItem(), SpecularInstrumentEditor::instrumentItem(), RealDataMaskWidget::intensityDataItem(), IntensityDataCanvas::intensityDataItem(), IntensityDataProjectionsWidget::intensityDataItem(), IntensityDataWidget::intensityDataItem(), ProjectionsPlot::intensityItem(), ColorMap::intensityItem(), DetectorPresenter::itemPresentation(), InstrumentPresenter::itemPresentation(), JobResultsPresenter::itemPresentation(), FitComparisonWidget::jobItem(), FitComparisonWidget1D::jobItem(), FitParameterWidget::jobItem(), RunFitControlWidget::jobItem(), JobPropertiesWidget::jobItem(), ParameterTuningWidget::jobItem(), SpecularDataImportWidget::realDataItem(), setPresentation(), JobResultsPresenter::setPresentation(), SpecularDataCanvas::specularDataItem(), SpecularDataImportWidget::specularDataItem(), SpecularDataWidget::specularDataItem(), SpecularPlot::specularItem(), subscribeToItem(), DistributionEditor::subscribeToItem(), GISASDetectorEditor::subscribeToItem(), PolarizationAnalysisEditor::subscribeToItem(), IntensityDataPropertyWidget::subscribeToItem(), JobPropertiesWidget::subscribeToItem(), ProjectionsPropertyPanel::subscribeToItem(), ProjectionsPlot::unsubscribeFromChildren(), and Plot1D::viewItem().

◆ 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 *  )
protectedvirtualinherited

Definition at line 56 of file SessionItemWidget.cpp.

57 {
59 }
void unsubscribe()
Fully unsubscribes the parent from listening item's signals.

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, InstrumentPresenter, and DetectorPresenter.

Definition at line 100 of file ItemComboWidget.cpp.

101 {
102  return selectedPresentation();
103 }
QString selectedPresentation() const
Presentation selected in combo selector.

References selectedPresentation().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ onComboChanged

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

Definition at line 119 of file ItemComboWidget.cpp.

120 {
122 }
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 93 of file ItemComboWidget.cpp.

94 {
95  return activePresentationList(item);
96 }
virtual QStringList activePresentationList(SessionItem *item)
Returns list of active presentations for given item.

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 43 of file ItemComboWidget.cpp.

44 {
45  m_widgetFactory.registerItem(presentationType, f);
46 }
bool registerItem(const Key &item_key, CreateItemCallback CreateFn)
Registers object's creation function.
Definition: IFactory.h:53
IFactory< QString, SessionItemWidget > m_widgetFactory

References m_widgetFactory, and IFactory< Key, AbstractProduct >::registerItem().

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

Here is the call graph for this function:

◆ selectedPresentation()

QString ItemComboWidget::selectedPresentation ( ) const
protected

Presentation selected in combo selector.

Definition at line 107 of file ItemComboWidget.cpp.

108 {
109  return m_toolBar->currentPresentation();
110 }
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 SessionItemWidget::setItem ( SessionItem item)
virtualinherited

Reimplemented in SpecularPlotCanvas, SpecularDataImportWidget, SpecularDataWidget, IntensityDataWidget, SpecularDataCanvas, ProjectionsWidget, IntensityDataCanvas, ColorMapCanvas, and Plot1DCanvas.

Definition at line 28 of file SessionItemWidget.cpp.

29 {
31 
32  if (isVisible())
34 }
void setItem(SessionItem *item)
void subscribe()
Subscribe parent to item's signals.

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

Referenced by IntensityDataWidget::onFFTAction(), JobSelectorWidget::onSelectionChanged(), ProjectionsEditor::resetContext(), ProjectionsEditor::setContext(), MaskGraphicsProxy::setIntensityItem(), FitSessionWidget::setItem(), Plot1DCanvas::setItem(), InstrumentEditorWidget::setItem(), ColorMapCanvas::setItem(), IntensityDataCanvas::setItem(), ProjectionsWidget::setItem(), SpecularDataCanvas::setItem(), DistributionDialog::setItem(), IntensityDataWidget::setItem(), SpecularDataWidget::setItem(), SpecularDataImportWidget::setItem(), SpecularPlotCanvas::setItem(), setPresentation(), GISASInstrumentEditor::subscribeToItem(), OffSpecularInstrumentEditor::subscribeToItem(), SpecularInstrumentEditor::subscribeToItem(), FitComparisonWidget::subscribeToItem(), FitComparisonWidget1D::subscribeToItem(), and GISASDetectorEditor::updateDetectorPresenter().

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 (!activePresentationList(currentItem()).contains(presentationType))
53  return;
54 
55  m_toolBar->setPresentation(presentationType);
56 
58 
59  SessionItemWidget* widget = m_presentationTypeToWidget[presentationType];
60 
61  if (!widget) {
62  widget = m_widgetFactory.createItemPtr(presentationType).release();
63  m_stackedWidget->addWidget(widget);
64  m_presentationTypeToWidget[presentationType] = widget;
65  }
66  ASSERT(widget);
67  widget->setItem(currentItem());
69  m_stackedWidget->setCurrentWidget(widget);
70  if (widget->isHidden())
71  widget->show();
72 
74 }
#define ASSERT(condition)
Definition: Assert.h:31
std::unique_ptr< AbstractProduct > createItemPtr(const Key &item_key) const
Definition: IFactory.h:46
void setActionList(const QList< QAction * > &actionList)
Sets external actions to tool bar (previous actions will be removed).
void setPresentation(const QString &name)
QMap< QString, SessionItemWidget * > m_presentationTypeToWidget
void setSizeToCurrentWidget()
Resizes QStackedWidget to currently active page.
virtual QList< QAction * > actionList()
virtual void setItem(SessionItem *item)

References SessionItemWidget::actionList(), activePresentationList(), ASSERT, IFactory< Key, AbstractProduct >::createItemPtr(), SessionItemWidget::currentItem(), m_presentationTypeToWidget, m_stackedWidget, m_toolBar, m_widgetFactory, ItemComboToolBar::setActionList(), SessionItemWidget::setItem(), ItemComboToolBar::setPresentation(), and setSizeToCurrentWidget().

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 126 of file ItemComboWidget.cpp.

127 {
128  for (int i = 0; i < m_stackedWidget->count(); ++i) {
129  // determine the vertical size policy
130  QSizePolicy::Policy policy = QSizePolicy::Ignored;
131  if (i == m_stackedWidget->currentIndex())
132  policy = QSizePolicy::Expanding;
133 
134  // update the size policy
135  auto page = m_stackedWidget->widget(i);
136  page->setSizePolicy(policy, policy);
137  }
138 }

References m_stackedWidget.

Referenced by setPresentation().

◆ setToolBarVisible()

void ItemComboWidget::setToolBarVisible ( bool  value)

Definition at line 76 of file ItemComboWidget.cpp.

77 {
78  m_toolBar->setVisible(value);
79 }

References m_toolBar.

Referenced by DetectorPresenter::DetectorPresenter(), and InstrumentPresenter::InstrumentPresenter().

◆ showEvent()

void SessionItemWidget::showEvent ( QShowEvent *  )
protectedvirtualinherited

Definition at line 51 of file SessionItemWidget.cpp.

52 {
54 }

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

Here is the call graph for this function:

◆ subscribeToItem()

void ItemComboWidget::subscribeToItem ( )
protectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 112 of file ItemComboWidget.cpp.

113 {
117 }
void setPresentationList(const QStringList &presentationList, const QStringList &activeList={})
virtual QStringList presentationList(SessionItem *item)
Returns full list of presentations available for given item.
virtual QString itemPresentation() const
Presentation which should be shown for current item.

References activePresentationList(), SessionItemWidget::currentItem(), itemPresentation(), m_toolBar, presentationList(), setPresentation(), and ItemComboToolBar::setPresentationList().

Here is the call graph for this function:

◆ unsubscribeFromItem()

Member Data Documentation

◆ m_itemController

◆ m_presentationTypeToWidget

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

Definition at line 68 of file ItemComboWidget.h.

Referenced by setPresentation().

◆ m_stackedWidget

QStackedWidget* ItemComboWidget::m_stackedWidget
private

Definition at line 65 of file ItemComboWidget.h.

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

◆ m_toolBar

ItemComboToolBar* ItemComboWidget::m_toolBar
private

◆ m_widgetFactory

IFactory<QString, SessionItemWidget> ItemComboWidget::m_widgetFactory
private

Definition at line 67 of file ItemComboWidget.h.

Referenced by registerWidget(), and setPresentation().


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