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

Description

Presents results of job (JobItem) using stack of different widgets and combo box in the right top corner of JobView, to switch between widgets.

Definition at line 27 of file JobResultsPresenter.h.

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

Public Types

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

Public Slots

void setPresentation (JobViewActivity activity)
 

Public Member Functions

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

Protected Member Functions

QStringList activePresentationList (SessionItem *item) override
 Returns list of presentation types, available for given item. JobItem with fitting abilities is valid for IntensityDataWidget and FitComparisonWidget. More...
 
void hideEvent (QHideEvent *) override
 
QString itemPresentation () const override
 Presentation which should be shown for current item. More...
 
QStringList presentationList (SessionItem *item) override
 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

QStringList defaultActivePresentationsOfInstrument (InstrumentItem *instrumentItem)
 
QString defaultPresentationOfInstrument (InstrumentItem *instrumentItem)
 
QString fitPresentationOfInstrument (InstrumentItem *instrumentItem)
 
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

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

Definition at line 42 of file ItemComboWidget.h.

Constructor & Destructor Documentation

◆ JobResultsPresenter()

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

Definition at line 25 of file JobResultsPresenter.cpp.

26  : ItemComboWidget(parent)
27 {
28  setWindowTitle("Job Datafield");
29  setObjectName("JobResultsPresenter");
30 
31  registerWidget("Heat Map", create_new<IntensityDataWidget>);
32  registerWidget("Projections", create_new<IntensityDataProjectionsWidget>);
33  registerWidget("Fit 1D Data", create_new<FitComparisonWidget1D>);
34  registerWidget("Fit 2D Data", create_new<FitComparisonWidget>);
35  registerWidget("Reflectometry", create_new<SpecularDataWidget>);
36 
37  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
38  setMinimumSize(600, 600);
39 }
ItemComboWidget(QWidget *parent=nullptr)
void registerWidget(const QString &presentationType, factory_function_t)

References ItemComboWidget::registerWidget().

Here is the call graph for this function:

Member Function Documentation

◆ actionList()

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

◆ activePresentationList()

QStringList JobResultsPresenter::activePresentationList ( SessionItem item)
overrideprotectedvirtual

Returns list of presentation types, available for given item. JobItem with fitting abilities is valid for IntensityDataWidget and FitComparisonWidget.

Reimplemented from ItemComboWidget.

Definition at line 85 of file JobResultsPresenter.cpp.

86 {
87  auto* jobItem = dynamic_cast<JobItem*>(item);
88  if (!jobItem || jobItem->isRunning())
89  return {};
90 
91  ASSERT(jobItem->instrumentItem() != nullptr);
92 
93  auto result = defaultActivePresentationsOfInstrument(jobItem->instrumentItem());
94 
95  if (jobItem->isValidForFitting())
96  result << fitPresentationOfInstrument(jobItem->instrumentItem());
97 
98  return result;
99 }
QStringList defaultActivePresentationsOfInstrument(InstrumentItem *instrumentItem)
QString fitPresentationOfInstrument(InstrumentItem *instrumentItem)

References defaultActivePresentationsOfInstrument(), and fitPresentationOfInstrument().

Here is the call graph for this function:

◆ 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:

◆ defaultActivePresentationsOfInstrument()

QStringList JobResultsPresenter::defaultActivePresentationsOfInstrument ( InstrumentItem instrumentItem)
private

Definition at line 126 of file JobResultsPresenter.cpp.

127 {
128  if (instrumentItem->is<SpecularInstrumentItem>())
129  return {"Reflectometry"};
130 
131  return {"Heat Map", "Projections"};
132 }
bool is() const

References InstrumentItem::is().

Referenced by activePresentationList(), and presentationList().

Here is the call graph for this function:

◆ defaultPresentationOfInstrument()

QString JobResultsPresenter::defaultPresentationOfInstrument ( InstrumentItem instrumentItem)
private

Definition at line 117 of file JobResultsPresenter.cpp.

118 {
119  if (instrumentItem->is<SpecularInstrumentItem>())
120  return "Reflectometry";
121 
122  return "Heat Map";
123 }

References InstrumentItem::is().

Referenced by setPresentation().

Here is the call graph for this function:

◆ fitPresentationOfInstrument()

QString JobResultsPresenter::fitPresentationOfInstrument ( InstrumentItem instrumentItem)
private

Definition at line 134 of file JobResultsPresenter.cpp.

135 {
136  if (instrumentItem->is<SpecularInstrumentItem>())
137  return "Fit 1D Data";
138 
139  return "Fit 2D Data";
140 }

References InstrumentItem::is().

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

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 JobResultsPresenter::itemPresentation ( ) const
overrideprotectedvirtual

Presentation which should be shown for current item.

Reimplemented from ItemComboWidget.

Definition at line 41 of file JobResultsPresenter.cpp.

42 {
43  if (!currentItem())
44  return {};
45 
46  const QString value = dynamic_cast<const JobItem*>(currentItem())->presentationType();
47  return value.isEmpty() ? selectedPresentation() : value;
48 }
QString selectedPresentation() const
Presentation selected in combo selector.

References SessionItemWidget::currentItem(), and ItemComboWidget::selectedPresentation().

Here is the call graph for this function:

◆ onComboChanged

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

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 ItemComboWidget::selectedPresentation(), and ItemComboWidget::setPresentation().

