BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
TestView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/TestView.cpp
6 //! @brief Implements class TestView
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 
33 #include <QTreeView>
34 
35 #include <QCheckBox>
36 #include <QLineEdit>
37 
38 namespace {
39 // These functions are required for testing purposes only
40 // They must be removed after completion of
41 // SpecularDataWidget
42 double getTestValue(size_t bin, double factor);
43 SpecularDataItem* fillTestItem(SessionItem* item, double factor);
44 } // namespace
45 
46 TestView::TestView(MainWindow* mainWindow) : QWidget(mainWindow), m_mainWindow(mainWindow)
47 {
48  // test_ComponentProxyModel();
49  // test_MaterialEditor();
50  // test_MinimizerSettings();
51  // test_AccordionWidget();
52  // test_RunFitWidget();
53  // test_ba3d();
54  // test_specular_data_widget();
55 }
56 
58 {
59  auto layout = new QHBoxLayout();
60  layout->setMargin(0);
61  layout->setSpacing(0);
62 
63  layout->addWidget(new TestComponentView(m_mainWindow));
64 
65  setLayout(layout);
66 }
67 
69 {
70  MaterialEditor* materialEditor = new MaterialEditor(m_mainWindow->materialModel());
71  QVBoxLayout* layout = new QVBoxLayout;
72  layout->setMargin(0);
73  layout->setSpacing(0);
74  layout->addWidget(materialEditor);
75  setLayout(layout);
76 }
77 
79 {
81  QVBoxLayout* layout = new QVBoxLayout;
82  layout->setMargin(0);
83  layout->setSpacing(0);
84  layout->addWidget(widget);
85  setLayout(layout);
86 
87  SessionModel* model = new SessionModel("TempModel", this);
88  auto minimizerItem = model->insertItem<MinimizerContainerItem>();
89  widget->setItem(minimizerItem);
90 }
91 
93 {
94  AccordionWidget* myAccordion = new AccordionWidget();
95  myAccordion->setMultiActive(true);
96  // add the Accordion to your layout
97  QVBoxLayout* layout = new QVBoxLayout;
98  layout->addWidget(myAccordion);
99  setLayout(layout);
100 
101  // add a content pane with a header
102  int firstPaneIndex = myAccordion->addContentPane("My first content pane");
103  // make sure our content pane was added
104  if (firstPaneIndex != -1) {
105  // get a QFrame* from the Content Pane. This is where we place our content
106  QFrame* contentFrame = myAccordion->getContentPane(firstPaneIndex)->getContentFrame();
107  // give the QFrame a QLayout
108  contentFrame->setLayout(new QVBoxLayout());
109  // add a simpel QLabel to the frame
110  contentFrame->layout()->addWidget(new QLabel("Hello Cute World!!!"));
111  }
112 
113  // add a content pane with a header
114  int secondPaneIndex = myAccordion->addContentPane("Basic settings");
115  // make sure our content pane was added
116  if (secondPaneIndex != -1) {
117  // get a QFrame* from the Content Pane. This is where we place our content
118  QFrame* contentFrame = myAccordion->getContentPane(secondPaneIndex)->getContentFrame();
119  // give the QFrame a QLayout
120  contentFrame->setLayout(new QVBoxLayout());
121  // add a simpel QLabel to the frame
122  QLineEdit* led = new QLineEdit();
123  QLineEdit* led2 = new QLineEdit();
124  contentFrame->layout()->addWidget(new QLabel("Name:"));
125  contentFrame->layout()->addWidget(led);
126  contentFrame->layout()->addWidget(new QLabel("Living place:"));
127  contentFrame->layout()->addWidget(led2);
128  }
129 
130  // add a content pane with a header
131  int third = myAccordion->addContentPane("Advanced");
132  // make sure our content pane was added
133  if (third != -1) {
134  // get a QFrame* from the Content Pane. This is where we place our content
135  myAccordion->getContentPane(third)->setMaximumHeight(500);
136  QFrame* contentFrame = myAccordion->getContentPane(third)->getContentFrame();
137  contentFrame->setMaximumHeight(500);
138  // give the QFrame a QLayout
139  contentFrame->setLayout(new QVBoxLayout());
140  // add a simpel QLabel to the frame
141  QCheckBox* cb = new QCheckBox();
142  cb->setText("Option 1");
143  QCheckBox* cb2 = new QCheckBox();
144  cb2->setText("Option 2");
145  QCheckBox* cb3 = new QCheckBox();
146  cb3->setText("Option 3");
147  QCheckBox* cb4 = new QCheckBox();
148  cb4->setText("Option 4");
149  QCheckBox* cb5 = new QCheckBox();
150  cb5->setText("Option 5");
151  QCheckBox* cb6 = new QCheckBox();
152  cb6->setText("Option 6");
153  QCheckBox* cb7 = new QCheckBox();
154  cb7->setText("Option 7");
155  contentFrame->layout()->addWidget(cb);
156  contentFrame->layout()->addWidget(cb2);
157  contentFrame->layout()->addWidget(cb3);
158  contentFrame->layout()->addWidget(cb4);
159  contentFrame->layout()->addWidget(cb5);
160  contentFrame->layout()->addWidget(cb6);
161  contentFrame->layout()->addWidget(cb7);
162  }
163 }
164 
166 {
167  // After putting this 3D view in Sample Viewer with the necessary changes, it does not work
168  // in test view and needs to be refactored in order to be used.
169 
170  QVBoxLayout* layout = new QVBoxLayout;
171  layout->setMargin(0);
172  layout->setSpacing(0);
174  layout->addWidget(widget);
175  setLayout(layout);
176 }
177 
179 {
180  SessionModel* tempModel = new SessionModel("Test", this);
181 
182  // creating job item
183  auto job_item = tempModel->insertItem<JobItem>();
184 
185  // creating "simulation" data
186  auto data_item = new SpecularDataItem();
187  job_item->insertItem(-1, data_item, JobItem::T_OUTPUT);
188  fillTestItem(data_item, 1.0);
189 
190  // creating "real" data
191  auto real_data = new RealDataItem();
192  job_item->insertItem(-1, real_data, JobItem::T_REALDATA);
193  data_item = new SpecularDataItem();
194  real_data->insertItem(-1, data_item, RealDataItem::T_INTENSITY_DATA);
195  fillTestItem(data_item, 2.0);
196 
197  // creating data view
198  auto data_view = new Data1DViewItem();
199  job_item->insertItem(-1, data_view, JobItem::T_DATAVIEW);
200  data_view->insertItem(-1, new DataPropertyContainer, Data1DViewItem::T_DATA_PROPERTIES);
201  auto container = data_view->item<DataPropertyContainer>(Data1DViewItem::T_DATA_PROPERTIES);
202  container->addItem(job_item->realDataItem()->dataItem());
203  container->addItem(job_item->dataItem());
204 
205  QVBoxLayout* layout = new QVBoxLayout;
206  layout->setMargin(0);
207  layout->setSpacing(0);
208  auto widget = new Plot1DCanvas(this);
209  widget->setItem(job_item->dataItemView());
210  layout->addWidget(widget);
211  setLayout(layout);
212 }
213 
214 namespace {
215 double getTestValue(size_t bin, double factor)
216 {
217  const double angle_factor = M_PI / (180.0 * 100.0);
218  const double angle = bin * angle_factor;
219  return (std::cos(angle * 1000.0) + 1.5) * std::exp(-(bin * factor / 100.0));
220 }
221 
222 SpecularDataItem* fillTestItem(SessionItem* item, double factor)
223 {
224  SpecularDataItem* result = dynamic_cast<SpecularDataItem*>(item);
225  ASSERT(result);
226  auto outputData = std::make_unique<OutputData<double>>();
227  outputData->addAxis(FixedBinAxis("Angle [deg]", 1000, 0.0, 10.0));
228  for (size_t i = 0; i < 1000; ++i)
229  outputData->operator[](i) = getTestValue(i, factor);
230 
231  result->setOutputData(outputData.release());
232  return result;
233 }
234 } // namespace
Defines class holding all application models.
#define ASSERT(condition)
Definition: Assert.h:31
#define M_PI
Definition: Constants.h:44
Defines ContentPane class.
Defines class Data1DViewItem.
Defines class DataPropertyContainer.
Defines class MainWindow.
Defines class JobItem.
Defines class JobModel.
Defines class MaskEditor.
Defines class MaterialEditor.
Defines MinimizerItem class.
Defines class MinimizerSettingsWidget.
Defines class Plot1DCanvas.
Defines class RealDataItem.
Defines class RealSpaceWidget.
Defines class SampleModel.
Defines class SpecularDataItem.
Defines class TestComponentView.
Defines class TestView.
QAccordion base class.
ContentPane * getContentPane(uint index)
Get content pane.
int addContentPane(QString header)
Add a new content Pane.
void setMultiActive(bool status)
Allow multiple ContentPane to be open.
QFrame * getContentFrame()
Get the content frame of the content pane.
Definition: ContentPane.cpp:53
void setMaximumHeight(int maxHeight)
Set the maximum height of the content pane container.
Definition: ContentPane.cpp:72
View model for 1D DataItem.
static const QString T_DATA_PROPERTIES
void addItem(DataItem *data_item)
Axis with fixed bin size.
Definition: FixedBinAxis.h:23
static const QString T_DATAVIEW
Definition: JobItem.h:52
static const QString T_OUTPUT
Definition: JobItem.h:50
static const QString T_REALDATA
Definition: JobItem.h:51
SampleModel * sampleModel()
Definition: mainwindow.cpp:144
MaterialModel * materialModel()
Definition: mainwindow.cpp:134
Main widget of MaterialEditor.
The MinimizerContainerItem class holds collection of minimizers.
Definition: MinimizerItem.h:33
The MinimizerSettingsWidget contains editor for all minnimizer settings and related fit options.
void setItem(JobItem *jobItem)
The Plot1DCanvas class contains SpecularPlotWithDataView for specular data presentation,...
Definition: Plot1DCanvas.h:29
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35
static const QString T_INTENSITY_DATA
Definition: RealDataItem.h:45
Prototype of real space widget to present sample structure in 3D view.
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Definition: SessionModel.h:125
void setOutputData(OutputData< double > *data) override
The given pointer becomes owned by this class!!
View to tests QListView working with ComponentProxyModel.
void test_MaterialEditor()
Definition: TestView.cpp:68
void test_MinimizerSettings()
Definition: TestView.cpp:78
TestView(MainWindow *mainWindow=nullptr)
Definition: TestView.cpp:46
void test_ba3d()
Definition: TestView.cpp:165
void test_AccordionWidget()
Definition: TestView.cpp:92
void test_ComponentProxyModel()
Definition: TestView.cpp:57
MainWindow * m_mainWindow
Definition: TestView.h:35
void test_specular_data_widget()
Definition: TestView.cpp:178