BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
JobResultsPresenter.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Job/JobResultsPresenter.cpp
6 //! @brief Implements class JobResultsPresenter
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 
17 #include "GUI/Model/Job/JobItem.h"
24 
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 }
40 
42 {
43  if (!currentItem())
44  return {};
45 
46  const QString value = dynamic_cast<const JobItem*>(currentItem())->presentationType();
47  return value.isEmpty() ? selectedPresentation() : value;
48 }
49 
51 {
53 }
54 
55 void JobResultsPresenter::setPresentation(const QString& presentationType)
56 {
57  ItemComboWidget::setPresentation(presentationType);
58  auto* item = dynamic_cast<JobItem*>(currentItem());
59  if (item && !presentationType.isEmpty())
60  item->setPresentationType(presentationType);
61 }
62 
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 }
81 
82 //! Returns list of presentation types, available for given item. JobItem with fitting abilities
83 //! is valid for IntensityDataWidget and FitComparisonWidget.
84 
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 }
100 
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 }
116 
118 {
119  if (instrumentItem->is<SpecularInstrumentItem>())
120  return "Reflectometry";
121 
122  return "Heat Map";
123 }
124 
125 QStringList
127 {
128  if (instrumentItem->is<SpecularInstrumentItem>())
129  return {"Reflectometry"};
130 
131  return {"Heat Map", "Projections"};
132 }
133 
135 {
136  if (instrumentItem->is<SpecularInstrumentItem>())
137  return "Fit 1D Data";
138 
139  return "Fit 2D Data";
140 }
Defines class FitComparisonWidget1D.
Defines class FitComparisonWidget.
Defines class InstrumentItem and all its children.
Defines class IntensityDataProjectionsWidget.
Defines class IntensityDataWidget.
Defines class JobItem.
Defines class JobResultsPresenter.
Defines class JobViewActivities.
JobViewActivity
Defines class SpecularDataWidget.
Abstract base class for instrument-specific item classes.
bool is() const
The ItemComboWidget class combines stack of widgets with QComboBox controller to switch between widge...
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 registerWidget(const QString &presentationType, factory_function_t)
void setPresentationType(const QString &type)
Definition: JobItem.cpp:341
QStringList activePresentationList(SessionItem *item) override
Returns list of presentation types, available for given item. JobItem with fitting abilities is valid...
void setItem(SessionItem *item) override
void setPresentation(const QString &presentationType) override
Sets stack to show widget corresponding to given presentation.
QStringList presentationList(SessionItem *item) override
Returns full list of presentations available for given item.
QString defaultPresentationOfInstrument(InstrumentItem *instrumentItem)
QString itemPresentation() const override
Presentation which should be shown for current item.
QStringList defaultActivePresentationsOfInstrument(InstrumentItem *instrumentItem)
QString fitPresentationOfInstrument(InstrumentItem *instrumentItem)
JobResultsPresenter(QWidget *parent=nullptr)
SessionItem * currentItem()
Base class for a GUI data item.
Definition: SessionItem.h:204