Referenced by ItemComboWidget::ItemComboWidget().

Here is the call graph for this function:

◆ presentationList()

QStringList JobResultsPresenter::presentationList ( SessionItem item)
overrideprotectedvirtual

Returns full list of presentations available for given item.

Reimplemented from ItemComboWidget.

Definition at line 101 of file JobResultsPresenter.cpp.

102 {
103  auto* jobItem = dynamic_cast<JobItem*>(item);
104  if (!jobItem || jobItem->isRunning())
105  return {};
106 
107  ASSERT(jobItem->instrumentItem() != nullptr);
108 
109  auto result = defaultActivePresentationsOfInstrument(jobItem->instrumentItem());
110  auto addon = fitPresentationOfInstrument(jobItem->instrumentItem());
111  if (!addon.isEmpty())
112  result << addon;
113 
114  return result;
115 }

References defaultActivePresentationsOfInstrument(), and fitPresentationOfInstrument().

Here is the call graph for this function:

◆ registerWidget()

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

Definition at line 44 of file ItemComboWidget.cpp.

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

References ItemComboWidget::m_widgetFactory.

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

◆ selectedPresentation()

QString ItemComboWidget::selectedPresentation ( ) const
protectedinherited

Presentation selected in combo selector.

Definition at line 122 of file ItemComboWidget.cpp.

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

References ItemComboToolbar::currentPresentation(), and ItemComboWidget::m_toolbar.

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

Here is the call graph for this function:

◆ setItem()

void JobResultsPresenter::setItem ( SessionItem item)
overridevirtual

Reimplemented from ItemComboWidget.

Definition at line 50 of file JobResultsPresenter.cpp.

51 {
53 }
void setItem(SessionItem *item) override

References ItemComboWidget::setItem().

Referenced by JobView::onSelectionChanged().

Here is the call graph for this function:

◆ setPresentation() [1/2]

void JobResultsPresenter::setPresentation ( const QString &  presentationType)
overridevirtual

Sets stack to show widget corresponding to given presentation.

Reimplemented from ItemComboWidget.

Definition at line 55 of file JobResultsPresenter.cpp.

56 {
57  ItemComboWidget::setPresentation(presentationType);
58  auto* item = dynamic_cast<JobItem*>(currentItem());
59  if (item && !presentationType.isEmpty())
60  item->setPresentationType(presentationType);
61 }
void setPresentationType(const QString &type)
Definition: JobItem.cpp:341

References SessionItemWidget::currentItem(), ItemComboWidget::setPresentation(), and JobItem::setPresentationType().

Referenced by JobView::connectActivityRelated(), JobView::setAppropriateActivityForJob(), and setPresentation().

Here is the call graph for this function:

◆ setPresentation [2/2]

void JobResultsPresenter::setPresentation ( JobViewActivity  activity)
slot

Definition at line 63 of file JobResultsPresenter.cpp.

64 {
65  QString presentation;
66  auto* jobItem = dynamic_cast<JobItem*>(currentItem());
67  if (jobItem && !jobItem->isRunning()) {
68  switch (activity) {
70  presentation = fitPresentationOfInstrument(jobItem->instrumentItem());
71  break;
72 
75  presentation = defaultPresentationOfInstrument(jobItem->instrumentItem());
76  break;
77  }
78  setPresentation(presentation);
79  }
80 }
void setPresentation(const QString &presentationType) override
Sets stack to show widget corresponding to given presentation.
QString defaultPresentationOfInstrument(InstrumentItem *instrumentItem)

References SessionItemWidget::currentItem(), defaultPresentationOfInstrument(), fitPresentationOfInstrument(), Fitting, JobView, RealTime, and setPresentation().

Here is the call graph for this function:

◆ setSizeToCurrentWidget()

void ItemComboWidget::setSizeToCurrentWidget ( )
privateinherited

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 }
QStackedWidget * m_stackedWidget

References ItemComboWidget::m_stackedWidget.

Referenced by ItemComboWidget::setPresentation().

◆ setToolbarVisible()

void ItemComboWidget::setToolbarVisible ( bool  value)
inherited

Definition at line 83 of file ItemComboWidget.cpp.

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

References ItemComboWidget::m_toolbar.

Referenced by ItemComboWidget::ItemComboWidget(), ItemComboWidget::setItem(), and ItemComboWidget::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 ( )
overrideprotectedvirtualinherited

Reimplemented from SessionItemWidget.

Definition at line 127 of file ItemComboWidget.cpp.

128 {
132 }
void setPresentationList(const QStringList &presentationList, const QStringList &activeList={})
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.
virtual QString itemPresentation() const
Presentation which should be shown for current item.

References ItemComboWidget::activePresentationList(), SessionItemWidget::currentItem(), ItemComboWidget::itemPresentation(), ItemComboWidget::m_toolbar, ItemComboWidget::presentationList(), ItemComboWidget::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
privateinherited

◆ m_itemController

◆ m_presentationTypeToWidget

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

Definition at line 69 of file ItemComboWidget.h.

Referenced by ItemComboWidget::setPresentation().

◆ m_stackedWidget

QStackedWidget* ItemComboWidget::m_stackedWidget
privateinherited

◆ m_toolbar

◆ m_widgetFactory

IFactory<QString, SessionItemWidget> ItemComboWidget::m_widgetFactory
privateinherited

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