BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationDataSelectorWidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/SimulationWidgets/SimulationDataSelectorWidget.cpp
6 //! @brief Implements class SimulationDataSelectorWidget
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 
24 #include <QComboBox>
25 #include <QFileDialog>
26 #include <QGroupBox>
27 #include <QLabel>
28 #include <QVBoxLayout>
29 
30 namespace {
31 const QString select_instrument_tooltip =
32  "Select Instrument to simulate from those defined in Instrument View";
33 const QString select_sample_tooltip = "Select Sample to simulate from those defined in Sample View";
34 const QString select_realdata_tooltip = "Select real data to use during the fitting. \n"
35  "If None is selected, the standard simulation will be run.";
36 } // namespace
37 
39  : QWidget(parent)
40  , m_instrumentCombo(new QComboBox)
41  , m_sampleCombo(new QComboBox)
42  , m_realDataCombo(new QComboBox)
43  , m_applicationModels(0)
44 {
45  QVBoxLayout* mainLayout = new QVBoxLayout;
46  mainLayout->setMargin(0);
47  mainLayout->setSpacing(0);
48 
49  // selection of input parameters
50  QGroupBox* groupBox = new QGroupBox("Data selection");
51 
52  QLabel* instrumentSelectionLabel = new QLabel("Instrument:");
53  instrumentSelectionLabel->setToolTip(select_instrument_tooltip);
54  m_instrumentCombo->setToolTip(select_instrument_tooltip);
55  m_instrumentCombo->setAttribute(Qt::WA_MacShowFocusRect, false);
56  m_instrumentCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
57 
58  QLabel* sampleSelectionLabel = new QLabel("Sample:");
59  sampleSelectionLabel->setToolTip(select_sample_tooltip);
60  m_sampleCombo->setToolTip(select_sample_tooltip);
61 
62  QLabel* readDataSelectionLabel = new QLabel("Real Data:");
63  readDataSelectionLabel->setToolTip(select_realdata_tooltip);
64  m_realDataCombo->setToolTip(select_realdata_tooltip);
65 
66  // layout
67  QGridLayout* dataSelectionLayout = new QGridLayout;
68  dataSelectionLayout->setMargin(12); // to match margin in SimulationOptionsWidget
69 
70  dataSelectionLayout->addWidget(instrumentSelectionLabel, 0, 0);
71  dataSelectionLayout->addWidget(m_instrumentCombo, 0, 1);
72  dataSelectionLayout->addWidget(sampleSelectionLabel, 1, 0);
73  dataSelectionLayout->addWidget(m_sampleCombo, 1, 1);
74  dataSelectionLayout->addWidget(readDataSelectionLabel, 2, 0);
75  dataSelectionLayout->addWidget(m_realDataCombo, 2, 1);
76  groupBox->setLayout(dataSelectionLayout);
77 
78  mainLayout->addWidget(groupBox);
79  setLayout(mainLayout);
80 }
81 
83 {
84  m_applicationModels = applicationModels;
86 }
87 
88 //! Returns selected MultiLayerItem taking into account that there might be several
89 //! multilayers with same name.
90 
92 {
94  if (items.isEmpty())
95  return nullptr;
96  return dynamic_cast<const MultiLayerItem*>(items.at(selectedSampleIndex()));
97 }
98 
99 //! Returns selected InstrumentItem taking into account that there might be several
100 //! instruments with same name.
101 
103 {
105  return items.isEmpty() ? nullptr : items.at(selectedInstrumentIndex());
106 }
107 
108 //! Returns selected real data item taking into account that there might be several
109 //! items with same name.
110 
112 {
114  if (items.isEmpty())
115  return nullptr;
116  if (selectedRealDataIndex() >= 0 && selectedRealDataIndex() < items.size())
117  return items.at(selectedRealDataIndex());
118 
119  return nullptr;
120 }
121 
123 {
130  true);
131 }
132 
134 {
135  return m_instrumentCombo->currentIndex();
136 }
137 
139 {
140  return m_sampleCombo->currentIndex();
141 }
142 
144 {
145  // -1 because m_realDataCombo always contains "None" as a first entry
146  return m_realDataCombo->currentIndex() - 1;
147 }
148 
149 //! Updates selection combo with string list while preserving previous selection.
150 //! If allow_none == true, additional "None" item will be added to the combo.
151 
152 void SimulationDataSelectorWidget::updateSelection(QComboBox* comboBox, QStringList itemList,
153  bool allow_none)
154 {
155  QString previousItem = comboBox->currentText();
156 
157  comboBox->clear();
158  if (itemList.isEmpty()) {
159  comboBox->setEnabled(false);
160  comboBox->addItem("Not yet defined");
161  } else {
162  comboBox->setEnabled(true);
163  // qSort(itemList.begin(), itemList.end()); // uncomment, if we want alphabetical order
164  if (allow_none)
165  itemList.insert(-1, "None");
166  comboBox->addItems(itemList);
167  if (itemList.contains(previousItem))
168  comboBox->setCurrentIndex(itemList.indexOf(previousItem));
169  }
170 }
Defines class holding all application models.
#define ASSERT(condition)
Definition: Assert.h:31
Defines InstrumentItems classes.
Defines class InstrumentModel.
Defines ModelUtils namespace.
Defines class MultiLayerItem.
Defines class RealDataItem.
Defines class RealDataModel.
Defines class SampleModel.
Defines class SimulationDataSelectorWidget.
SampleModel * sampleModel()
RealDataModel * realDataModel()
InstrumentModel * instrumentModel()
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35
QVector< RealDataItem * > realDataItems() const
QVector< T * > topItems() const
Definition: SessionModel.h:147
void updateSelection(QComboBox *comboBox, QStringList itemList, bool allow_none=false)
Updates selection combo with string list while preserving previous selection.
const MultiLayerItem * selectedMultiLayerItem() const
Returns selected MultiLayerItem taking into account that there might be several multilayers with same...
const RealDataItem * selectedRealDataItem() const
Returns selected real data item taking into account that there might be several items with same name.
void setApplicationModels(ApplicationModels *applicationModels)
const InstrumentItem * selectedInstrumentItem() const
Returns selected InstrumentItem taking into account that there might be several instruments with same...
QStringList topItemNames(SessionModel *model, const QString &modelType="")
Returns list of top iten manes.
Definition: ModelUtils.cpp:20